directorio
I. Introducción
Por lo general, desarrollar todos sabemos que tenemos que estar archivo apk paquete en línea en estudio Android, pero el nombre del paquete predeterminado o aplicación-release.apk nombres como App-debug.apk, lo que no es reconocible de.
Aquí echamos un vistazo a cómo Android Estudio de edición en bloque generan los nombres de los archivos apk.
En segundo lugar, la aplicación del código
1, Gradle 3.0 la siguiente versión
Agregue el código siguiente en el archivo de la aplicación build.gradle:
android {
...
//签名
signingConfigs{
release{
storeFile file("xxxx.jks")
storePassword '123456'
keyAlias 'xxxx'
keyPassword '123456'
}
debug{
storeFile file("xxxx.jks")
storePassword '123456'
keyAlias 'xxxx'
keyPassword '123456'
}
}
productFlavors{
google{
manifestPlaceholders = [
SDKChannel: "google",
app_name : "@string/app_name"
]
}
baidu{
manifestPlaceholders = [
SDKChannel: "baidu",
app_name : "@string/app_name"
]
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//整理优化apk文件的工具,它能提高系统和应用的运行效率,更快的读写apk中的资源,降低内存的使用
zipAlignEnabled true
}
debug{
signingConfig signingConfigs.debug
}
}
applicationVariants.all { variant ->
variant.outputs.each{ output ->
if(output.outputFile != null
&& output.outputFile.name.endsWith('.apk')){
def apkFile = new File(
output.outputFile.getParent(),
"SDK_${variant.flavorName}_${variant.buildType.name}_V${variant.versionName}_${buildTime()}.apk"
)
output.outputFile = apkFile
}
}
}
}
def buildTime(){
def date = new Date()
def formattedDate = date.format('yyyyMMddHHmm')
return formattedDate
}
2, Gradle 3.0 o posterior
android {
...
//签名
signingConfigs{
release{
storeFile file("xxxx.jks")
storePassword '123456'
keyAlias 'xxxx'
keyPassword '123456'
}
debug{
storeFile file("xxxx.jks")
storePassword '123456'
keyAlias 'xxxx'
keyPassword '123456'
}
}
productFlavors{
google{
manifestPlaceholders = [
SDKChannel: "google",
app_name : "@string/app_name"
]
}
baidu{
manifestPlaceholders = [
SDKChannel: "baidu",
app_name : "@string/app_name"
]
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//整理优化apk文件的工具,它能提高系统和应用的运行效率,更快的读写apk中的资源,降低内存的使用
zipAlignEnabled true
}
debug{
signingConfig signingConfigs.debug
}
}
android.applicationVariants.all {variant ->
variant.outputs.all {
//在这里修改apk文件名,引号内的字符串都可以随便定义
outputFileName = "SDK_${variant.flavorName}_${variant.buildType.name}_V${variant.versionName}_${buildTime()}.apk"
}
}
}
def buildTime(){
def date = new Date()
def formattedDate = date.format('yyyyMMddHHmm')
return formattedDate
}
Descripción:
-
{variant.flavorName}
: Nombre de canal; -
{variant.buildType.name}
: Release o de depuración paquetes; -
{variant.versionName}
: Nombre de la versión; -
{buildTime()}
La hora actual;
Embalaje resultados son los siguientes: