android 忽略过时api,android - 警告:API'variable.getJavaCompile()'已过时,已替换为'variant.getJavaCompileProvider(...

android - 警告:API'variable.getJavaCompile()'已过时,已替换为'variant.getJavaCompileProvider()'

在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年底停止工作。任何想法是什么,以及如何解决它?

14个解决方案

42 votes

更新到3.3.0后我遇到了这个问题

如果你没有在gradle文件中执行什么错误状态,那么它仍然没有更新到导致此错误的新API。 要找出哪个插件,请执行以下操作(如3.3.0声明中的“使用过时API时更好的调试信息”中所述):

将'android.debug.obsoleteApi = true'添加到gradle.properties文件中,该文件将记录错误并提供更多详细信息

再试一次,阅读日志详细信息。 会有一些“有问题”的插件

当你确定时,尝试禁用它,看看问题是否已经消失,只是为了确定

转到插件的github页面并创建包含详细日志和清晰描述的问题,以便您帮助开发人员更快地为每个人修复它

在他们修复它时要有耐心,或者你修复它并为开发者创建PR

希望它能帮助别人

Ewoks answered 2019-08-05T04:39:42Z

31 votes

这只是一个警告,它可能会在2019年之前修复插件更新,所以不用担心。 我建议你使用兼容版本的插件和gradle。

您可以在此处查看插件版本和gradle版本,以获得更好的体验和性能。

[https://developer.android.com/studio/releases/gradle-plugin]

尝试使用稳定版本获得平滑且无警告/无错误的代码。

Harshil Shah answered 2019-08-05T04:40:29Z

7 votes

现在使用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'

}

}

M.Noman answered 2019-08-05T04:38:20Z

5 votes

这是构建工具发出的警告,原因有两个。

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 {

Variants.all { variant ->

/* Disable Generating Build config */

// variant.generateBuildConfig.enabled = true //

variant.generateBuildConfigProvider.configure {

it.enabled = true // Replacement

}

}

}

同样,找到'variant.getJavaCompile()'或'variant.javaCompile','variant.getMergeResources()'或'variant.mergeResources'的用法。替换如上。

有关任务配置规避的更多信息

VenomVendor answered 2019-08-05T04:41:36Z

4 votes

如果我从application gradle删除此行:

apply plugin: 'io.fabric'

错误将不再出现。

参考链接github

Java coder answered 2019-08-05T04:42:16Z

3 votes

从classpath'com.android.tools.build:gradle:3.3.0-alpha13'返回到classpath'com.android.tools.build:gradle:3.2.0'

这对我有用

Narh-ngwah Ebenezer Watts answered 2019-08-05T04:42:47Z

2 votes

在我的情况下,我不得不评论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以来的一个错误

Anggrayudi H answered 2019-08-05T04:43:24Z

2 votes

将gradle更改为gradle:3.3.0

默认的“汇编”任务仅适用于普通变体。 添加测试变体。

android.testVariants.all { variant ->

tasks.getByName('assemble').dependsOn variant.getAssembleProvider()

}

还评论申请面料

//apply plugin: 'io.fabric'

Krste Moskov answered 2019-08-05T04:44:04Z

1 votes

将Kotlin(插件和stdLib)版本升级到1.3.1在我的案例中解决了这个警告。 通过将现有的Kotlin版本替换为:更新整个项目中的Kotlin版本:

ext.kotlin_version = '1.3.1'

erluxman answered 2019-08-05T04:44:30Z

1 votes

当插件检测到您正在使用不再受支持的API时,它现在可以提供更详细的信息,以帮助您确定API的使用位置。 要查看其他信息,您需要在项目的gradle.properties文件中包含以下内容:

android.debug.obsoleteApi=true

Hamed safari answered 2019-08-05T04:44:57Z

1 votes

将结构插件更新为最新的项目级gradle文件(不是应用级别)。 就我而言,这条线解决了这个问题

classpath 'io.fabric.tools:gradle:1.25.4'

classpath 'io.fabric.tools:gradle:1.28.0'

Bibaswann Bandyopadhyay answered 2019-08-05T04:45:25Z

0 votes

这里有一个临时的解决方法,如果你正在使用room只升级到1.1.0或更高版本

implementation "android.arch.persistence.room:runtime:1.1.0"

它为我删除了这个警告。

Sergio KS answered 2019-08-05T04:45:59Z

0 votes

降级Gradle版本对我有用:

classpath 'com.android.tools.build:gradle:3.2.0'

Naimish Verma answered 2019-08-05T04:46:24Z

0 votes

就我而言

build.gradle(Project)

ext.kotlin_version = '1.2.71'

更新为

ext.kotlin_version = '1.3.0'

看起来问题现在已经消失了

Sam answered 2019-08-05T04:47:06Z

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值