Pra*_*abs 129 android android-studio
每当我在Android Studio中生成一个已签名的apk时,默认情况下它会将名称命名为app-release.apk ...
我们可以进行任何设置,以便它应该提示并询问我需要分配给apk的名称(在eclipse中的方式)
我所做的是 - 生成后重命名apk.这不会给出任何错误但是有任何真正的方法,以便我可以在设置中进行任何更改以获得提示.
注意::
生成apk安卓工作室给我一个选择位置的提示(仅)
Abh*_*bey 125
是的,我们可以改变这一点,但需要更多关注

现在在项目的build.gradle中添加它,同时确保已经检查了项目的构建变体,release or Debug
所以我在这里设置了我的构建变量,release但您也可以选择Debug.
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig getSigningConfig()
applicationVariants.all { variant ->
variant.outputs.each { output ->
def date = new Date();
def formattedDate = date.format('yyyyMMddHHmmss')
output.outputFile = new File(output.outputFile.parent,
output.outputFile.name.replace("-release", "-" + formattedDate)
//for Debug use output.outputFile = new File(output.outputFile.parent,
// output.outputFile.name.replace("-debug", "-" + formattedDate)
)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
你可以用不同的方法这样做
defaultConfig {
applicationId "com.myapp.status"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
setProperty("archivesBaseName", "COMU-$versionName")
}
Run Code Online (Sandbox Code Playgroud)
在build.gradle中使用Set属性方法 并且在运行项目之前不要忘记同步gradle 希望它能解决你的问题:)
谷歌更新最近添加的新方法 您现在可以根据风味或变体输出重命名您的构建 //源代码来自开发人员Android文档 更多详细信息请参阅上面的文档链接
使用Variant API来操作变量输出使用新插件.它仍然适用于简单的任务,例如在构建时更改APK名称,如下所示:
// If you use each() to iterate through the variant objects,
// you need to start using all(). That's because each() iterates
// through only the objects that already exist during configuration time—
// but those object don't exist at configuration time with the new model.
// However, all() adapts to the new model by picking up object as they are
// added during execution.
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "${variant.name}-${variant.versionName}.apk"
}
}
Run Code Online (Sandbox Code Playgroud)
重命名.aab bundle David Medenjak很好地回答了这个问题
tasks.whenTaskAdded { task ->
if (task.name.startsWith("bundle")) {
def renameTaskName = "rename${task.name.capitalize()}Aab"
def flavor = task.name.substring("bundle".length()).uncapitalize()
tasks.create(renameTaskName, Copy) {
def path = "${buildDir}/outputs/bundle/${flavor}/"
from(path)
include "app.aab"
destinationDir file("${buildDir}/outputs/renamedBundle/")
rename "app.aab", "${flavor}.aab"
}
task.finalizedBy(renameTaskName)
}
//@credit to David Medenjak for this block of code
}
Run Code Online (Sandbox Code Playgroud)
是否需要上面的代码
我在android studio 3.3.1的最新版本中观察到的
.aab包的重命名由前面的代码完成,不需要任何任务重命名全部.
希望它会帮助你们.:)
Joh*_*Doe 67
你可能会得到最新的android gradle插件(3.0)的错误:
无法设置只读属性'outputFile'的值
根据迁移指南,我们现在应该使用以下方法:
applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "${applicationName}_${variant.buildType.name}_${defaultConfig.versionName}.apk"
}
}
Run Code Online (Sandbox Code Playgroud)
注2:主要变化如下:
all现在用于代替each迭代变量输出.outputFileName 使用property而不是改变文件引用.ran*_*913 52
我修改了@Abhishek Chaubey的答案来改变整个文件名:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.each { output ->
project.ext { appName = 'MyAppName' }
def formattedDate = new Date().format('yyyyMMddHHmmss')
def newName = output.outputFile.name
newName = newName.replace("app-", "$project.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 {
}
}
Run Code Online (Sandbox Code Playgroud)
这会生成一个文件名,如: MyAppName-release20150519121617.apk
Fer*_*Fer 41
(已编辑,可与Android Studio 3.0和Gradle 4配合使用)
我正在寻找一个更复杂的apk文件名重命名选项,我写了这个解决方案,用以下数据重命名apk:
你会得到一个这样的apk:myProject_dev_debug_1.3.6_131016_1047.apk.
你可以在这里找到完整的答案.希望能帮助到你!
在build.gradle中:
android {
...
buildTypes {
release {
minifyEnabled true
...
}
debug {
minifyEnabled false
}
}
productFlavors {
prod {
applicationId "com.feraguiba.myproject"
versionCode 3
versionName "1.2.0"
}
dev {
applicationId "com.feraguiba.myproject.dev"
versionCode 15
versionName "1.3.6"
}
}
applicationVariants.all { variant ->
variant.outputs.all { output ->
def project = "myProject"
def SEP = "_"
def flavor = variant.productFlavors[0].name
def buildType = variant.variantData.variantConfiguration.buildType.name
def version = variant.versionName
def date = new Date();
def formattedDate = date.format('ddMMyy_HHmm')
def newApkName = project + SEP + flavor + SEP + buildType + SEP + version + SEP + formattedDate + ".apk"
outputFileName = new File(newApkName)
}
}
}
Run Code Online (Sandbox Code Playgroud)
Anr*_*ian 21
这是一个更短的方式:
defaultConfig {
...
applicationId "com.blahblah.example"
versionCode 1
versionName "1.0"
setProperty("archivesBaseName", applicationId + "-v" + versionCode + "(" + versionName + ")")
//or so
archivesBaseName = "$applicationId-v$versionCode($versionName)"
}
Run Code Online (Sandbox Code Playgroud)
它给你起名字com.blahblah.example-v1(1.0)-debug.apk(在调试模式下)
Android Studio默认按构建类型名称添加versionNameSuffix,如果要覆盖它,请执行下一步:
buildTypes {
debug {
...
versionNameSuffix "-MyNiceDebugModeName"
}
release {
...
}
}
Run Code Online (Sandbox Code Playgroud)
调试模式下的输出:com.blahblah.example-v1(1.0)-MyNiceDebugModeName.apk
我基于@Fer答案编写了更通用的解决方案。
还应该与风味和积累型的配置工作applicationId,versionName,versionCode。
在build.gradle中:
android {
...
applicationVariants.all { variant ->
variant.outputs.each { output ->
def appId = variant.applicationId
def versionName = variant.versionName
def versionCode = variant.versionCode
def flavorName = variant.flavorName // e. g. free
def buildType = variant.buildType // e. g. debug
def variantName = variant.name // e. g. freeDebug
def apkName = appId + '_' + variantName + '_' + versionName + '_' + versionCode + '.apk';
output.outputFile = new File(output.outputFile.parentFile, apkName)
}
}
}
Run Code Online (Sandbox Code Playgroud)
apk名称示例: com.example.app_freeDebug_1.0_1.apk
有关variant变量的更多信息,请参见ApkVariant和BaseVariant接口定义。
android.applicationVariants.all在您的应用程序级别 gradle 中添加如下块
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
lintOptions {
disable 'MissingTranslation'
}
signingConfig signingConfigs.release
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "${applicationId}_${versionCode}_${variant.flavorName}_${variant.buildType.name}.apk"
}
}
}
debug {
applicationIdSuffix '.debug'
versionNameSuffix '_debug'
}
}
Run Code Online (Sandbox Code Playgroud)
2019/03/25 可用
| 归档时间: |
|
| 查看次数: |
101998 次 |
| 最近记录: |