多渠道打包、32位、64位等分包打包配置
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "xxx.xxx.com"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 100
versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//**添加多 dex分包支持
multiDexEnabled true
javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
// ndk {
// //选择要添加的对应cpu类型的.so库。
// abiFilters 'arm64-v8a', 'armeabi-v7a', 'armeabi'
// }
manifestPlaceholders = [
JPUSH_PKGNAME: applicationId,
JPUSH_APPKEY : "000000", //JPush上注册的包名对应的appkey.
JPUSH_CHANNEL: "developer-default" //暂时填写默认值即可.
]
}
signingConfigs {
release {
storeFile file('bgkeystore.keystore')
storePassword 'bg123'
keyAlias 'gbgov'
keyPassword 'bg123'
}
}
flavorDimensions "default"
productFlavors {
huawei {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "huawei"]
ndk {
//选择要添加的对应cpu类型的.so库。
abiFilters 'arm64-v8a', 'armeabi-v7a', 'armeabi'
}
}
app32bity {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "yingyongbao32"]
ndk {
//选择要添加的对应cpu类型的.so库。
abiFilters 'armeabi-v7a', 'armeabi'
}
}
app64bity {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "yingyongbao64"]
ndk {
//选择要添加的对应cpu类型的.so库。
abiFilters 'arm64-v8a'
}
}
// yingyongbao {
// manifestPlaceholders = [UMENG_CHANNEL_VALUE: "yingyongbao"]
// }
// baidu {
// manifestPlaceholders = [UMENG_CHANNEL_VALUE: "baidu"]
// }
// c360 {
// manifestPlaceholders = [UMENG_CHANNEL_VALUE: "c360"]
// }
// oppo {
// manifestPlaceholders = [UMENG_CHANNEL_VALUE: "oppo"]
// }
// vivo {
// manifestPlaceholders = [UMENG_CHANNEL_VALUE: "vivo"]
// }
// meizu {
// manifestPlaceholders = [UMENG_CHANNEL_VALUE: "meizu"]
// }
// xiaomi {
// manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"]
// }
// anzhi {
// manifestPlaceholders = [UMENG_CHANNEL_VALUE: "anzhi"]
// }
// tiantanCMS {
// manifestPlaceholders = [UMENG_CHANNEL_VALUE: "tiantanCMS"]
// }
}
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
//自定义APK名称,多渠道打包
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
variant.productFlavors.each { flavor ->
def project = "bggov"
def separator = "_"
def buildType = variant.variantData.variantConfiguration.buildType.name
def versionName = variant.versionName
def versionCode = variant.versionCode
def date = new Date()
def formattedDate = date.format('yyyyMMdd')
def apkName = project + separator + "v" + versionName + separator + versionCode + separator + buildType + separator + flavor.name + ".apk"
if (buildType == "release") {
apkName = project + separator + "v" + versionName + separator + versionCode + separator + buildType + separator + flavor.name + separator + formattedDate + ".apk"
}
output.outputFileName = apkName
}
}
}
//自定义输出包名的设置
// applicationVariants.all { variant ->
// variant.outputs.all {
//
// // 输出apk名称为app-release-gizdisgov_v1.0.apk
// def fileName = "app-release-gizdisgov_V${defaultConfig.versionName}.apk"
// outputFileName = fileName
// }
// }
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
debuggable false //启用debug的buildType配置
}
//输出类型
applicationVariants.all {
//判断是release还是debug版本
def buildType = it.buildType.name
//获取当前时间的"YYYY-MM-dd"格式。
def createTime = new Date().format("YYYY-MM-dd_HH-mm", TimeZone.getTimeZone("GMT+08:00"))
//如果是正式包,将其输入到指定文件夹
if (buildType == "release") {
it.getPackageApplication().outputDirectory = new File('E:\\tarApk\\bggovApks'+ "/${applicationId}/${createTime}")
}
}
}
//打包不检查
lintOptions {
checkReleaseBuilds false
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'org.jetbrains:annotations:15.0'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
}
<application下配置
<!-- 多渠道打包-->
<meta-data android:name="UMENG_CHANNEL" android:value="${UMENG_CHANNEL_VALUE}" />