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

Migrate dagger-android to work with the latest Gradle android plugin and dependencies #865

Open
wants to merge 2 commits into
base: dagger-android
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions app/build.gradle
Expand Up @@ -12,6 +12,7 @@ android {
targetSdkVersion rootProject.targetSdkVersion
versionCode 1
versionName "1.0"
multiDexEnabled true

testInstrumentationRunner 'com.example.android.architecture.blueprints.todoapp.CustomTestRunner'
}
Expand All @@ -32,14 +33,12 @@ android {
debug {
minifyEnabled false
testCoverageEnabled true
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
}

release {
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
}
Expand Down Expand Up @@ -85,8 +84,7 @@ dependencies {
implementation "androidx.room:room-runtime:$roomVersion"
kapt "androidx.room:room-compiler:$roomVersion"
implementation "androidx.room:room-ktx:$roomVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$archLifecycleVersion"
kapt "androidx.lifecycle:lifecycle-compiler:$archLifecycleVersion"
implementation "androidx.lifecycle:lifecycle-common-java8:$archLifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$archLifecycleVersion"
implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"
Expand Down Expand Up @@ -114,10 +112,12 @@ dependencies {
testImplementation "androidx.test:core-ktx:$androidXTestCoreVersion"
testImplementation "androidx.test.ext:junit-ktx:$androidXTestExtKotlinRunnerVersion"
testImplementation "androidx.test:rules:$androidXTestRulesVersion"
// Once https://issuetracker.google.com/127986458 is fixed this can be testImplementation
implementation "androidx.fragment:fragment-testing:$fragmentVersion"
implementation "androidx.test:core:$androidXTestCoreVersion"
testImplementation "androidx.test:core:$androidXTestCoreVersion"
debugImplementation "androidx.fragment:fragment-testing:$fragmentVersion"

// AndroidX Fragments
implementation "androidx.fragment:fragment:$fragmentVersion"
implementation "androidx.fragment:fragment-ktx:$fragmentVersion"

// AndroidX Test - Instrumented testing
androidTestImplementation "androidx.test:core-ktx:$androidXTestCoreVersion"
Expand All @@ -140,7 +140,7 @@ dependencies {
androidTestImplementation "com.google.android.material:material:$materialVersion"

// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
implementation "androidx.fragment:fragment-ktx:$fragmentKtxVersion"

// Dagger
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -28,6 +28,7 @@
<activity
android:name="com.example.android.architecture.blueprints.todoapp.tasks.TasksActivity"
android:windowSoftInputMode="adjustResize"
android:exported="true"
android:theme="@style/AppTheme.OverlapSystemBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Expand Up @@ -50,7 +50,7 @@ class AddEditTaskFragment : DaggerFragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
): View {
val root = inflater.inflate(R.layout.addtask_frag, container, false)
viewDataBinding = AddtaskFragBinding.bind(root).apply {
this.viewmodel = viewModel
Expand All @@ -60,8 +60,8 @@ class AddEditTaskFragment : DaggerFragment() {
return viewDataBinding.root
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupSnackbar()
setupNavigation()
this.setupRefreshLayout(viewDataBinding.refreshLayout)
Expand All @@ -73,7 +73,7 @@ class AddEditTaskFragment : DaggerFragment() {
}

private fun setupNavigation() {
viewModel.taskUpdatedEvent.observe(this, EventObserver {
viewModel.taskUpdatedEvent.observe(viewLifecycleOwner, EventObserver {
val action = AddEditTaskFragmentDirections
.actionAddEditTaskFragmentToTasksFragment(ADD_EDIT_RESULT_OK)
findNavController().navigate(action)
Expand Down
48 changes: 24 additions & 24 deletions build.gradle
@@ -1,12 +1,12 @@
buildscript {
ext.kotlinVersion = '1.3.31'
ext.navigationVersion = "2.1.0-alpha06"
ext.kotlinVersion = '1.6.10'
ext.navigationVersion = "2.5.0"
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.android.tools.build:gradle:7.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"

Expand All @@ -18,7 +18,7 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand All @@ -31,34 +31,34 @@ ext {
// Sdk and tools
// Support library and architecture components support minSdk 14 and above.
minSdkVersion = 14
targetSdkVersion = 28
compileSdkVersion = 28
targetSdkVersion = 31
compileSdkVersion = 31

// App dependencies
androidXVersion = '1.0.0'
androidXTestCoreVersion = '1.2.0'
androidXTestExtKotlinRunnerVersion = '1.1.1'
androidXTestCoreVersion = '1.4.0'
androidXTestExtKotlinRunnerVersion = '1.1.3'
androidXTestRulesVersion = '1.2.0-beta01'
androidXAnnotations = '1.0.1'
androidXAnnotations = '1.4.0'
androidXLegacySupport = '1.0.0'
appCompatVersion = '1.0.2'
archLifecycleVersion = '2.1.0-rc01'
archTestingVersion = '2.0.0'
appCompatVersion = '1.4.2'
archLifecycleVersion = '2.5.0'
archTestingVersion = '2.1.0'
cardVersion = '1.0.0'
coroutinesVersion = '1.2.1'
dexMakerVersion = '2.12.1'
daggerVersion = '2.23.2'
espressoVersion = '3.2.0-beta01'
fragmentVersion = '1.1.0-alpha07'
coroutinesVersion = '1.6.1'
dexMakerVersion = '2.28.1'
daggerVersion = '2.42'
espressoVersion = '3.5.0-alpha07'
fragmentVersion = '1.5.0'
fragmentKtxVersion = '1.1.0-rc01'
hamcrestVersion = '1.3'
junitVersion = '4.12'
materialVersion = '1.0.0'
mockitoVersion = '2.8.9'
recyclerViewVersion = '1.0.0'
robolectricVersion = '4.3-beta-1'
roomVersion = '2.1.0'
materialVersion = '1.6.1'
mockitoVersion = '2.28.2'
recyclerViewVersion = '1.2.1'
robolectricVersion = '4.8.1'
roomVersion = '2.4.2'
rulesVersion = '1.0.1'
timberVersion = '4.7.1'
truthVersion = '0.44'
truthVersion = '1.1.2'
}
3 changes: 1 addition & 2 deletions gradle.properties
Expand Up @@ -17,5 +17,4 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.enableJetifier=true
android.useAndroidX=true
android.enableUnitTestBinaryResources=true
android.useAndroidX=true
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Thu Apr 04 11:20:54 PDT 2019
#Fri Jul 08 11:17:21 IST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
zipStoreBase=GRADLE_USER_HOME