一、首先我们在项目根目录建立一个project.properties自定义的签名相关信息:
key.file=../filename.keystore
keyAlias=filealias
keyPassword=123456
storePassword=123456
二、然后在module的gradle中定义如下内容:
signingConfigs {
debug {
//加载资源
Properties properties = new Properties()
InputStream inputStream = project.rootProject.file('project.properties').newDataInputStream() ;
properties.load( inputStream )
//读取文件
def sdkDir = properties.getProperty('key.file')
//读取字段
def key_keyAlias = properties.getProperty( 'keyAlias' )
def key_keyPassword = properties.getProperty( 'keyPassword' ) ;
def key_storePassword = properties.getProperty( 'storePassword' ) ;
storeFile file(sdkDir)
storePassword key_storePassword
keyAlias key_keyAlias
keyPassword key_keyPassword
}
/* release {
storeFile file( sdkDir )
storePassword key_storePassword
keyAlias key_keyAlias
keyPassword key_keyPassword
}*/
}
当然这样做的最终目的是为了防止签名信息暴露,最后不要把签名文件放到项目下,而是类似C:\work\Key.jks这样