在Syncing Gradle突然间,我收到此错误:
WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance
Affected Modules: app
我为app模块准备了这个build.gradle
:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
android {
compileSdkVersion 28
buildToolsVersion "28.0.2"
defaultConfig {
applicationId "..."
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "..."
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
versionNameSuffix = version_suffix
[...]
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
[...]
}
debug {
[...]
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.61"
implementation 'androidx.appcompat:appcompat:1.0.0-rc02'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "com.android.support:preference-v7:28.0.0"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation 'com.google.android.material:material:1.0.0-rc02'
[...]
}
我可以正确编译应用程序,但它有点麻烦,而且正如我所看到的,某些东西将在2019年底停止工作。任何想法是什么,以及如何解决它?
现在使用update Fabric Gradle版本1.28.0修复此问题:
更新发布:2019年3月19日
请看这个链接:https://docs.fabric.io/android/changelog.html#march-15-2019
请更新项目级Gradle中的类路径依赖项:
buildscript {
// ... repositories, etc. ...
dependencies {
// ...other dependencies ...
classpath 'io.fabric.tools:gradle:1.28.0'
}
}
将gradle更改为gradle:3.3.0
默认的“汇编”任务仅适用于普通变体。添加测试变体。
android.testVariants.all { variant ->
tasks.getByName('assemble').dependsOn variant.getAssembleProvider()
}
还评论申请面料
//apply plugin: 'io.fabric'
当插件检测到您正在使用不再受支持的API时,它现在可以提供更详细的信息,以帮助您确定API的使用位置。要查看其他信息,您需要在项目的gradle.properties文件中包含以下内容:
android.debug.obsoleteApi=true
就我而言
build.gradle(Project)
是
ext.kotlin_version = '1.2.71'
更新为
ext.kotlin_version = '1.3.0'
看起来问题现在已经消失了
将结构插件更新为最新的项目级gradle文件(不是应用级别)。就我而言,这条线解决了这个问题
classpath 'io.fabric.tools:gradle:1.25.4'
至
classpath 'io.fabric.tools:gradle:1.28.0'
这里有一个临时的解决方法,如果你正在使用room只升级到1.1.0或更高版本
implementation "android.arch.persistence.room:runtime:1.1.0"
它为我删除了这个警告。
降级Gradle版本对我有用:
classpath 'com.android.tools.build:gradle:3.2.0'
保持项目(不是应用程序)Build.gradle依赖项classpath版本代码是新的
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0-beta01'
classpath 'com.novoda:bintray-release:0.8.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
更新到3.3.0后我遇到了这个问题
如果你没有在gradle文件中执行什么错误状态,那么它仍然没有更新到导致此错误的新API。要找出哪个插件,请执行以下操作(如"Better debug info when using obsolete API" of 3.3.0 announcement中所述):
希望它能帮助别人
这只是一个警告,它可能会在2019年之前修复插件更新,所以不用担心。我建议你使用兼容版本的插件和gradle。
您可以在此处查看插件版本和gradle版本,以获得更好的体验和性能。
https://developer.android.com/studio/releases/gradle-plugin
尝试使用稳定版本获得平滑且无警告/无错误的代码。
就我而言,它是由gms服务4.3.0引起的。所以我不得不把它改成:
com.google.gms:google-services:4.2.0
我通过运行找到了这个:
gradlew sync -Pandroid.debug.obsoleteApi=true
在终端。转到视图 - >工具窗口 - > Android Studio中的终端。
这是构建工具发出的警告,原因有两个。 1.其中一个插件依赖于Task而不是TaskProvider,我们无能为力。 2.您已配置任务的使用,因为它支持TaskProvider。
WARNING: API 'variant.getGenerateBuildConfig()' is obsolete and has been replaced with 'variant.getGenerateBuildConfigProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance
WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance
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
请注意下面的片段并更新。
android {
<library|application>Variants.all { variant ->
/* Disable Generating Build config */
// variant.generateBuildConfig.enabled = true // <- Deprecated
variant.generateBuildConfigProvider.configure {
it.enabled = true // Replacement
}
}
}
同样,找到'variant.getJavaCompile()'
或'variant.javaCompile'
,'variant.getMergeResources()'
或'variant.mergeResources'
的用法。如上所述替换。
有关Task Configuration Avoidance的更多信息
从classpath'com.android.tools.build:gradle:3.3.0-alpha13'返回到classpath'com.android.tools.build:gradle:3.2.0'
这对我有用
将Kotlin(插件和stdLib)版本升级到1.3.1在我的案例中解决了这个警告。通过将现有的Kotlin版本替换为:更新整个项目中的Kotlin版本:
ext.kotlin_version = '1.3.1'
在我的情况下,我不得不评论com.google.firebase.firebase-crash
插件:
apply plugin: 'com.android.application'
// apply plugin: 'com.google.firebase.firebase-crash' <== this plugin causes the error
这是自Android Studio 3.3.0以来的一个错误