Change generated apk name from “app-debug.apk”

不想你离开。 提交于 2019-11-30 17:23:31

You can use applicationVariants and change the output file in the build.gradle. You can also modify the name regarding to your needs.

buildTypes{

    applicationVariants.all { variant ->                              
        variant.outputs.each { output ->                              
            output.outputFile = file("$project.buildDir/apk/test.apk")
        }                                                             
    }

}

In build.gradle (Module: app):

android {
    ...
    defaultConfig {
        ...
        setProperty("archivesBaseName", "MyNewAppNameGoesHere")
    }
}

This works by modifying the archivesBaseName-property and works for Gradle Version >= 2.0, last tested with 2.1.0.

Solution for gradle3:

android.applicationVariants.all { variant ->
    variant.outputs.all {
        outputFileName = applicationId;
        outputFileName += "-v" + android.defaultConfig.versionName;
        if (variant.buildType.name == "release") {
            outputFileName += ".apk";
        } else {
            outputFileName += "-SNAPSHOT.apk";
        }
    }
}
pklinken

The 'app' part of the name uses the folder name of your application's module (default is 'app'). See the link below on how to change that.
Why is my APK name generic?

The '-debug' prefix is something you can change in the Module settings at Build Types

If anyone is looking to change apk name outside the Android studio(just to send this file to someone else, as in my case), just right click the app name and change it to whatever you want.

David Carlson
defaultConfig {  

    applicationId "com.dcarl661.awesomelayout"

    minSdkVersion 14

    targetSdkVersion 25

    versionCode 1

    versionName "1.0"

    //here put it in the section where you have the version stuff
    setProperty("archivesBaseName", "AwesomeLayout")

}
Valentin Kuhn

Maybe this question (and its accepted answer) are interesting for you: How to set versionName in APK filename using gradle? It describes how to put your versionName into the APK name.

You have to use the 'Update' part of the accepted answer. Also you need the versionName (in this example) declared in your defaultConfig in the build.gradle file. It does also work if you define versionCode in the build.gradle (as described here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Manifest-entries ).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!