Confused with signing android APK?

 ̄綄美尐妖づ 提交于 2019-12-02 02:04:26

问题


I have followed the steps as per officials says for digitally signing my android application.for signing in release mode they are saying to use .keystore file and it's credentials like this.I am using android studio so that am getting .jks file instead.So where do i need to keep the .jks file according to the docs for building my signed APK ? Please give a simple elaboration on this.and say if am doing anything wrong ?

Thanks.


回答1:


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
}


来源:https://stackoverflow.com/questions/33645835/confused-with-signing-android-apk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!