40
40

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AndroidStudioでAPKのファイル名にバージョン番号などを入れる設定

Last updated at Posted at 2014-07-02

Android Studio初心者です。

Release版のAPK生成時にファイル名を自動で付加したいので書いてみました。

build.grade
...
    signingConfigs {
        myConfig
    }

    buildTypes {
        release {
            runProguard true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-project.txt'
            signingConfig signingConfigs.myConfig
        }
    }

    applicationVariants.all { variant ->
        if (variant.buildType.name.equals("release")) {
            variant.outputs.each { output ->
                if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) {
                    def file = output.outputFile
                    def d = new java.text.SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date())
                    def newName = "TwitPane_r${defaultConfig.versionCode}_v${defaultConfig.versionName}_${d}.apk"
                    output.outputFile = new File(file.parent, newName)
                }
            }
        }
    }

...

// load signing settings from gradle.properties
if (project.hasProperty('storeFile')) {
    android.signingConfigs.myConfig.storeFile = file(storeFile)
}
if (project.hasProperty('storePassword')) {
    android.signingConfigs.myConfig.storePassword = storePassword
}
if (project.hasProperty('keyAlias')) {
    android.signingConfigs.myConfig.keyAlias = keyAlias
}
if (project.hasProperty('keyPassword')) {
    android.signingConfigs.myConfig.keyPassword = keyPassword
}
gradle.properties
storeFile=example.keystore
storePassword=example
keyAlias=example
keyPassword=example

signingConfig のファイル分離については こちら を参考にしました。

上記で gradle assembleRelease すると TwitPane_r252_v5.8.2_20140703_022651.apk のようなファイルが app/build/outputs に生成されました。

40
40
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
40
40

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?