我今天将我的 Android Studio 更新到了 3.3 版本,它附带了 Gradle 插件版本 4.10.1。
以前,我的 build.gradle 将使用此代码的 apk 重命名为以下结构:
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", "")
}
}
但是更新后出现了这个错误。
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,因为您无法访问此插件版本的输出数据。
到目前为止,我已经尝试过这种方法但没有成功。
applicationVariants.all { variant ->
variant.flavors*.name.all { flavor ->
outputFileName = "${flavor}-${variant.buildType.name}-${variant.versionName}-${variant.versionCode}.apk".replace("-unsigned", "")
}
}
有什么想法吗?
============================================= ========
更新
我重新考虑了这个问题,我尝试了以下代码 fragment ,但我在检索该变体的味道时遇到了问题。
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。
关于android - 使用 Gradle 插件 v4.10.1 重命名 Apk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54196783/