Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the dagger.android.support lib for compatibility with AppCompatActivity and support Fragment with minSdkVersion changed from 17 to 14. Closes #48 #49

Merged
merged 1 commit into from
Aug 14, 2017

Conversation

vestrel00
Copy link
Owner

@vestrel00 vestrel00 commented Aug 14, 2017

This answers #48.

This feature branch will get merged into the master-support branch- not the master branch. I will be keeping the non-support and support setups separate to keep things as clean as possible.

Branches

  1. master
  • Uses regular Activity and Fragment classes with a minSdkVersion of 17.
  1. master-support

Why is the minSdkVersion of the non-support setup in master 17? Can it be lower?

There are 2 main reasons why the minSdkVersion of the non-support setup can only be as low as 17.

  1. https://github.com/vestrel00/android-dagger-butterknife-mvp/pull/20/files#r133777223
  2. https://github.com/vestrel00/android-dagger-butterknife-mvp/pull/29/files#r133777242

Thus, the lowest minSdkVersion supported for the non-support setup in master is 17.
It cannot be lower.

What about the minSdkVersion of the support setup in master-support? Can it be lower than 14?

No. The dagger.android.support API only supports minSdkVersion
as low as 14.

Changes

  1. Added google maven repository
  2. Added android.dagger.support to dependencies
  3. Set minSdkVersion from 17 to 14
  4. Set Application theme to Theme.AppCompat
  5. Including AndroidSupportInjectionModule instead of AndroidInjectionModule in AppModule includes
  6. BaseActivity and module now using AppCompatActivity
  7. BaseFragment and module now using android.support.v4.app.Fragment
  8. BaseFragment now injecting with AndroidSupportInjection.inject(this) in only onAttach(Context)
  9. Replaced all occurrences of HasFragmentInjector with HasSupportFragmentInjector
  10. Replaced all occurrences of android.app.Fragment with android.support.v4.app.Fragment
  11. Replaced all occurrences of android.app.FragmentManager with android.support.v4.app.FragmentManager

@@ -25,7 +25,7 @@ android {
versionCode 1
versionName '1.0.0'

minSdkVersion 17
minSdkVersion 14
Copy link
Owner Author

@vestrel00 vestrel00 Aug 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The minSdkVersion of 17 is the lowest version that our non-support setup in master supports due to Fragment.getChildFragmentManager() and Fragment.onViewStateRestored only being available starting at API level 17.

The minSdkVersion 14 is the lowest version that dagger.android.support API supports. See https://github.com/google/dagger/blob/master/java/dagger/android/support/AndroidManifest.xml#L18

@@ -21,7 +21,10 @@
<application
android:name=".App"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat">
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theme.AppCompat (or descendant) is required for AppCompatActivity


/**
* Provides application-wide dependencies.
*/
@Module(includes = AndroidInjectionModule.class)
@Module(includes = AndroidSupportInjectionModule.class)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AndroidSupportInjectionModule includes AndroidInjectionModule implicitly.

…Activity and support Fragment with minSdkVersion changed from 17 to 14. Closes #48
@vestrel00 vestrel00 force-pushed the feature/#48-dagger-android-support-setup branch from 12253ce to 80140a8 Compare August 14, 2017 19:52
AndroidInjection.inject(this);
}
// This is called even for API levels below 23.
AndroidSupportInjection.inject(this);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now only invoked in onAttach(Context) because the support Fragment provides this method even to devices running API level 22 and below.

@@ -30,5 +30,9 @@ allprojects {
repositories {
jcenter()
mavenCentral()
// Required for dagger.android.support
maven {
url "https://maven.google.com"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required for dagger.android.support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant