Android Studio 3.x 自动生成多渠道包
1)AndroidManifest清单文件中添加
完整如下:
2)module 的build.gradle中添加渠道及打包方法
apply plugin: ‘com.android.application‘
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.demo.activityfragmentlifescyle"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
flavorDimensions "versionCode"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile(‘proguard-android-optimize.txt‘), ‘proguard-rules.pro‘
}
applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFile = output.outputFile
def fileName
if (outputFile != null && outputFile.name.endsWith(‘.apk‘)) {
if (variant.buildType.name.equals(‘release‘)) {//如果是release包
fileName = "cbx_release_v${defaultConfig.versionName}.apk"
} else if (variant.buildType.name.equals(‘debug‘)) {//如果是debug包
fileName = "cbx_debug_v${defaultConfig.versionName}.apk"
}
outputFileName = fileName
}
}
}
}
productFlavors{
baidu{}
_91{}
xiaomi{}
huawei{}
}
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [MAT_CHANNEL_VALUE: name]
}
}
def releaseTime() {
return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}
dependencies {
implementation fileTree(dir: ‘libs‘, include: [‘*.jar‘])
implementation ‘androidx.appcompat:appcompat:1.1.0‘
implementation ‘androidx.constraintlayout:constraintlayout:1.1.3‘
implementation ‘androidx.legacy:legacy-support-v4:1.0.0‘
testImplementation ‘junit:junit:4.12‘
androidTestImplementation ‘androidx.test.ext:junit:1.1.1‘
androidTestImplementation ‘androidx.test.espresso:espresso-core:3.2.0‘
}
原文:https://www.cnblogs.com/zhou2016/p/12922258.html