【问题标题】:API 'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()'API 'variant.getMergeResources()' 已过时,已替换为 'variant.getMergeResourcesProvider()'
【发布时间】:2019-06-28 11:20:12
【问题描述】:

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

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 play services 插件和所有依赖项,但问题仍然存在。

这是项目级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' 可以解决这个问题。但是我使用最新的谷歌服务插件,如果没有它,我显然无法使用任何与 firebase 相关的东西。

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

【问题讨论】:

  • 我无法确定,因为在我的情况下更新 gradle 插件会导致另一个问题 (discuss.cocos2d-x.org/t/…),但无论如何我都会接受你的回答 :)

标签: java android android-studio gradle android-gradle-plugin


【解决方案1】:

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


在您的项目级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) 在编辑时。

【讨论】:

  • 谢谢这解决了我的问题。这是谷歌的错误吗?
  • @Saeid 很可能,是的!我猜谷歌也会犯错。不客气:)
【解决方案2】:

【讨论】:

    【解决方案3】:

    请在项目级 Gradle 中更改您的类路径依赖项:

    buildscript {
    
        dependencies {
    
             classpath 'com.android.tools.build:gradle:3.1.4'
        }
     }
    

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

    【讨论】:

    • 但是 3.4.1 也很稳定。 3.1.4 有点老了,缺少一些功能。
    • 那你可以试试这个——3.3.0一次
    猜你喜欢
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 2019-09-28
    • 1970-01-01
    • 2019-12-11
    相关资源
    最近更新 更多