LoginSignup
53

More than 5 years have passed since last update.

Gradle で複数種類の apk をビルドする

Last updated at Posted at 2014-01-18

複数種類の apk(ステージング用、リリース用など)をビルドするスクリプト。
プロジェクトのroot以下に、confディレクトリを掘って、その中にkeystoreファイルを置くスタイル。debug 用のはリポジトリに入れておくと良さそう。release 用のは入れるとまずいので、そこだけ頑張らないといけない。

android {
    // ...

    // デバッグ用 apk とリリース用 apk の署名の設定
    signingConfigs {
        debug {
            storeFile file("conf/debug.keystore")
            storePassword "android"
            keyAlias "androiddebugkey"
            keyPassword "android"
        }
        release {
            storeFile file("conf/release.keystore")
            storePassword "fugafugahogehoge"
            keyAlias "yokomark"
            keyPassword "foobarbaz"
        }
    }

    // ビルドの種類に応じて、ビルド時に実行するステップを設定
    buildTypes {
        release {
            debuggable false
            zipAlign true
            runProguard true
            proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
            signingConfig signingConfigs.release
        }
        debug {
            debuggable true
            zipAlign true
            runProguard false
            signingConfig signingConfigs.debug
        }
    }

    productFlavors {
        staging {
            proguardFile 'proguard-rules.txt'
            packageName "jp.yokomark.foo.staging"
        }

        production {
            proguardFile 'proguard-rules.txt'
            packageName "jp.yokomark.foo.product"
        }
    }
}

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
53