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

前端 未结 16 1026
轻奢々
轻奢々 2021-01-30 04:36

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

ERROR: [TA

相关标签:
16条回答
  • 2021-01-30 05:12

    Removing the testInstrumentationRunner worked for me:

    defaultConfig {
    ...
    ...
    //        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
    
    0 讨论(0)
  • 2021-01-30 05:15

    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!

    0 讨论(0)
  • 2021-01-30 05:18

    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
         }
    }
    
    0 讨论(0)
  • 2021-01-30 05:18

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

    0 讨论(0)
  • 2021-01-30 05:20

    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.

    0 讨论(0)
  • 2021-01-30 05:20

    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.

    0 讨论(0)
提交回复
热议问题