LoginSignup
117
99

More than 5 years have passed since last update.

Androidの署名情報(signingConfigs)を外出しよう

Posted at

Androidでgradleファイルを記述するときに、build.gradleのsigningConfigsの欄に直でパスワードを書いていませんか?

パスワードを直に書かない方法だとgradle.propertiesに設定を書いてそれを利用する方法、標準入力から毎度入力する方法もあります。ですがあまりスマートとはいえません。

しかしapply fromで外部のgradleファイルとして読み込むととても簡単に設定情報が外部ファイルに切り出せます。

やりかたは簡単で以下のとおり。

app/build.gradle

android {
    // ...

    // signingConfigs
    apply from: 'signingConfigs/debug.gradle', to: android
    apply from: 'signingConfigs/release.gradle', to: android

    buildTypes {
        debug {
            debuggable true
            signingConfig signingConfigs.debug
        }

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }
}

app/signingConfigs/debug.gradle

signingConfigs {
    debug {
        storeFile file("debug.keystore")
        storePassword "android"
        keyAlias "androiddebugkey"
        keyPassword "android"
    }
}

debug.gradleなどをプロジェクト間で共通にしておけば、署名ファイルが一意に使いまわせてよいです。

この方法は、signingConfigsだけでなくbuildTypesなどにも利用できるので、決まりきった設定は外部ファイルに切り出すと楽です。

app/build.gradle

android {
    // ...

    // signingConfigs
    apply from: 'signingConfigs/debug.gradle', to: android
    apply from: 'signingConfigs/release.gradle', to: android

    // buildTypes
    apply from: 'buildTypes/debug.gradle', to: android
    apply from: 'buildTypes/release.gradle', to: android
}

app/buildTypes/debug.gradle

buildTypes {
    debug {
        debuggable true
        signingConfig signingConfigs.debug
    }
}

簡単なサンプル作ったので実行確認にどぞ

117
99
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
117
99