关于com.android.tools.build:gradle:3.4.2的构建与apply plugin: 'com.novoda.bintray-release'之间的问题

前言:

  当您在阅读这篇记录时,说明您也正在处理关于lib库上传到Bintray,并可能add to jcenter中去,那么就会遇到如下警告

Android Studio Version:3.4.2

Android Gradle Plugin Version:3.4.2

Gradle Version:5.1.1

Novoda Bintray:0.9

根据以上IDE工具以及对应的插件版本,搭建了一个Android 项目,并配置好发布到Bintray,配置内容如下

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'
classpath 'com.novoda:bintray-release:0.9'

// 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
}

Module的build.gradle:

apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"


    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

publish {
    userOrg = 'itsdf07'//bintray.com用户名
    groupId = 'com.itsdf07'//jcenter上的路径
    artifactId = 'lib-alog'//项目名称
    publishVersion = '1.0.0'//版本号
    desc = 'An ALog Util library'//描述,不重要
    website = 'https://github.com/itsdf07/UtilsALog'//网站,最好有,不重要
}

  

当搭建完项目之后进行构建,会发现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'
原文地址:https://www.cnblogs.com/dfsu/p/11724630.html