2
2

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 1 year has passed since last update.

Android Studioで出力されるAPKに任意の名前をつける

Posted at

Android Studioのビルド時に"app-release.apk"から毎回リネームするのが面倒なので、デフォルトで名前をつけたい。
ここでは、リリース時は"MyAndroidApp-v1.x.x-20230204-131212.apk"という名前をつけるようにする。デバッグ時はもとの"app-debug.apk"にする(なにもしない)。

開発環境

Android Studio Dolphin | 2021.3.1 Patch 1
Gradle version 7.3.3

変更箇所

(project)/app/build.gradle
...
buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        // ここから追加
        applicationVariants.all{
            variant ->
                variant.outputs.each{
                    output->
                        // app-release.apk -> MyAndroidApp-v1.x.x-20230204.apk
                        def myAppName = 'MyAndroidApp'
                        def formattedDate = new Date().format('yyyyMMdd-HHmmss')
                        def newName = output.outputFile.name
                        def version = variant.versionName
                        newName = newName.replace("app-release", "$myAppName-v$version-$formattedDate")
                        output.outputFileName  = newName
                }
        }
}
...

参考

2
2
1

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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?