Android Studio3.0 flavorDimensions多维度理解(版本差异化打包) : flavorDimensions dimension
Posted Mars-xq
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android Studio3.0 flavorDimensions多维度理解(版本差异化打包) : flavorDimensions dimension相关的知识,希望对你有一定的参考价值。
参考:
flavorDimensions和productFlavors——安卓gradle
示例:
plugins
id 'com.android.application'
android
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig
applicationId "com.xq.myapplication"
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
// 获取Git用户名 , 可以通过 BuildConfig 进行获取 : BuildConfig.USER_ID
buildConfigField("String", "USER_ID", "\\"$getGitUserName()\\"")
debug
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
// 获取Git用户名 , 可以通过 BuildConfig 进行获取 : BuildConfig.USER_ID
buildConfigField("String", "USER_ID", "\\"$getGitUserName()\\"")
compileOptions
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
//可支持编译 : 2(debug/release)*3(baidu/gaode/tencent)*2(uat/pro)=12种结果:
//baiduProDebug
//baiduProRelease
//baiduUatDebug
//baiduUatRelease
//
//gaodeProDebug
//gaodeProRelease
//gaodeUatDebug
//gaodeUatRelease
//
//tencentProDebug
//tencentProRelease
//tencentUatDebug
//tencentUatRelease
flavorDimensions "app", "env"
productFlavors
//<application
// android:allowBackup="true"
// android:icon="$logo"
// android:label="$appName"
// android:roundIcon="$logo"
// android:supportsRtl="true"
// android:theme="@style/AppTheme">
//......
baidu
dimension 'app'
//
applicationId 'com.xq.baidu'
manifestPlaceholders = [
logo : "@drawable/logo_baidu",
appName: "baidu",
]
signingConfig signingConfigs.baidu
gaode
dimension 'app'
//
applicationId 'com.xq.gaode'
manifestPlaceholders = [
logo : "@drawable/logo_gaode",
appName: "gaode",
]
signingConfig signingConfigs.baidu
tencent
dimension 'app'
//
applicationId 'com.xq.tencent'
manifestPlaceholders = [
logo : "@drawable/logo_tencent",
appName: "tencent",
]
signingConfig signingConfigs.tencent
//=================================================
//引用:
//<?xml version="1.0" encoding="utf-8"?>
//<manifest xmlns:android="http://schemas.android.com/apk/res/android"
// package="com.xq.map"
// android:sharedUserId="$sharedUserId">
uat
dimension 'env'
//
manifestPlaceholders["sharedUserId"] = ""
pro
dimension 'env'
//
manifestPlaceholders["sharedUserId"] = "android.uid.system"
//重命名APP
applicationVariants.all variant ->
variant.outputs.all output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk'))
def fileName = "BydCrossCountry_v$defaultConfig.versionName_$getUserName()" +
"_$getShortCommitID()_$releaseTime()_$variant.buildType.name.apk"
outputFileName = fileName
static def getUserName()
return 'git config user.name'.execute().text.trim()
static def getShortCommitID()
return 'git rev-parse --short HEAD'.execute().text.trim()
static def releaseTime()
return new Date().format("yyMMddHHmm", TimeZone.getTimeZone("GMT+08:00"))
dependencies
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
以上是关于Android Studio3.0 flavorDimensions多维度理解(版本差异化打包) : flavorDimensions dimension的主要内容,如果未能解决你的问题,请参考以下文章
Android Studio3.0 配置ButterKnife出错的解决
Android Studio3.0 配置AndroidAnnotation注解框架
Android Studio3.0配置Butterknife8.8.1及大坑
Android Studio3.0 flavorDimensions多维度理解(版本差异化打包) : flavorDimensions dimension
Android Studio3.0 flavorDimensions多维度理解(版本差异化打包) : flavorDimensions dimension