Release signing in gradle.properties for Android

后端 未结 6 1023
故里飘歌
故里飘歌 2021-01-30 23:20

So I\'m trying to convert all of my ant build scripts to gradle, and I\'ve been able to find ample resources and documentation on all of it except how to configure signing in th

6条回答
  •  感动是毒
    2021-01-31 00:12

    My requirements were that anyone without the keystore should be able to build properly. This is the cleanest way I could find:

    android {
        signingConfigs {
            release    //Filled in readSigningConfigIfAvailable()
        }
    
        buildTypes {
            release {
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-xyz.txt'
                readSigningConfigIfAvailable()
            }
        }
    }
    
    private void readSigningConfigIfAvailable() {
        if (hasAllSigningProperties()) {
            android.signingConfigs.release.storeFile = file(keystore_path)
            android.signingConfigs.release.storePassword = keystore_password
            android.signingConfigs.release.keyAlias = key_alias
            android.signingConfigs.release.keyPassword = key_password
            android.buildTypes.release.signingConfig = android.signingConfigs.release
        } else {
            android.buildTypes.release.signingConfig = null
        }
    }
    
    private boolean hasAllSigningProperties() {
        (hasProperty('keystore_path')
        && hasProperty('keystore_password')
        && hasProperty('key_alias')
        && hasProperty('key_password'))
    }
    

提交回复
热议问题