//build.gradle该配置文件里路径均是相对路径
apply plugin: 'com.android.application'android {def suffix = "suffix"//后缀//新增一个配置须要加入一个新的变量,命名规则operator_xxxxxxdef operator_Z = "Z"Map
}dependencies {
//在混淆文件里须要凝视相关jar包。例如以下
//#-libraryjars libs/dom4j-1.6.1.jar
//#-libraryjars libs/jackson-core-asl-1.8.0.jar
//#-libraryjars libs/jackson-mapper-asl-1.8.0.jar
//#-libraryjars libs/junit4.4.jar
//#-libraryjars libs/spring-android-rest-template-1.0.0.M2.jar
//#-libraryjars libs/Log.jar
//#-libraryjars libs/gson-2.2.4.jarcompile '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 {//复制release版本号apk到单独目录from('build/outputs/apk')into(dir_debug)include('*_debug.apk')exclude("*-unaligned.apk");exclude("*-unsigned.apk");}copy {//复制debug版本号apk到单独目录from('build/outputs/apk')into(dir_release)include('*.apk')exclude('*_debug.apk')exclude("*-unaligned.apk");exclude("*-unsigned.apk");}
}def setup(Map
// def version = android.defaultConfig.versionName;def version = variant.productFlavors[0].versionName;def file = output.outputFiledef buildTypeOfApp = variant.buildType.namedef operator = operatorMap.get("${variant.productFlavors[0].name}")//这里传入參数时须要使用“ "${variant.productFlavors[0].name}" ”
// def outputName = name + operator + variant.productFlavors[0].name + "_" + suffix + "_" + versiondef 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);
}