对签署 android APK 感到困惑?

Confused with signing android APK?

我是否已按照 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 中的步骤构建我的签名 APK?请简单说明一下 this.and 是否做错了什么?

谢谢。

您可以将 .jks 文件放在任何地方。
这意味着您可以将文件放在您的项目中,也可以将文件放在外部文件夹中(看看下面的路径)。 这取决于您的政策。

只需使用 gradle 配置 apk 的签名。

android {

    signingConfigs {
        release
    }

    buildTypes {
            release {
                signingConfig signingConfigs.release
            }
    }
}

简单方法:只需在 build.gradle 文件中定义凭据。

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'

     }
  }

使用 .properties 文件 将凭据存储在脚本之外(例如,如果您不想将凭据推送到 git 存储库中)。

示例:signing.properties

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

然后在您的 build.gradle 文件中获取这些值:

signingConfigs {
        release
 }

然后定义:

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
}