Gradleマルチチャネルパッケージ(必要に応じて名前を変更)
3900 ワード
レコードコード
build.gradleファイルは次のとおりです.
これでapkの名前を再び修正する必要はありません.一労永逸、ははは!
build.gradleファイルは次のとおりです.
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
applicationId "com.xxxx.abcd"
versionCode 1
versionName "1.0.1"
//All flavors must now belong to a named flavor dimension
flavorDimensions "versionCode"// , flavor dimension ,
multiDexEnabled true // dex 65535
//Nuance so , , so 。
// //armeabi,armeabi-v7a,x86,mips,arm64-v8a,mips64,x86_64
ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8a" }
//vectorDrawables.useSupportLibrary = true // .xml flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
//--[E] --
buildTypes {
release {
//...
}
debug {
//...
}
}
// apk build
/*
//android studio 2
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
// apk
//String apkName = "${variant.productFlavors[0].name}_${defaultConfig.versionName}_${compilePackTime()}_.apk"
output.outputFile = new File(outputFile.parent, appName(outputFile.name, defaultConfig.versionName))
}
}
}*/
//android studio 3
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
outputFileName = appName(outputFile.name, defaultConfig.versionName)
}else {// apk
outputFileName = "${variant.productFlavors[0].name}_${defaultConfig.versionName}_${compilePackTime()}_.apk"
}
}
}
}
// :app-umeng-debug.apk app-umeng-release.apk
// apk umeng_V419_20171110_1110.apk
def appName(String outputFileName, String versionName) {
String appName = outputFileName.replace("app-", "").replace(".apk", "");
String debugName = appName.replace("-debug", "");
if (appName == debugName) {// release apk
appName = appName.replace("-release", "") + visionName(versionName) + compilePackTime() + ".apk";
} else { // debug apk
appName = debugName + visionName(versionName) + compilePackTimeD() + "_debug.apk";
}
return appName;
}
//
def visionName(String visionName) {
return "_V" + visionName.replace(".", "") + "_";
}
//
def compilePackTime() {
return (new Date().format("yyyyMMdd HHmm", TimeZone.getTimeZone("GMT+8"))).replace(" ", "_")
// //
}
def compilePackTimeD() { //debug name ( ) :The APK file does not exist on disk
return (new Date().format("yyyyMMdd", TimeZone.getTimeZone("GMT+8")))
}
//...
dependencies {
//...
}
これでapkの名前を再び修正する必要はありません.一労永逸、ははは!