每当我生成签名时apk在Android Studio中,默认情况下它给出了名称为App-release.apk …

我们可以进行任何设置,以便它应该提示并询问需要分配给APK的名称(以Eclipse的方式进行操作)

我要做的是 - 生成后重命名APK。这不会给出任何错误,但是是否有任何真实的方法,以便我可以在设置中进行任何更改以获取提示。

笔记::

在生成APK Android Studio时,请提示我选择位置(仅)enter image description here

答案

Yes we can change that but with some more attention

SeeThis

现在将其添加到您的build.gradle 在您的项目中,请确保已检查build variant 您的项目的release or Debug所以我在这里将构建变体设置为release但是您也可以选择作为调试。

    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)
                        )
                    }
                }
            }
        }

您可能会以这种不同的方法来做到这一点

 defaultConfig {
        applicationId "com.myapp.status"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        setProperty("archivesBaseName", "COMU-$versionName")
    }

在build.gradle中使用设置属性方法并且不要忘记在运行项目之前同步 gradle希望它能解决您的问题:)

Google Update最近添加的一种新方法来处理此操作You may now rename your build according to flavor or Variant output //以下来源来自开发人员Android文档 有关更多详细信息,请遵循上述文档链接
Using the Variant API to manipulate variant outputs is broken with the new plugin. It still works for simple tasks, such as changing the APK name during build time, as shown below:

// 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"
    }
}

重命名.aab捆扎这很好大卫·梅登贾克(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
}

是否需要上述代码

What I have observed in the latest version of the android studio 3.3.1

.AAB捆绑包的重命名是由以前的代码完成的,根本不需要任何任务重命名。

希望它能帮助你们。:)

来自: stackoverflow.com