android studio 从 local.properties 读取参数

android studio 从 local.properties 读取参数

原文

以读取 签名秘钥为例子

首先在 local.properties 中定义字段,假设现在有下面的字段

local.properties:

STORE_FILE_NAME=Apk_jks.jks
STORE_ALIAS=xxx
KEYSTORE_PASSWORD=xxx
KEY_PASSWORD=xxx

appandroid {} 字段中 则用下面这样的方法读取

signingConfigs {
        //加载资源
        Properties properties = new Properties()
        InputStream inputStream = project.rootProject.file('local.properties').newDataInputStream() ;
        properties.load( inputStream )

        signConfig {
            storeFile file(properties.getProperty("STORE_FILE_NAME"))//签名文件路径,
            storePassword properties.getProperty("KEY_PASSWORD") //密码
            keyAlias properties.getProperty("STORE_ALIAS")
            keyPassword properties.getProperty("KEY_PASSWORD") //密码
        }
}

主要使用这种方式加载和读取:

Properties properties = new Properties()
InputStream inputStream = project.rootProject.file('local.properties').newDataInputStream() ;
properties.load( inputStream )

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容