others - android警告:API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'

同步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



我有这个应用模块的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年之前通过插件更新来解决,所以不用担心,我建议你使用兼容版本的插件和gradle 。

你可以在这里检查插件版本和gradle版本,以获得更好的体验和性能。

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

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

在我这里可以工作

这是由构建工具发出的警告,原因如下,
1插件之一是依靠Task而不是TaskProvider,我们无能为力,
2你已配置task的用法,因为它支持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.get().enabled = true // Replacement


 }


}




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



它为我删除了这个警告。

...