迁移到AndroidX时无法解析变量'$ {animal.sniffer.version}'

问题描述 投票:99回答:12

我正在使用Android Studio 3.2 Beta5将我的项目迁移到AndroidX。当我重建我的应用程序时,我遇到了这些错误:

错误:[TAG]无法解析变量'$ {animal.sniffer.version}'

错误:[TAG]无法解析变量'$ {junit.version}'

完全清洁和重建不起作用!有人知道怎么修这个东西吗?


grad了.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
}

应用程序/的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 android-studio android-studio-3.0 androidx android-studio-3.2
12个回答
83
投票

我通过两个步骤修复此问题

1)文件 - >使高速缓存无效/重新启动... enter image description here

2)建立 - >清洁项目enter image description here


0
投票

我通过将firebase依赖项更新为最新版来修复此问题。


-1
投票

我通过刷新缓存来修复它(而不是使它失效 - 这也清除了本地历史记录):

  1. 在gradle.properties文件中,注释行org.gradle.caching = true。
  2. 清洁,重建。
  3. 在gradle.properties文件中,取消注释行org.gradle.caching = true。
  4. 清洁,重建。

而已!


-1
投票

转到文件并单击“使高速缓存无效”并重新启动。

重新启动后,您将在应用程序的build.gradle文件中增加最低SDK版本。


18
投票

使用AndroidX Test dependencies更新build.gradle文件后出现同样的错误。结果我忘了删除旧的junit依赖。所以对我来说,修复只是删除以下依赖项:

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

16
投票

添加Java 8支持build.gradle文件修复了我的问题

android {
     ...

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

13
投票

这似乎是Glide的问题。

我有同样的错误,我刚刚将Glide的依赖项更新为4.8,并且没有构建错误。

科特林:

// 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"

一定要在gradle.properties中启用:

android.useAndroidX=true
android.enableJetifier=true

资料来源:https://github.com/bumptech/glide/issues/3124

希望对你有帮助!


4
投票

如果您正在使用Kotlin,如果不将kapt版本用于您在项目中使用的任何注释处理器,则会弹出该问题。 正如@Vince提到Glide的情况,这可能发生在Dagger2Butterknife等。 如果您同时使用JavaKotlin,则需要保留两个依赖关系,如下所示($glideVersionGlide的预定义版本):

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

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

如果您正在使用Kotlin项目,那么kapt依赖项应该单独使用。

编辑 您应该记住的另一件事是,如果您已经在使用AndroidxAndroidx是一个伟大的重构,但在迁移它时可能会导致一些依赖关系崩溃。主流图书馆已经更新到Androidx,但是,其中一些不是,甚至不会。 如果问题没有消除我在此编辑上方提供的解决方案,您可以查看您的依赖项并确保它们也使用Androidx

编辑2 正如@Ted所说,我研究过,他是对的kapt也会处理java文件。只有kapt才能做到这一点,不需要保持kaptannotationProcessor依赖。


3
投票

尝试删除此行:

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

来自build.gradle文件的buildscript / repositories部分。

当我添加该行时,我收到了您描述的错误。当我删除它时,不再。该行应该只在allprojects / repositories部分中。


3
投票

删除testInstrumentationRunner对我有用:

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

2
投票

尝试在gradle.properties中设置android.enableJetifier = false。然后在Android Studio中使Invalidate Caches / Restart ...无效


1
投票

修复程序在4.2.0中,使用更高版本的google gms jar。

尝试改变:

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

通过这个版本:

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

希望这有效......

© www.soinside.com 2019 - 2024. All rights reserved.