144

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'
Community
  • 1
  • 1
nhoxbypass
  • 8,877
  • 9
  • 39
  • 62

16 Answers16

115

I fix this with two steps

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

2) Build -> Clean project enter image description here

Beto
  • 3,343
  • 5
  • 27
  • 37
33

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'
}
A Droid
  • 945
  • 10
  • 19
17

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
     }
}
Dhaval Patel
  • 9,209
  • 4
  • 42
  • 44
14

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!

Vince
  • 1,517
  • 12
  • 16
7

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

Jee Mok
  • 4,537
  • 7
  • 35
  • 66
beeftosino
  • 111
  • 1
  • 4
4

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.

pamobo0609
  • 752
  • 8
  • 21
  • 1
    kapt can also handle java files, so no need to use them both, just only kapt is OK. – Ted Mar 21 '19 at 05:55
4

Removing the testInstrumentationRunner worked for me:

defaultConfig {
...
...
//        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
M. Usman Khan
  • 4,258
  • 1
  • 48
  • 62
3

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.

Raj
  • 101
  • 4
  • 1
    I believe Jake Wharton already added support for AndroidX in 9.0.0 snapshot. See: https://github.com/JakeWharton/butterknife/issues/1280 – nhoxbypass Aug 29 '18 at 08:23
2

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

Minh Pham
  • 29
  • 1
  • 3
  • 8
    It's not recommended since there could be third-party libraries which weren't upgraded to AndroidX yet! As the documentation says: "android.enableJetifier: When set to true, the Android plugin automatically migrates existing third-party libraries to use AndroidX by rewriting their binaries. The flag is false by default if it is not specified." https://developer.android.com/jetpack/androidx/ – gabhor Nov 22 '18 at 19:52
2

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...

Shubham Pandey
  • 1,498
  • 1
  • 15
  • 23
Dimitri de Jesus
  • 775
  • 7
  • 12
1

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.

ikhsanudinhakim
  • 1,255
  • 12
  • 20
1

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.

Pedro Molina
  • 429
  • 6
  • 7
0

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

Gab Ledesma
  • 1,515
  • 1
  • 5
  • 12
0

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
  }
}
  1. clean prject and run.
-1

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!

Hanoch Moreno
  • 543
  • 7
  • 9
-1

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.

double-beep
  • 3,889
  • 12
  • 24
  • 35
EngineerDanny
  • 512
  • 6
  • 9