对签署 android APK 感到困惑? [英] Confused with signing android APK?

查看:34
本文介绍了对签署 android APK 感到困惑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照 官方 所说的数字签名步骤我的 android application.for 在发布模式下签名,他们说使用 .keystore 文件和它的凭据,如 this.我正在使用 android studio,以便获得 .jks 文件.那么我需要在哪里保留 .jks 文件根据 docs 用于构建我签名的 APK ?请对此做一个简单的阐述.如果我做错了什么?

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 ?

谢谢.

推荐答案

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

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.

只需使用 gradle 配置您的 apk 的签名.

Just use gradle to configure the signing of your apk.

android {

    signingConfigs {
        release
    }

    buildTypes {
            release {
                signingConfig signingConfigs.release
            }
    }
}

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

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'

     }
  }

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

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).

示例:signing.properties

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

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

Then get these values in your build.gradle file:

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
}

这篇关于对签署 android APK 感到困惑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆