使用Gradle插件v4.10.1重新命名的APK [英] Apk rename with the Gradle plugin v4.10.1
问题描述
我今天已将我的Android Studio更新为Gradle插件版本4.10.1附带的3.3版本.
I´ve updated my Android Studio today to the 3.3 version which came with Gradle plugin version 4.10.1.
以前,我的build.gradle使用此代码将apk的名称重命名为以下结构:
Previously, my build.gradle was renaming my apk´s with this code to the following structure:
app- {buildType [release | debug]}-{flavor [prod | stage]}-{versionName [1.2.4]-{versionCode [43]}.apk
app-release-prod-1.1.4-45.apk .
applicationVariants.all { variant ->
variant.outputs.all { output ->
outputFileName = output.outputFile.name.replace(".apk", "-${variant.versionName}-${variant.versionCode}.apk").replace("-unsigned", "")
}
}
但是更新后出现了此错误.
But I got this error after updating.
警告:API'variantOutput.getPackageApplication()'已过时,并已替换为'variant.getPackageApplicationProvider()'.它将在2019年底删除.有关更多信息,请参见 https://d.android.com/r/tools/避免任务配置.要确定调用variantOutput.getPackageApplication()的内容,请在命令行上使用-Pandroid.debug.obsoleteApi = true来显示堆栈跟踪.受影响的模块:应用
WARNING: API 'variantOutput.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 variantOutput.getPackageApplication(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace. Affected Modules: app
问题出在output.outputFile.name上,因为您无法访问此插件版本上的输出数据.
The problem is at output.outputFile.name since you can't access output data on this plugin version.
到目前为止,我尝试这种方法都没有成功.
So far I´ve tried this approach without success.
applicationVariants.all { variant ->
variant.flavors*.name.all { flavor ->
outputFileName = "${flavor}-${variant.buildType.name}-${variant.versionName}-${variant.versionCode}.apk".replace("-unsigned", "")
}
}
有什么主意吗?
========================================================
=======================================================
更新
我在这个问题上很重述,我尝试了以下代码段,但是在检索该变体的样式时遇到了问题.
I took a retake on this matter, I´ve tried the following snippet, but I'm having issues retrieving the flavor of that variant.
android.applicationVariants.all { variant ->
def flavor = variant.flavorName
variant.outputs.all { output ->
def builtType = variant.buildType.name
def versionName = variant.versionName
def versionCode = variant.versionCode
outputFileName = "app-${flavor}-${builtType}-${versionName}-${versionCode}.apk"
}
}
outputs: app--release-1.0.4-88.apk
谢谢
推荐答案
尝试一下:
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
def builtType = variant.buildType.name
def versionName = variant.versionName
def versionCode = variant.versionCode
def flavor = variant.flavorName
outputFileName = "app-${flavor}-${builtType}-${versionName}-${versionCode}.apk"
}
}
这将输出以下apk名称: app-release-myFlavor-0.0.1-1.apk.
This outputs the following apk name : app-release-myFlavor-0.0.1-1.apk.
这篇关于使用Gradle插件v4.10.1重新命名的APK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!