android studio 從 local.properties 讀取參數(shù)
以讀取 簽名秘鑰為例子
首先在 local.properties
中定義字段纺阔,假設(shè)現(xiàn)在有下面的字段
local.properties:
STORE_FILE_NAME=Apk_jks.jks
STORE_ALIAS=xxx
KEYSTORE_PASSWORD=xxx
KEY_PASSWORD=xxx
在 app
的 android {}
字段中 則用下面這樣的方法讀取
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 )