Confused with signing android APK?

南楼画角 提交于 2019-12-02 00:20:24

You can put the .jks file anywhere.
It means that you can put the file inside your project, or you can put the file in an external folder (just take a look the path below). It depends by your policy.

Just use gradle to configure the signing of your apk.

android {

    signingConfigs {
        release
    }

    buildTypes {
            release {
                signingConfig signingConfigs.release
            }
    }
}

Simple way: just define the credential inside your build.gradle file.

signingConfigs {
     release {
            //Pay attention to the path. You can use a relative path or an absolute path
            storeFile file("../your_key_store_file.jks")
            storePassword 'some_password'
            keyAlias 'alias_name'
            keyPassword 'key_password'

     }
  }

Using a .properties file to store the credentials outside the script (for example if you don't want to push the credential in a git repo).

Example: signing.properties

STORE_FILE=/path/to/your.keystore
STORE_PASSWORD=yourkeystorepass
KEY_ALIAS=projectkeyalias
KEY_PASSWORD=keyaliaspassword

Then get these values in your build.gradle file:

signingConfigs {
        release
 }

Then define:

def Properties props = new Properties()
def propFile = new File('signing.properties')
if (propFile.canRead()){
    props.load(new FileInputStream(propFile))

    if (props!=null && props.containsKey('STORE_FILE') && props.containsKey('STORE_PASSWORD') &&
            props.containsKey('KEY_ALIAS') && props.containsKey('KEY_PASSWORD')) {
        android.signingConfigs.release.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.release.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.release.keyAlias = props['KEY_ALIAS']
        android.signingConfigs.release.keyPassword = props['KEY_PASSWORD']
    } else {
        println 'signing.properties found but some entries are missing'
        android.buildTypes.release.signingConfig = null
    }
}else {
    println 'signing.properties not found'
    android.buildTypes.release.signingConfig = null
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!