美文网首页
android studio 从 local.properti

android studio 从 local.properti

作者: Asbefore如初_3142 | 来源:发表于2019-04-25 17:17 被阅读0次

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 )

相关文章

网友评论

      本文标题:android studio 从 local.properti

      本文链接:https://www.haomeiwen.com/subject/bqnzgqtx.html