Failed to resolve variable '${animal.sniffer.version}' when migrate to AndroidX

AndroidAndroid StudioAndroid Studio-3.0AndroidxAndroid Studio-3.2

Android Problem Overview


I'm using Android Studio 3.2 Beta5 to migrate my project to AndroidX. When I rebuild my app I got these errors:

> ERROR: [TAG] Failed to resolve variable '${animal.sniffer.version}' > > ERROR: [TAG] Failed to resolve variable '${junit.version}'

Full clean & rebuild did not work! Anyone know how to fix this?


gradle.properties

android.enableJetifier=true
android.useAndroidX=true

build.gradle

buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0-beta05'

        classpath 'com.google.gms:google-services:4.0.1'
        classpath "io.realm:realm-gradle-plugin:5.3.1"
        classpath 'io.fabric.tools:gradle:1.25.4'
        classpath 'com.google.firebase:firebase-plugins:1.1.5'
    }
}

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

task clean(type: Delete) {
    delete rootProject.buildDir
}

app/build.gradle

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'io.fabric'
apply plugin: 'com.google.firebase.firebase-perf'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.0"
    defaultConfig {
        applicationId "com.iceteaviet.fastfoodfinder"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
        }
    }
    aaptOptions {
        cruncherEnabled = false
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.12'

    implementation 'com.jakewharton:butterknife:9.0.0-SNAPSHOT'

    implementation 'androidx.appcompat:appcompat:1.0.0-rc01'
    implementation 'com.google.android.material:material:1.0.0-rc01'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0-rc01'
    implementation 'androidx.cardview:cardview:1.0.0-rc01'

    implementation 'com.google.maps.android:android-maps-utils:0.5'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.google.android.gms:play-services-location:15.0.1'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.google.firebase:firebase-auth:16.0.1'
    implementation 'com.google.android.gms:play-services-auth:15.0.1'

    implementation 'com.github.bumptech.glide:glide:4.7.1'

    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'

    implementation 'org.greenrobot:eventbus:3.1.1'

    implementation 'de.hdodenhof:circleimageview:2.2.0'

    implementation 'io.realm:realm-android-library:5.3.1'

    implementation 'com.facebook.android:facebook-android-sdk:4.34.0'

    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
    implementation 'io.reactivex.rxjava2:rxjava:2.0.2'

    implementation 'androidx.multidex:multidex:2.0.0'

    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.4'
    implementation 'com.google.firebase:firebase-perf:16.0.0'

    implementation 'com.jakewharton.timber:timber:4.7.1'

    annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
}

apply plugin: 'com.google.gms.google-services'

Android Solutions


Solution 1 - Android

I fix this with two steps

  1. File -> Invalidate Caches / restart... enter image description here

  2. Build -> Clean project enter image description here

Solution 2 - Android

I got the same error after updating my build.gradle file with AndroidX Test dependencies. Turns out I forgot to remove the old junit dependency. So for me, the fix was simply to remove the following dependency:

dependencies {
    ...
    testImplementation 'junit:junit:4.12'
}

Solution 3 - Android

Adding Java 8 support to build.gradle file fixed issue for me

android {
     ...
 
     //Add the following configuration in order to target Java 8.
     compileOptions {
         sourceCompatibility JavaVersion.VERSION_1_8
         targetCompatibility JavaVersion.VERSION_1_8
     }
}

Solution 4 - Android

It seems to be Glide the problem.

I had the same error and I just updated the Glide's dependencies to 4.8 and there is no build errors.

Kotlin :

// Glide
def glide_version = "4.8.0"
implementation "com.github.bumptech.glide:glide:$glide_version"
kapt "com.github.bumptech.glide:compiler:$glide_version"

Java :

// Glide
def glide_version = "4.8.0"
implementation "com.github.bumptech.glide:glide:$glide_version"
annotationProcessor "com.github.bumptech.glide:compiler:$glide_version"

Be sure to have enabled in your gradle.properties :

android.useAndroidX=true
android.enableJetifier=true

Source : https://github.com/bumptech/glide/issues/3124

Hope this will help you!

Solution 5 - Android

Fixed it by going to the main directory and typing flutter clean

Solution 6 - Android

Removing the testInstrumentationRunner worked for me:

defaultConfig {
...
...
//        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

Solution 7 - Android

If you're using Kotlin, the issue will popup if don't use the kapt version for any annotation processor you use in the project.

As @Vince mentioned the case with Glide, this could happen with Dagger2, Butterknife, etc.

If you're using both Java and Kotlin you'll need to keep both dependencies, as follows (were $glideVersion is a predefined version of Glide):

implementation "com.github.bumptech.glide:glide:$glideVersion"

kapt "com.github.bumptech.glide:compiler:$glideVersion"

If you're on a Kotlin only project, the kapt dependency should work alone.

EDIT

Another thing you should have in mind is if you're already using Androidx. Androidx is a great refactor but when migrating it can cause some of your dependencies to collapse. Mainstream libraries are already updated to Androidx, however, some of them are not and even won't.

If the issue doesn't go away with my provided solution above this edit, you can take a look at your dependencies and make sure they use Androidx as well.

EDIT 2

As @Ted mentioned, I researched back and he's right kapt does handle java files as well. kapt alone will do the trick, no need to keep both kapt and annotationProcessor dependencies.

Solution 8 - Android

Try removing this line:

maven { url "https://oss.sonatype.org/content/repositories/snapshots" }

from the buildscript / repositories section of your build.gradle file.

When I added that line, I got the error you described. When I removed it, no longer. That line should only be in the allprojects / repositories section.

Solution 9 - Android

Try set android.enableJetifier=false in gradle.properties. Then Invalidate Caches / Restart ... in Android Studio

Solution 10 - Android

The fix is in 4.2.0, use the higher version of google gms jar.

Try changing:

>classpath 'com.google.gms:google-services:4.0.1'

by this version:

>classpath 'com.google.gms:google-services:4.2.0'

Hope this works...

Solution 11 - Android

If you are using dagger or butterknife, please make sure to update it to the latest version. Or, if you have another injection library used in your project, you can try to check it if it support androidx or no.

I've found same error, the problem is on my dagger and butterknife. Have fixed it by updating it to newest version.

Solution 12 - Android

Android version: 4.10.2

I solved this issue with three simple steps: First i added below this in pubspec.yml: (with two spaces of identation)

module:
  androidX: true 

Adding this two lines below in gradle.properties, i have this in android/gradle.properties, in the project folder.

android.useAndroidX=true
android.enableJetifier=true

And after this i wrote with the terminal:

flutter clean

Maybe you will have to stop the device and run again.

Solution 13 - Android

I fixed this by updating the firebase dependencies to the latest.

Solution 14 - Android

I faced this error after adding butterknife to my project.

In order to resolve this error you should use Java8.

I would recommend this answer.

How I resolved it:

1.add following code in build.gradle (module: app)

android {
  ...
  // Configure only for each module that uses Java 8
  // language features (either in its source code or
  // through dependencies).
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

2. clean prject and run.

Solution 15 - Android

I fixed it by refreshing the cahche (Instead of invalidating it - which also clears the local history):

  1. in gradle.properties file, comment the line org.gradle.caching=true.
  2. Clean, Rebuild.
  3. in gradle.properties file, un-comment the line org.gradle.caching=true.
  4. Clean, Rebuild.

Thats it!

Solution 16 - Android

Go to file and click on Invalidate caches and restart.

After it restarts then you increase the minimum SDK version in your app's build.gradle file.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnhoxbypassView Question on Stackoverflow
Solution 1 - AndroidBetoView Answer on Stackoverflow
Solution 2 - AndroidA DroidView Answer on Stackoverflow
Solution 3 - AndroidDhaval PatelView Answer on Stackoverflow
Solution 4 - AndroidVinceView Answer on Stackoverflow
Solution 5 - AndroidbeeftosinoView Answer on Stackoverflow
Solution 6 - AndroidM. Usman KhanView Answer on Stackoverflow
Solution 7 - Androidpamobo0609View Answer on Stackoverflow
Solution 8 - AndroidRajView Answer on Stackoverflow
Solution 9 - AndroidMinh PhamView Answer on Stackoverflow
Solution 10 - AndroidDimitri de JesusView Answer on Stackoverflow
Solution 11 - AndroidikhsanudinhakimView Answer on Stackoverflow
Solution 12 - AndroidPedro MolinaView Answer on Stackoverflow
Solution 13 - AndroidGab LedesmaView Answer on Stackoverflow
Solution 14 - AndroidAhsan MalikView Answer on Stackoverflow
Solution 15 - AndroidHanoch MorenoView Answer on Stackoverflow
Solution 16 - AndroidEngineerDannyView Answer on Stackoverflow