发布签署gradle.properties为Androidgradle、properties、Android

2023-09-04 08:30:02 作者:潇潇暮雨

所以,我试图把所有的我的Ant构建脚本摇篮,我已经能够找到足够的资源和文档的这一切,除了如何配置签署了gradle.properties文件。

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 the gradle.properties file.

ant.properties做它像这样:

ant.properties does it like so:

key.alias=alias
key.store.password=password
key.store=keystore.file
key.alias.password=password

但我怎么做同样的摇篮?

But how do I do the same in gradle?

推荐答案

在你的 gradle.properties 的文件存储相同的值在 ant.properties 的文件,我想你所要做的更简单的名称,如 keyAlias​​ 的实例。只是删除的点是肯定的。

In your gradle.properties file store the same values as in the ant.properties file, I think you'll have to do simpler names, like keyAlias for instance. Just remove the dots to be sure.

然后在您的 build.gradle 的文件做这样的事情:

then in your build.gradle file do something like this:

android {
    signingConfigs {
        release
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}

if (project.hasProperty('keyAlias')) {
    android.signingConfigs.release.keyAlias = keyAlias
}
// do the same for the three other properties
// ...

这样做可以让你的灵活性,以建立一个计算机上具有的 gradle.properties 的文件或没有。如果存在的keyalias属性是只读因此code有没有失败,如果它不存在。

Doing it this way gives you flexibility to build on a computer that has the gradle.properties file or not. The "keyalias" property is only read if it exists so the code with not fail if it's not there.

如果所有属性都在那里, signingConfigs.release 将全面配置,将用于签署生成过程中的APK。如果它不存在,将APK将建成,但尚未签署。

If all the properties are there, signingConfigs.release will be fully configured and will be used to sign the apk during the build. If it's not there, the APK will be built but not signed.