相信大家在使用gradle定制自己打包出来的apk名字时,都遇到过这个问题吧:
WARNING: API 'variant.getPackageApplication()' is obsolete and has been replaced with 'variant.getPackageApplicationProvider()'.
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 variant.getPackageApplication(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
Affected Modules: app
原因就是:
在app模块下的build.gradle中,我们在android{}闭包中写了:
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
//自定义目录,我这里把apk包输出路径定义到:/工程根目录/output/项目代号
variant.getPackageApplication().outputDirectory =new File(project.rootDir.absolutePath +"/output/${projectId}/")
//apk名字定义为:自己想取的名字_版本名.apk
outputFileName ="自己想取的名字_${variant.versionName}.apk"
}
}
但是在使用了这段代码修改路径和apk名字的时候,AndroidStudio就会报以上警告,其实原因很简单,就是api过时了,需要修改一下api,修改如下即可
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
//把getPackageApplication()改成getPackageApplicationProvider().get()即可
variant.getPackageApplicationProvider().get().outputDirectory = new File(project.rootDir.absolutePath + "/output/${projectId}/")
outputFileName = "自己想取的名字_${variant.versionName}.apk"
}
}
网友评论