Wednesday, October 21, 2015

Changing the .apk file's name in Android Studio

This is here, so I can remember next time. Use it if you will!

My version of Android Studio ( 1.4 ) does not allow you to change the name of the file produced by "Generate Signed APK...". At least if it does, I have no idea where.

So, to get an .apk that says something other than "app-release.apk" you need to modify your "build.gradle (Module:app) file by including the italicized code in the code below:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    defaultConfig {
        applicationId "ca.jlcreative.discountcalculator"
        minSdkVersion 10
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def newName = output.outputFile.name
                    newName = newName.replace("app", "$defaultConfig.applicationId")
                    output.outputFile = new File(output.outputFile.parent, newName)
                }
            }
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.google.android.gms:play-services-ads:7.0.0'
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'com.android.support:preference-v7:23.0.1'
}

No comments:

Post a Comment