突然,当同步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年底停止工作。你知道它是什么,如何解决它吗?


当前回答

这只是一个警告,可能会在2019年之前通过插件更新修复,所以不用担心。我建议你使用兼容版本的插件和gradle。

你可以在这里检查你的插件版本和gradle版本,以获得更好的体验和性能。

https://developer.android.com/studio/releases/gradle-plugin

尝试使用稳定版本以获得流畅且无警告/错误的代码。

其他回答

就我而言,我是这样做的。 总结,在gradle应用级别:更改以下内容:

variant.outputs.all { output ->
    variant.assemble.doLast {
        ....
    }
}

to

variant.outputs.all { output ->
variant.getAssembleProvider().configure() {
    it.doLast { 
        ....
    }
}

我在更新到3.3.0后就遇到了这个问题

如果你没有按照gradle文件中的错误状态去做,那就是某些插件仍然没有更新到更新的API导致了这个问题。要弄清楚哪个插件是它做以下(解释在“更好的调试信息时使用过时的API”的3.3.0公告):

添加'android.debug.obsoleteApi=true'到你的gradle。属性文件,该文件将用更详细的信息记录错误 重试并读取日志详细信息。会有“有问题的”插件的痕迹 确认后,试着禁用它,看看问题是否消失了,只是为了确定 进入插件的github页面并创建问题,其中将包含详细的日志和清晰的描述,因此您可以帮助开发人员更快地为每个人修复它 耐心等待他们修复问题,或者你自己修复问题,然后为开发者创造PR

希望能帮助到别人

升级Kotlin(插件和stdLib)版本到1.3.1解决了这个问题。更新整个项目的Kotlin版本,替换现有的Kotlin版本:

ext.kotlin_version = '1.3.50'

这只是一个警告,可能会在2019年之前通过插件更新修复,所以不用担心。我建议你使用兼容版本的插件和gradle。

你可以在这里检查你的插件版本和gradle版本,以获得更好的体验和性能。

https://developer.android.com/studio/releases/gradle-plugin

尝试使用稳定版本以获得流畅且无警告/错误的代码。

这解决了我的问题。我所需要做的就是在build.gradle(项目)级别文件的buildscript中降级我的google-services插件,如下所示

buildscript{
     dependencies {
        // From =>
        classpath 'com.google.gms:google-services:4.3.0'
        // To =>
        classpath 'com.google.gms:google-services:4.2.0'
        // Add dependency
        classpath 'io.fabric.tools:gradle:1.28.1'
    }
}