如何在Android Studio中生成具有自定义名称的输出APK文件?
作者:互联网
我想使用自定义名称生成输出apk文件.例如.默认情况下,Android Studio会生成“ app-debug.apk”文件.但我希望它是-“ MyAppName_myCurrentProdFlavour_vMyVersionName.apk”
如何使用模块的build.gradle文件执行此操作
解决方法:
您可以将以下机制分别用于调试和发行版本,这将允许您为每个版本提供不同的名称.
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.each { output ->
project.ext { appName = 'MY-CUSTOM-APP' }
def newName = output.outputFile.name
newName = newName.replace("app-", "$project.ext.appName-")
output.outputFile = new File(output.outputFile.parent, newName)
}
}
signingConfig signingConfigs.MyApp
}
release {
debuggable false
jniDebuggable false
applicationVariants.all { variant ->
variant.outputs.each { output ->
project.ext { appName = 'MY-CUSTOM-APP' }
def newName = output.outputFile.name
newName = newName.replace("app-", "$project.ext.appName-")
output.outputFile = new File(output.outputFile.parent, newName)
}
}
signingConfig signingConfigs.MyApp
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
乐意效劳!!!
标签:android-gradle,android-studio,build-gradle,android 来源: https://codeday.me/bug/20191108/2009350.html