在 Android Studio 3.5 中使用 Build Variant 重命名应用程序的存档名称
Rename archive Name for app with Build Variant in Android Studio 3.5
我正在使用以下 gradle 代码为多个 apk 构建单一代码:
flavorDimensions "version"
productFlavors {
Free {
dimension "version"
applicationId "com.exampleFree.app"
}
Paid {
dimension "version"
applicationId "com.examplePaid.app"
}
}
现在,当我构建时,它会创建如下名称的存档应用程序:
app-Free-debug.apk
当我在 gradle 中包含以下代码时,
setProperty("archivesBaseName","")
现在创建如下 APK 存档名称
-Free-debug.apk
我需要我的 APK 文件名如下
Free-debug.apk
我已经很接近了,但是如何删除附加在前缀中的连字符 (-)
?
在这里你可以像这样使用android迁移。
android {
//........
flavorDimensions "version"
productFlavors {
Free {
dimension "version"
applicationId "com.exampleFree.app"
}
Paid {
dimension "version"
applicationId "com.examplePaid.app"
}
}
applicationVariants.all { variant ->
variant.outputs.all { output ->
def appId = variant.applicationId// com.exampleFree.app OR com.examplePaid.app
def versionName = variant.versionName
def versionCode = variant.versionCode // e.g 1.0
def flavorName = variant.flavorName // e. g. Free
def buildType = variant.buildType.name // e. g. debug
def variantName = variant.name // e. g. FreeDebug
//customize your app name by using variables
outputFileName = "${variantName}.apk"
}
}}
Apk 名称 FreeDebug.apk
证明
我正在使用以下 gradle 代码为多个 apk 构建单一代码:
flavorDimensions "version"
productFlavors {
Free {
dimension "version"
applicationId "com.exampleFree.app"
}
Paid {
dimension "version"
applicationId "com.examplePaid.app"
}
}
现在,当我构建时,它会创建如下名称的存档应用程序:
app-Free-debug.apk
当我在 gradle 中包含以下代码时,
setProperty("archivesBaseName","")
现在创建如下 APK 存档名称
-Free-debug.apk
我需要我的 APK 文件名如下
Free-debug.apk
我已经很接近了,但是如何删除附加在前缀中的连字符 (-)
?
在这里你可以像这样使用android迁移。
android {
//........
flavorDimensions "version"
productFlavors {
Free {
dimension "version"
applicationId "com.exampleFree.app"
}
Paid {
dimension "version"
applicationId "com.examplePaid.app"
}
}
applicationVariants.all { variant ->
variant.outputs.all { output ->
def appId = variant.applicationId// com.exampleFree.app OR com.examplePaid.app
def versionName = variant.versionName
def versionCode = variant.versionCode // e.g 1.0
def flavorName = variant.flavorName // e. g. Free
def buildType = variant.buildType.name // e. g. debug
def variantName = variant.name // e. g. FreeDebug
//customize your app name by using variables
outputFileName = "${variantName}.apk"
}
}}
Apk 名称 FreeDebug.apk
证明