Android Studio Version:3.4.2
Android Gradle Plugin Version:3.4.2
Gradle Version:5.1.1
根据以上IDE工具以及对应的插件版本,搭建了一个Android 项目,app的build.gradle如下:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
当搭建完项目之后进行构建,会发现AS报了如下警告:
WARNING: API 'variantOutput.getPackageLibrary()' is obsolete and has been replaced with 'variant.getPackageLibraryProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variantOutput.getPackageLibrary(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
Affected Modules: *****
看到以上信息,我们都能看懂这个警告的原因是在当前的Android Gradle Plugin Version中,API->variantOutput.getPackageLibrary()已经过时了,替代它的是variant.getPackageLibraryProvider()
那么我们会发现,新搭建的项目,我们并没有使用到这些API接口,为什么会报出这个警告呢?
经过多方资料查阅,这个是谷歌在做相应版本升级时遗留下来的问题,它并不是bug,只是会影响到同您一样,看到这个警告浑身不舒服的同类人!
解决方案:
1、等待升级,看是否能去掉这个警告
2、降低版本,退回会出现这个警告之前的版本
我的解决方案是:降低版本
classpath 'com.android.tools.build:gradle:3.4.2'
--->
classpath 'com.android.tools.build:gradle:3.2.1'