API 'variant.getMergeResources()' 已过时,已被替换为 '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插件,谷歌播放服务插件和所有依赖项,但问题仍然存在。

下面是项目级 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'

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

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


答案 1

两个版本的Google Services Gradle插件( & )正在导致这种情况,升级版本似乎可以解决问题;4.3.04.3.14.3.2


在项目级文件中的 “下,检查是否有此行build.gradlebuildscript -> dependencies

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

如果是这样,请将其更改为

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

编辑:单击此处查看最新版本。(4.3.3) 编辑时。


推荐