karthiks
karthiks

Reputation: 7299

Issue Setting up Dagger 2.x for Android on AndroidStudio3.0 Canary4

I get following errors while setting up dagger 2.x in Android Studio 3.0 Canary 4

Error:(71, 20) Failed to resolve: com.google.dagger:dagger:2.x

Error:(73, 20) Failed to resolve: com.google.dagger:dagger-android:2.x

Error:(74, 20) Failed to resolve: com.google.dagger:dagger-android-support:2.x

My build files are like below:

dependencies {
    //For DI - Dagger 2
    implementation 'com.google.dagger:dagger:2.x'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.x'
    implementation 'com.google.dagger:dagger-android:2.x' // If you're using classes in dagger.android
    implementation 'com.google.dagger:dagger-android-support:2.x' // if you use the support libraries
    annotationProcessor 'com.google.dagger:dagger-android-processor:2.x'
}

The project build file has below snippets

allprojects {
    repositories {
        jcenter()
        maven { url "https://maven.google.com" }
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    }
}

Your help is appreciated...

Upvotes: 21

Views: 14949

Answers (2)

Piyush Saxena
Piyush Saxena

Reputation: 174

Edit: I completely agree with the comments mentioning the usage of specific version of this library instead of +, so for example 2.11 should be used instead of 2.+ 2.+ was intended to fix the issue with 2.x as most of beginners take 2.x literally like I did when I first used it. The x here meant to be latest minor version of the stable release. Please check the latest release notes and replace x with latest minor version of library.

Original Answer: I am sure by now you have resolved your issue, though after trying few others and this one too, I found a reliable solution and posting it for helping others. Instead of 2.x use 2.+.

It solved all issues for me, not only it resolved the above problem,it also make sure to pull the latest version dagger 2.x available.

It should look like this:

dependencies {
    implementation 'com.google.dagger:dagger:2.+'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.+'
    implementation 'com.google.dagger:dagger-android:2.+' // If you're using classes in dagger.android
    implementation 'com.google.dagger:dagger-android-support:2.+' // if you use the support libraries
    annotationProcessor 'com.google.dagger:dagger-android-processor:2.+'
}

Thanks!

Upvotes: 14

karthiks
karthiks

Reputation: 7299

If you're like me to have got into this problem, this is what I did to get out of this situation.

I went to https://github.com/google/dagger/releases to figure out the latest release version of dagger, and found v2.11 to be the latest as on date. I replaced 2.x with 2.11 in the version portion for this libraries configuration in the build file and bingo the build is successful.

dependencies {
    //For DI - Dagger 2
    implementation 'com.google.dagger:dagger:2.11'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
    implementation 'com.google.dagger:dagger-android:2.11' // If you're using classes in dagger.android
    implementation 'com.google.dagger:dagger-android-support:2.11' // if you use the support libraries
    annotationProcessor 'com.google.dagger:dagger-android-processor:2.11'
}

Upvotes: 45

Related Questions