Guo Xiaoxing
Weibo: Guo Xiaoxing's Sina Weibo
Email:[email protected]
Blog: http://blog.csdn.net/allenwells
Github:https://github.com/allenwell
Because of the large number of domestic Android market channels, in order to count the download of each channel and data statistics, we need to be individually packaged for each channel, and Gradle can help us complete automatic multi-channel packaging.
A multi-channel packaging process (1) Configuring placeholder in Androidmanifest.xml
<meta-data android:name="UMENG_CHANNEL" android:value="${UMENG_CHANNEL_VALUE}" />
(2) Configuring Producflavors in Build.gradle
or batch Modification
android { productFlavors { {} _360 {} baidu {} wandoujia {} } productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] }}
Appendix
Apply plugin:' Com.android.application 'Def releasetime () {return NewDate ().format("Yyyy-mm-dd", Timezone.gettimezone ("UTC"))}android {compilesdkversion +Buildtoolsversion' 21.1.2 'Defaultconfig {ApplicationID"com.boohee.*"Minsdkversion -Targetsdkversion +Versioncode1Versionname"1.0" //Dex exceeds the limit of 65535Multidexenabledtrue //default is Umeng channelManifestplaceholders = [Umeng_channel_value:"Umeng"]} lintoptions {Abortonerrorfalse} signingconfigs {debug {//No debug config} release {StoreFilefile(".. /yourapp.keystore ") Storepassword"Your password"Keyalias"Your alias"Keypassword"Your password"}} buildtypes {debug {//Display logBuildconfigfield"Boolean","Log_debug","true"Versionnamesuffix"-debug"MinifyenabledfalseZipalignenabledfalseShrinkresourcesfalseSigningconfig Signingconfigs.debug} release {//Do not display logBuildconfigfield"Boolean","Log_debug","false"MinifyenabledtrueZipalignenabledtrue //Remove useless resource filesShrinkresourcestrueProguardfiles Getdefaultproguardfile (' Proguard-android.txt '),' Proguard-rules.pro 'Signingconfig signingconfigs.release Applicationvariants.all {variant-variant.outputs. each{OUTPUT, def outputFile = Output.outputfileif(OutputFile! =NULL&& OutputFile.name.endsWith ('. apk ')) {//output APK name is called boohee_v1.0_2015-01-15_wandoujia.apkdef fileName ="Boohee_v${defaultconfig.versionname}_${releasetime ()}_${variant.productflavors[0].name}.apk"Output.outputfile =NewFile (Outputfile.parent, FileName)}}}}//Friend Alliance multi-channel packagingproductflavors {Wandoujia {}_360{} Baidu {} tencent {} taobao {} ...} Productflavors.all {flavor-flavor.manifestplaceholders = [Umeng_channel_value:name]}}dependencies { Compile Filetree (dir:' Libs ',include: [' *.jar ']) Compile' com.android.support:support-v4:21.0.3 'Compile' com.jakewharton:butterknife:6.0.0 '...}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Android Studio Discovery Road Series": Gradle Project Building System (iv): Android Studio project multi-channel packaging: