API 'variant.getMergeResources()' 已过时并已替换为 'variant.getMergeResourcesProvider()'

API 'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()'

我在我的项目中遇到非常烦人的警告:

WARNING: API 'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
REASON: It is currently called from the following trace:

...

WARNING: Debugging obsolete API calls can take time during configuration. It's recommended to not keep it on at all times.
Affected Modules: app

由于此警告明年将成为错误,因此我想一劳永逸地修复它。

我已经更新了 gradle 插件、google 播放服务插件和所有依赖项,但问题仍然存在。

这是项目级 build.gradle 文件:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath 'com.google.gms:google-services:4.3.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是模块应用 build.gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.3"

    defaultConfig {
        applicationId "com.foo.bar"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 9
        versionName "1.08"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        checkReleaseBuilds false
        //If you want to continue even if errors found use following line
        abortOnError false
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    ...
}

apply plugin: 'com.google.gms.google-services'

如您所见,我没有直接使用 getMergeResources(),所以它一定是依赖项之一。我已经一个一个地注释掉依赖项,最后得到一个空的依赖项列表。但是,仍然发出警告。然后我发现注释掉 apply plugin: 'com.google.gms.google-services' 可以解决问题。但我使用最新的 google 服务插件,没有它我显然无法使用任何与 firebase 相关的东西。

我该如何解决这个问题?我不喜欢降级 gradle 插件,因为它只是一个临时修复。

请更改项目级别的类路径依赖性 Gradle:

buildscript {

    dependencies {

         classpath 'com.android.tools.build:gradle:3.1.4'
    }
 }

我正在使用它。它工作正常。这是一个稳定的版本。希望这个问题会在这个依赖的未来版本中得到解决。

Google Services Gradle Plugin (4.3.0 & 4.3.1) 的两个版本导致此问题,将版本升级到 4.3.2 似乎可以解决问题;


在你的 project-level build.gradle 文件中,在 buildscript -> dependencies 下,检查你是否有这一行

classpath 'com.google.gms:google-services:4.3.x'

如果是这样,将其更改为

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

编辑:点击here查看最新版本。 (4.3.3) 在编辑时。

是一个已知问题,将在下一个版本中修复:

https://github.com/google/play-services-plugins/issues/65

https://github.com/google/play-services-plugins/pull/62