Android 中的打包配置在build.gradle文件中,下面对该文件的内容做一下记录。
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
}
}
这里生命了仓库的位置,依赖gradle的版本。
android{}
android {
compileSdkVersion 22
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.insthub.*****"
minSdkVersion 15
targetSdkVersion 22
versionCode 29
versionName "2.0.7"
}
signingConfigs {
debug {
storeFile file('*******.keystore')
storePassword '111111'
keyAlias '*****'
keyPassword '111111'
}
myConfig {
storeFile file('farmlink.keystore')
storePassword '111111'
keyAlias 'farmlink'
keyPassword '111111'
}
}
lintOptions {
warningsAsErrors false
checkReleaseBuilds false
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
zipAlignEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.myConfig
}
}
sourceSets {
main {
res.srcDirs = ['src/main/res']
}
}
这里面的内容比较多,主要有配置android 支持版本、版本号、签名配置、资源配置等内容。
关于签名配置为了不再该文件显示太多内容,可以使用配置文件的形式。
File propFile = File('signing.properties');
if(propFile.exists()){
def Properties props = new Properties();
props.load(new FileInputStream(propFile));
if(props.containsKey('KEY_ALIAS') && props.containsKey('STORY_PASSWORD')&&props.containsKey('KEY_ALIAS') && props.containsKey('KEY_PASSWORD')){
android.signingConfig.release.storeFile = file(props['STORE_FILE'])
android.signingConfig.release.storeFile = file(props['STORE_PASSWORD'])
android.signingConfig.release.storeFile = file(props['KEY_ALIAS'])
android.signingConfig.release.storeFile = file(props['KEY_PASSWORD'])
} else {
android.buildTypes.release.signingConfig = null
}
} else {
android.buildTypes.release.signingConfig = null
}
signing.properties文件内容
STORE_FILE=*****.keystore
STORE_PASSWORD= *****
KEY_ALIAS=****
KEY_PASSWORD=****
在打包时可以给包命名:
applicationVariantsall {variant ->
variant.outputs.each{ output ->
def outputFile = output.outputFile
if(outputFile != null && outputFile.name.endsWith('.apk')){
File outputDirectory = new File(outputFile.parent);
def fileName;
if(variant.buildType.name == "release"){
fileName = "****_v${defaultConfig.versionName}_$(releaseTime())}_${variant.productFlavors[0].name}.apk"
} else {
fileName = "farmlink_v${defaultConfig.versionName}_${releaseTime()}_debug.apk"
}
output.outputFile = new File(outputDirectory, fileName)
}
}
}
def releaseTime(){
return new Date().format("yyyy-MM-dd_HH-mm",TimeZone.getTimeZone("GMT+8"))
}
下面就是渠道发布了
productFlavors{
playStore{
manifestPlaceholders = [UMENG_CHANNEL_VALUE:"playStore"]
}
}
还可以这样写
productFlavors{
wandoujia{}
_360{}
}