API 'variant.getMergeResources()' 已过时,已被替换为 'variant.getMergeResourcesProvider()'
2022-09-03 00:36:03
我在我的项目中遇到了非常烦人的警告:
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插件,因为它只是一个临时修复。