apply plugin: 'com.android.application'
android {
def suffix = "suffix"
def operator_Z = "Z"
Map<String, String> operatorMap = new HashMap<String, String>();
Map<String, Boolean> versionMap = new HashMap<String, Boolean>();
Map<String, Integer> versionCodeMap = new HashMap<String, Integer>();
Map<String, String> versionNameMap = new HashMap<String, String>();
setVersionCN(versionMap, versionCodeMap, versionNameMap, "projectName001", true, 10, "1.0.0.10test")
setVersionCN(versionMap, versionCodeMap, versionNameMap, "projectName002", true, 10, "1.0.0.10test")
compileSdkVersion 21
buildToolsVersion "23.0.0 rc2"
enforceUniquePackageName = false
lintOptions {
abortOnError false
}
dexOptions {
preDexLibraries = false
}
signingConfigs {
commonConfig {
storeFile file("wasu.keystore")
storePassword "wasu1234"
keyAlias "android.keystore"
keyPassword "wasu1234"
}
}
defaultConfig {
applicationId "cn.com.wasu.backplay"
minSdkVersion 11
targetSdkVersion 15
versionCode 11
versionName "1.0.0.11"
}
buildTypes {
release {
zipAlignEnabled true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-project.txt'
}
}
productFlavors {
def flavorSign = signingConfigs.commonConfig
projectName001 {
sourceSets."$name".java.srcDirs += "build-types/projectName001"
signingConfig flavorSign
operatorMap.put("$name", operator_Z)
if (versionMap.get(name)) {
versionCode versionCodeMap.get(name)
versionName versionNameMap.get(name)
} else {
versionCode defaultConfig.versionCode
versionName defaultConfig.versionName
}
}
projectName002 {
sourceSets."$name".java.srcDirs += "build-types/projectName002"
signingConfig flavorSign
operatorMap.put("$name", operator_Z)
if (versionMap.get(name)) {
versionCode versionCodeMap.get(name)
versionName versionNameMap.get(name)
} else {
versionCode defaultConfig.versionCode
versionName defaultConfig.versionName
}
}
}
sourceSets {
main {
assets.srcDirs = ['src/main/assets']
res.srcDirs = ['src/main/res']
aidl.srcDirs = ['src/main/java']
resources.srcDirs = ['src/main/java']
renderscript.srcDirs = ['src/main/java']
jniLibs.srcDirs = ['libs']
manifest.srcFile 'src/main/AndroidManifest.xml'
java {
srcDirs = ['src/main/java']
exclude 'cn/com/a/b/c/Common.java'
}
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/ASL2.0'
}
println "共" + operatorMap.size() + "个项目须要编译"
setup(operatorMap, suffix)
clean {
delete += "output"
}
}
dependencies {
compile 'com.android.support:support-v4:21.0.3'
compile 'com.google.code.gson:gson:2.2.4'
compile files('libs/Log.jar')
compile files('libs/dom4j-1.6.1.jar')
compile files('libs/jackson-core-asl-1.8.0.jar')
compile files('libs/jackson-mapper-asl-1.8.0.jar')
compile files('libs/junit4.4.jar')
compile files('libs/spring-android-rest-template-1.0.0.M2.jar')
}
build.doLast {
def today = new Date().format('yyyyMMdd');
def dir_debug = 'output/' + today + '/debug'
def dir_release = 'output/' + today + '/release'
copy {
from('build/outputs/apk')
into(dir_debug)
include('*_debug.apk')
exclude("*-unaligned.apk");
exclude("*-unsigned.apk");
}
copy {
from('build/outputs/apk')
into(dir_release)
include('*.apk')
exclude('*_debug.apk')
exclude("*-unaligned.apk");
exclude("*-unsigned.apk");
}
}
def setup(Map<String, String> operatorMap, suffix) {
def name = "xxxx_";
def today = new Date().format('yyyyMMddHHmm');
def today1 = new Date().format('yyyyMMdd');
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def version = variant.productFlavors[0].versionName;
def file = output.outputFile
def buildTypeOfApp = variant.buildType.name
def operator = operatorMap.get("${variant.productFlavors[0].name}")
def test = "%s%s%s_%s_%s"
def outputName = String.format(test, name, operator, variant.productFlavors[0].name, suffix, version)
if (!variant.buildType.name.equalsIgnoreCase("debug")) {
output.outputFile = new File(file.parent, outputName + "_" + today + ".apk")
} else {
output.outputFile = new File(file.parent, outputName + "_" + today1 + "_debug.apk");
}
println output.outputFile;
}
}
}
/**
* 设置是否使用自己定义versionCode和versionName
* @param versionMap 是否自己定义map
* @param versionCodeMap 自己定义versionCode map
* @param versionNameMap 自己定义versionName map
* @param name 项目名
* @param isSingle 是否使用自己定义
* @param code 自己定义versionCode
* @param vname 自己定义versionName
* @return
*/
def setVersionCN(versionMap, versionCodeMap, versionNameMap, String name, boolean isSingle, int code, String vname) {
versionMap.put(name, isSingle);
versionCodeMap.put(name, code);
versionNameMap.put(name, vname);
}