"Android Studio Discovery Road Series": Gradle Project Building System (iv): Android Studio project multi-channel packaging:

Source: Internet
Author: User



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:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.