Gradle Android Studio 使用属性文件签名 [英] Gradle Android Studio signing with a properties file

查看:26
本文介绍了Gradle Android Studio 使用属性文件签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 gradle 构建文件为我的应用程序签名.当我使用普通的签名配置时,它可以工作(signingConfigs.release)!但是如果我试图从属性文件中读取属性,它将无法工作.(signingConfigs.config)

I´m trying to sign my app with the gradle build file. When I use the plain signingConfigs it works (signingConfigs.release)! But If I´m trying to read the properties from the properties-file it won´t work. (signingConfigs.config)

Properties props = new Properties();
props.load(new FileInputStream(file(rootProject.file("signing.properties"))))

android {
        signingConfigs {
            config {
                storeFile file(props["storeFile"])
                storePassword props["storePassword"]
                keyAlias props["keyAlias"]
                keyPassword props["KeyPassword"]
            }
            release {
                storeFile file("..\\xyz.jks")
                storePassword "****"
                keyAlias "****"
                keyPassword "****"
            }
        } 
    .
    .
    .
        buildTypes {
            release {
                runProguard false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
                signingConfig signingConfigs.release
            }
            debug {
                applicationIdSuffix '.debug'
                versionNameSuffix '-SNAPSHOT'
            }
        }

属性文件:

storeFile=xyz.jks
storePassword=xyz
keyAlias=xyz
keyPassword=xyz

当我运行该项目时,android studios 会显示一个对话框,内容为:

When I run the project, android studios show a dialog which says:

xyz.apk 未签名.请配置签名信息使用项目结构"对话框选择的风格.

xyz.apk is not signed. Please configure the signing information for the selected flavor using the Project Structure dialog.

属性文件被正确读取,因为我可以从文件中记录一些属性并抛出控制台.

The property file is read correctly because I can log some properties from the file throw the console.

我的一些系统详细信息:

Some of my system details:

Android Studio 0.8.6视窗 8.1 x64gradle 1.12

Android Studio 0.8.6 Windows 8.1 x64 gradle 1.12

希望任何人都可以帮助我.如果您想了解更多详情,请咨询我.

Hope anyone can help me. If you want to know more details, then ask me.

推荐答案

这就是我所做的并且对我有用:

This is what I do and it works for me:

signingConfigs {
    release {
        def Properties localProps = new Properties()
        localProps.load(new FileInputStream(file('../local.properties')))
        def Properties keyProps = new Properties()
        assert localProps['keystore.props.file'];
        keyProps.load(new FileInputStream(file(localProps['keystore.props.file'])))
        storeFile file(keyProps["store"])
        keyAlias keyProps["alias"]
        storePassword keyProps["storePass"]
        keyPassword keyProps["pass"]
    }
}

我的 local.properties 文件包含keystore.properties"文件的路径.其中包含我关于密钥库的信息:

My local.properties file contains a path to a "keystore.properties" file. That contains my info about the keystore:

store=***
alias=***
pass=***
storePass=***

也许加载两个属性文件是多余的,但它对我有用.

Perhaps the loading of two Propreties file is redundant, but it does work for me.

这篇关于Gradle Android Studio 使用属性文件签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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