Help us understand the problem. What is going on with this article?

AndroidStudioでrelease用apkのファイル名を変更して特定フォルダにコピーする

More than 5 years have passed since last update.

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

le_skamba
Android/iPhoneアプリ開発者。その前はゲームプログラマをしてました。Windowsアプリも幾つか作りました。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away