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


当前回答

这里有一个临时的解决方案,如果你正在使用的房间只是升级到1.1.0或更高

implementation "android.arch.persistence.room:runtime:1.1.0"

它为我消除了这个警告。

其他回答

当插件检测到你正在使用一个不再受支持的API时,它现在可以提供更详细的信息来帮助你确定该API正在被使用的位置。要查看额外的信息,您需要在项目的gradle中包含以下内容。属性文件:

android.debug.obsoleteApi=true

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

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

1)在gradle.properties中添加android.debug.obsoleteApi=true。它将显示哪些模块受到警告日志的影响。

2)更新这些废弃的功能。

变体。javaCompile转换为variant.javaCompileProvider variant.javaCompile.destinationDir来 .destinationDir variant.javaCompileProvider.get ()

在我的案例中,它是由gms services 4.3.0引起的。所以我不得不把它改成:

com.google.gms:google-services:4.2.0

我通过跑步发现了这一点:

gradlew sync -Pandroid.debug.obsoleteApi=true

在终端。进入查看->工具窗口->终端在安卓工作室。

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

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

to

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