Android studio将生成默认的apk名称为app-(release|debug).apk。
如何生成apk文件名,与com.example-debug.apk
等app的包名相同。
发布于 2015-09-08 14:59:23
您可以在不使用其他任务、设置archivesBaseName
的情况下完成此操作。
例如:
defaultConfig {
....
project.ext.set("archivesBaseName", "MyName-" + defaultConfig.versionName);
}
输出:
MyName-1.0.12-release.apk
在您的案例中:
project.ext.set("archivesBaseName", "com.example" );
发布于 2015-09-08 13:11:24
尝试将此代码放入模块的build.gradle中
applicationVariants.all { variant ->
variant.outputs.each { output ->
def file = output.outputFile
def appId = android.defaultConfig.applicationId
def fileName = appId + "-" variant.buildType.name +".apk"
output.outputFile = new File(file.parent, fileName)
}
}
发布于 2015-09-08 13:21:47
您可以看到这个link。或不合理的选择,用你想在文件浏览器中命名的名称来重命名你的release|debug.apk
。
此代码可能对您有用:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.each { output ->
def formattedDate = new Date().format('yyyyMMddHHmmss')
def newName = output.outputFile.name
newName = newName.replace("app-", "$rootProject.ext.appName-") //"MyAppName" -> I set my app variables in the root project
newName = newName.replace("-release", "-release" + formattedDate)
//noinspection GroovyAssignabilityCheck
output.outputFile = new File(output.outputFile.parent, newName)
}
}
}
debug {
}
}
享受您的代码:)
https://stackoverflow.com/questions/32449558
复制相似问题