+-
java – API’variable.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
}

这是模块app 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(),因此它必须是依赖项之一.我逐个注释掉依赖项,最后有一个空的依赖项列表.然而,警告仍然被抛出.然后我发现注释掉了应用插件:’com.google.gms.google-services’解决了这个问题.但我使用最新的谷歌服务插件,我显然不能使用任何firebase相关没有它.

我怎样才能解决这个问题?我不喜欢降级gradle插件,因为它只是一个临时修复.

最佳答案
最新版本的 Google Services Gradle Plugin(4.3.0)导致了这一点,将版本降级到4.2.0似乎暂时解决了问题 (source).但是谷歌将在2019年底之前发布更新版本.直到那时;

在项目级build.gradle文件中,在buildscript下 – >依赖.检查你是否有这条线

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

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

classpath 'com.google.gms:google-services:4.2.0'
点击查看更多相关文章

转载注明原文:java – API’variable.getMergeResources()’已过时,已替换为’variant.getMergeResourcesProvider()’ - 乐贴网