Android: How to change specific name of the generated apk file in Android Studio?

后端 未结 9 1691
遥遥无期
遥遥无期 2020-12-29 08:44

By default IDE genarate a apk like app-debug.apk or app-release.apk file but I need to generate specific name of the Apk of the Ap

相关标签:
9条回答
  • 2020-12-29 09:03

    You can use this for app name with current date and version

    android {
    def version = "2.4";
    def milestone = "1";
    def build = "0";
    def name = getDate()+"APP NAME WHAT YOU WANT"+"v"+version
    
    
    signingConfigs {
        config {
           ….
       }
    }
    compileSdkVersion Integer.parseInt(COMPILE_SDK)
    buildToolsVersion BUILD_TOOLS_VERSION
    defaultConfig {
       applicationId "com.PACKAGENAME"
       minSdkVersion Integer.parseInt(MIN_SDK_LIBRARY)
       targetSdkVersion Integer.parseInt(TARGET_SDK)
       versionCode 11
       versionName "2.3"
       multiDexEnabled true
    }
    buildTypes {
       debug {
           applicationVariants.all { variant ->
               variant.outputs.each { output ->
                   def apk = output.outputFile;
                   def newName;
                   newName = apk.name.replace("-" + variant.buildType.name, "")
                           .replace(project.name, name);
                   newName = newName.replace("-", "-" + version + "-" + milestone +
                           "-" + build + "-");
                   output.outputFile = new File(apk.parentFile, newName);
               }
           }
       }
    
    0 讨论(0)
  • 2020-12-29 09:04

    For Android Studio 3.1 this works for me:

    android {
         ...............
         ...............
    
         applicationVariants.all { variant ->
                changeAPKName(variant, defaultConfig)
            }
    
      compileOptions {
           sourceCompatibility JavaVersion.VERSION_1_8
           targetCompatibility JavaVersion.VERSION_1_8
           }
    
          .................................
          .................................
         }
    

    and

    def changeAPKName(variant, defaultConfig) {
        variant.outputs.all { output ->
            outputFileName = new File("xxxxx" + variant.versionName +".apk")
        }
    }
    
    0 讨论(0)
  • 2020-12-29 09:09

    For Android Studio 3, this works for me:

    applicationVariants.all { variant ->
            variant.outputs.all { output ->
                outputFileName = new File("AppName-" + variant.versionName + ".apk");
            }
    }
    
    0 讨论(0)
  • 2020-12-29 09:09

    Try this code:

    defaultConfig{
          applicationVariants.all { variant ->
                    changeAPKName(variant, defaultConfig)
                }
    }
    
    def changeAPKName(variant, defaultConfig) {
        variant.outputs.each { output ->
            if (output.zipAlign) {
                def file = output.outputFile
                output.packageApplication.outputFile = new File(file.parent, "Your APK NAME")
            }
            def file = output.packageApplication.outputFile
            output.packageApplication.outputFile = new File(file.parent, "Your APK NAME")
        }
    }
    
    0 讨论(0)
  • 2020-12-29 09:10

    Just add

       archivesBaseName = "NAME_YOU_WANT"
    

    in the android{} part of your gradle file.

    You'll get "NAME_YOU_WANT-release.apk" as name of the generated file.

    0 讨论(0)
  • 2020-12-29 09:13

    You just have to add following one line of code in app level gradle.

    1. For name only

    archivesBaseName = "NAME_YOU_WANT"

     defaultConfig {
    
           applicationId "com.PACKAGENAME"
    
           minSdkVersion Integer.parseInt(MIN_SDK_LIBRARY)
    
           targetSdkVersion Integer.parseInt(TARGET_SDK)
    
           versionCode 11
    
           versionName "2.3"
    
           multiDexEnabled true
    
           archivesBaseName = "NAME_YOU_WANT"
    
    
        }
    
    1. Name with version

    archivesBaseName = "NAME_YOU_WANT" + versionName

    defaultConfig {
    
       applicationId "com.PACKAGENAME"
    
       minSdkVersion Integer.parseInt(MIN_SDK_LIBRARY)
    
       targetSdkVersion Integer.parseInt(TARGET_SDK)
    
       versionCode 11
    
       versionName "2.3"
    
       multiDexEnabled true
    
       archivesBaseName = "NAME_YOU_WANT" + versionName
    }
    
    0 讨论(0)
提交回复
热议问题