5
5

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でrelease用apkのファイル名を変更して特定フォルダにコピーする

Last updated at Posted at 2015-03-31

#1 build.gradleを編集する

build.gradle
  signingConfigs {
    release
  }
  buildTypes {
    release {
      signingConfig signingConfigs.release
    }
  }

  applicationVariants.all { variant ->
    if (variant.buildType.name.equals("release")) {
      variant.outputs.each { output ->
        if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) {
          // Rename APK
          def versionCode = defaultConfig.versionCode
          def versionName = defaultConfig.versionName
          def date = new java.text.SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date())
          def newName = "AppName_r${versionCode}_v${versionName}_${date}.apk"

          def publish = project.tasks.create("publishAll")

          // Move and Rename APK
          def task = project.tasks.create("publish${variant.name.capitalize()}Apk", Copy)
          task.from(output.outputFile)
          task.rename(output.outputFile.name, newName)
          task.into(deployTo)

          task.dependsOn variant.assemble
          publish.dependsOn task
        }
      }
    }
  }

...

  if (project.hasProperty('storeFile')) {
    android.signingConfigs.release.storeFile = new File(storeFile)
  }
  if (project.hasProperty('storePassword')) {
    android.signingConfigs.release.storePassword = storePassword
  }
  if (project.hasProperty('keyAlias')) {
    android.signingConfigs.release.keyAlias = keyAlias
  }
  if (project.hasProperty('keyPassword')) {
    android.signingConfigs.release.keyPassword = keyPassword
  }

#2 gradle.propertiesを作成して編集する

gradle.properties
storeFile=your.keystore
storePassword=yourpassword
keyAlias=youralias
keyPassword=yourpassword

deployTo=/Users/xxxx/Documents/apk

AndroidStudioの右端にある「Gradle tasks」を開き、
「publishAll」を探して実行するか(見つからない場合は、「Refresh」ボタンを押してみる)、以下のコマンドをプロジェクトフォルダで実行。

$ ./gradlew publishAll 

AppName_r5_v1.0.5_20150331_121230.apk
が、
/Users/xxxx/Documents/apk/下に作成されます。

#3 参考
http://qiita.com/takke/items/c6c774807f064500aca4
http://qiita.com/wada811/items/e8047f0f0fd1203b0fc5

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?