突然,当同步Gradle,我得到这个错误:

警告:API 'variant.getJavaCompile()'已经过时 替换为'variant.getJavaCompileProvider()'。 它将在2019年底被移除。 欲了解更多信息,请参见https://d.android.com/r/tools/task-configuration-avoidance 受影响模块:app

我有这样的身材。应用模块的Gradle:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'

apply plugin: 'io.fabric'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.2"
    defaultConfig {
        applicationId "..."
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "..."
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        versionNameSuffix = version_suffix

        [...]
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

            [...]
        }
        debug {
            [...]
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.61"
    implementation 'androidx.appcompat:appcompat:1.0.0-rc02'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation "com.android.support:preference-v7:28.0.0"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
    implementation 'com.google.android.material:material:1.0.0-rc02'

    [...]
}

我可以正确地编译应用程序,但它有点麻烦,在我看来,有些东西将在2019年底停止工作。你知道它是什么,如何解决它吗?


当前回答

这是一个很常见的问题。如果不使用这些方法,解决方案是更新库。 请更新您的kotlin版本,以及所有依赖的面料,protobuf等。如果您确定已经更新了所有内容,请尝试询问库的作者。

其他回答

降级版本的Gradle对我来说很管用:

classpath 'com.android.tools.build:gradle:3.2.0'

在我的例子中,我必须注释掉com.google.firebase。firebase-crash插件:

apply plugin: 'com.android.application'
// apply plugin: 'com.google.firebase.firebase-crash' <== this plugin causes the error

这是Android Studio 3.3.0以来的bug

这主要是由于过时的图书馆。要手动检查新更新,您应该导航到

分析>“按名称运行巡检”

这应该足够了。另一个选择是运行gradle依赖更新使用

。/ gradlew dependencyUpdates

这将产生如下的报告:

:dependencyUpdates

------------------------------------------------------------
: Project Dependency Updates (report to plain text file)
------------------------------------------------------------

The following dependencies are using the latest milestone version:
 - com.github.ben-manes:gradle-versions-plugin:0.15.0

The following dependencies have later milestone versions:
 - com.google.auto.value:auto-value [1.4 -> 1.4.1]
 - com.google.errorprone:error_prone_core [2.0.19 -> 2.0.21]
 - com.google.guava:guava [21.0 -> 23.0-rc1]
 - net.ltgt.gradle:gradle-apt-plugin [0.9 -> 0.10]
 - net.ltgt.gradle:gradle-errorprone-plugin [0.0.10 -> 0.0.11]

...

在项目级构建中升级谷歌服务。Gradle解决了我的问题。

升级后:

dependencies {
    ...
    classpath 'com.google.gms:google-services:4.3.2'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

从build.gradle中更改谷歌Services版本:

dependencies {
  classpath 'com.google.gms:google-services:4.2.0'
}