今天看Google Android developer文檔 突然看到關(guān)于簽署應(yīng)用的安全問題。仔細(xì)看了下承桥,好像自己的項(xiàng)目,并沒有這樣實(shí)現(xiàn)(這也是一道面試題)
1.應(yīng)用場景
項(xiàng)目中如果把簽名文件的參數(shù)上傳到git乍迄,別人可以通過別的渠道獲取蔬芥,從而導(dǎo)致對項(xiàng)目造成的不必要的損失。
2.解決方案
google給出的方案是可以把相應(yīng)的屬性配置在本地冒签,
1.在項(xiàng)目的根目錄創(chuàng)建keystore.properties文件在抛,把相應(yīng)的屬性內(nèi)容放進(jìn)去
storePassword=myStorePassword //不需要帶‘’號
keyPassword=mykeyPassword
keyAlias=myKeyAlias
storeFile=myStoreFileLocation
2.在模塊的build.gradle文件中,android{}塊前面添加加載keystore.properties文件的代碼
// Create a variable called keystorePropertiesFile, and initialize it to your
// keystore.properties file, in the rootProject folder.
def keystorePropertiesFile = rootProject.file("keystore.properties")
// Initialize a new Properties() object called keystoreProperties.
def keystoreProperties = new Properties()
// Load your keystore.properties file into the keystoreProperties object.
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android {
...
}
3然后修改模塊中的代碼
signingConfigs {
// config {
// keyAlias 'android'
// keyPassword 'android'
// storeFile file('android.keystore')
// storePassword 'android'
// }
config{
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
這樣就配置好了萧恕,把配置文件保存好刚梭,在.gitignore文件中忽略,這樣就不會上傳敏感信息到git上去了票唆,建議大家平時可以多看看developer文檔朴读,里面有很多知識,我們都可以從這里學(xué)習(xí)