release模式配置keystore
我們點擊Project Structure
點擊我們項目的model慧脱,選擇Signing選項
輸入已創(chuàng)建的keystore信息
使得簽名生效需配置Build Types
點擊ok后,此時發(fā)現(xiàn)我們model下的build.gradle文件有如下的變化:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.zxn.gaode"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
keyAlias 'mgddkeystore'
keyPassword 'mgdd888'
storeFile file('D:/MyGitHubDemos/MyGaoDe-asp/MyGaoDeDemo/mgdd.jks')
storePassword 'mgdd888'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
簽名文件的密碼信息配置在local.properties
上述的配置簡單實用,但是不安全奠宜,假如你的項目是開源的,你把簽名文件的配置密碼之類的信息用明文寫在build.gradle里面,不夠安全
可以將簽名文件的配置密碼之類的信息寫在local.properties下压真,因為在Git版本控制的項目中娩嚼,我們可以看到我們項目project模式根目錄下有一個.gitignore的文件,里面的配置大概如下所示
*.iml
.gradle
/local.properties
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
.DS_Store
/build
/captures
.externalNativeBuild
其中我們可以看到/local.properties滴肿,意思就是說local.properties默認是不添加到版本控制里面的岳悟,因為local.properties存儲的是我們環(huán)境資源的一些相關(guān)信息,如sdk的路徑泼差。故我們可以在local.properties下配置簽名信息而不用擔心密鑰外泄贵少。對于開源項目來說,是非常好的堆缘。
在local.properties下直接添加相關(guān)信息
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Sat Apr 21 12:17:45 CST 2018
ndk.dir=C\:\\MyPrograms\\Android\\sdkAS\\ndk-bundle
sdk.dir=C\:\\MyPrograms\\Android\\sdkAS
#keystore.path= D\:/MyGitHubDemos/MyGaoDe-asp/MyGaoDeDemo/mgdd.jks
KEY_ALIAS = mgddkeystore
STORE_PASSWORD = mgdd888
KEY_PASSWORD = mgdd888
為了不用明文顯示滔灶,app的build.gradle里配置
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.zxn.gaode"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
Properties properties = new Properties();
properties
.load(project.rootProject.file("local.properties")
.newDataInputStream())
storePassword properties.get("STORE_PASSWORD")
keyAlias properties.get("KEY_ALIAS")
keyPassword properties.get("KEY_PASSWORD")
storeFile file('D:/MyGitHubDemos/MyGaoDe-asp/MyGaoDeDemo/mgdd.jks')
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Signing中keystore值不設(shè)置
到此,配置完成
我們在工程進行編譯打包
打包成功