注册APK没有把密钥存储信息的build.gradle [英] Sign APK without putting keystore info in build.gradle

查看:128
本文介绍了注册APK没有把密钥存储信息的build.gradle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图安装签名过程,使密钥库密码和密钥密码的不是存储在项目中的 build.gradle 文件。

I am trying to setup signing process so that keystore password and key password are not stored in the project's build.gradle file.

目前我有以下的 build.gradle

android {
    ...
    signingConfigs {
        release {
            storeFile file("my.keystore")
            storePassword "store_password"
            keyAlias "my_key_alias"
            keyPassword "key_password"
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release            
        }
    }
}

这工作完全正常,但我的不得将值的 storePassword keyPassword 在我的仓库。我想preFER不要把 storeFile keyAlias​​ 有两种。

It works perfectly fine but I must not put the values for the storePassword, and keyPassword in my repository. I would prefer to not put storeFile and keyAlias there either.

有没有办法改变 build.gradle ,这样它会从一些外部源(如文件驻留在我的电脑只)获取密码?

Is there a way to alter the build.gradle so that it will obtain passwords from some external source (like a file that resides on my computer only)?

当然,改变的 build.gradle 应该是任何其它计算机上可用(即使计算机无法访问密码)。

And of course, the altered build.gradle should be usable on any other computer (even if the computer doesn't have access to passwords).

我使用的是Android Studio和在Mac OS X Maverics如果它确实很重要。

I am using Android Studio and in Mac OS X Maverics if it does matter.

推荐答案

关于Groovy的好处是,你可以自由组合的Java code,这是pretty的易于使用的一键/值读取文件 java.util.Properties 。也许有使用习惯的Groovy更简单的方法,但Java的仍然是pretty的简单。

The nice thing about Groovy is that you can freely mix Java code, and it's pretty easy to read in a key/value file using java.util.Properties. Perhaps there's an even easier way using idiomatic Groovy, but Java is still pretty simple.

创建一个 keystore.properties 文件(在这个例子中,在项目旁边的 settings.gradle ,但你可以把它放在你喜欢的地方:

Create a keystore.properties file (in this example, in the root directory of your project next to settings.gradle, though you can put it wherever you like:

storePassword="..."
keyPassword="..."
keyAlias="..."
storeFile="..."

添加到您的 build.gradle

allprojects {
    afterEvaluate { project ->
        def propsFile = rootProject.file('keystore.properties')
        def configName = 'release'

        if (propsFile.exists() && android.signingConfigs.hasProperty(configName)) {
            def props = new Properties()
            props.load(new FileInputStream(propsFile))
            android.signingConfigs[configName].storeFile = file(props['storeFile'])
            android.signingConfigs[configName].storePassword = props['storePassword']
            android.signingConfigs[configName].keyAlias = props['keyAlias']
            android.signingConfigs[configName].keyPassword = props['keyPassword']
        }
    }
}

这篇关于注册APK没有把密钥存储信息的build.gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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