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

nho*_*ass 125 android android-studio android-studio-3.0 android-studio-3.2 androidx

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

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

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

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

gradle.properties

android.enableJetifier=true
android.useAndroidX=true
Run Code Online (Sandbox Code Playgroud)

的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
}
Run Code Online (Sandbox Code Playgroud)

应用程序/的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'
Run Code Online (Sandbox Code Playgroud)

Bet*_*eto 98

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

1)文件 - >无效缓存/重启... 在此输入图像描述

2)构建 - >清理项目 在此输入图像描述

  • 以某种方式工作了几次重建,但我现在再次得到同样的错误.. (4认同)
  • 对我来说,清洁项目就足够了 (2认同)

A D*_*oid 26

使用AndroidX Test依赖项更新build.gradle文件后,出现了相同的错误。原来我忘了删除旧的junit依赖项。因此,对我来说,解决方法是简单地删除以下依赖项:

dependencies {
    ...
    testImplementation 'junit:junit:4.12'
}
Run Code Online (Sandbox Code Playgroud)


Dha*_*tel 17

添加的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
     }
}
Run Code Online (Sandbox Code Playgroud)

  • 不,不,我想你必须使用androidx包. (3认同)

Vin*_*nce 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"
Run Code Online (Sandbox Code Playgroud)

Java:

// Glide
def glide_version = "4.8.0"
implementation "com.github.bumptech.glide:glide:$glide_version"
annotationProcessor "com.github.bumptech.glide:compiler:$glide_version"
Run Code Online (Sandbox Code Playgroud)

一定要在gradle.properties中启用:

android.useAndroidX=true
android.enableJetifier=true
Run Code Online (Sandbox Code Playgroud)

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

希望对你有帮助!

  • 在没有Glide作为依赖关系的情况下,我也会出现此错误 (9认同)

bee*_*ino 7

通过转到主目录并键入来修复它 flutter clean

  • @KevinGalligan 然后使用 Flutter ;) (4认同)

M. *_*han 6

删除 testInstrumentationRunner 对我有用:

defaultConfig {
...
...
//        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
Run Code Online (Sandbox Code Playgroud)