Android Studio multi-channel packaging, Debug formal package, Build.gradle parsing

Source: Internet
Author: User

1, explain the Build.gradle file. 1.1 Root directory Android

1.1.1
Defaultconfig is the root directory of Android, you can configure the package name and other information, if the Androidmainfest.xml is also configured, to Defaultconfig prevail.
1.1.2
Signingconfigs is the root directory of Android and can be configured with signatures such as:


When debugging, if you want to use a formal signature package can be configured in the BuildType.

buildtypes {    Debug {        signingconfig signingconfigs.release    }    release {        false         proguardfiles getdefaultproguardfile (' proguard-android.txt'proguard-rules.pro '     }}

1.1.3
Multi-channel packaging, modifying the Meta-data value of Androidmainfest.
The Androidmainfest configuration is as follows:

${value} is dynamically configured.

Android : Name= ". MyApplication ">    <meta-data        android: Name= "Channelvalue"  android: value= "${value}" ></meta-data>         

The Build.gradle is configured as follows

productflavors {    Huawei {                manifestplaceholders        =[  Value"Huawei"]    }    Xiaomi                 {         manifestplaceholders =[Value"Xiaomi"}    }

Gets the value of Androidmainnifest value in the code

//Get meta fieldsPublic StaticStringgetmetastring(Context con,String name) {ApplicationInfo AI =null;Try{ai = Con.getpackagemanager (). Getapplicationinfo (Con.getpackagename (), Packagemanager.Get_meta_data);        }Catch(Packagemanager.namenotfoundexception e) {E.printstacktrace ();        } Bundle bundle = AI.MetaData;returnBundle.getstring (name);}

Direct use when packaging



Finally paste the Build.gradle file.

Applyplugin:' Com.android.application 'Android {Compilesdkversion +    Buildtoolsversion"21.1.2"    Defaultconfig {ApplicationID"Caisheng.com.search"        Minsdkversion -        Targetsdkversion +        Versioncode1        Versionname"1.0"    } signingconfigs {//Your own KeyStore information        Release {Keyalias' Aolaigo '            Keypassword' 123456 '            StoreFile file (' E:/test.jks ') Storepassword' 123456 '        }} lintoptions {Checkreleasebuildsfalse        //or, if you prefer, you can continue-to-check for errors in release builds,//But continue the build even when errors is found:        Abortonerrorfalse    } buildtypes {debug {signingconfig Signingconfigs.release} release {Mini Fyenabledfalse            Proguardfiles Getdefaultproguardfile (' Proguard-android.txt '),' Proguard-rules.pro '        }} productflavors {huawei {minsdkversion -            Targetsdkversion +            Manifestplaceholders =[Value:"Huawei"]} Xiaomi {Minsdkversion -            Targetsdkversion +            Manifestplaceholders =[Value:"Xiaomi"]}}}dependencies {compile Filetree (dir:' Libs ',include: [' *.jar '])//compile (name: ' Cai ', ext: ' AAR ')//Compile Project (': Cai ')/ * compile ' com.facebook.fresco:fresco:0.6.0 'compile ' com.android.support:appcompat-v7:22.2.0 'compile ' com.github.liuguangqiang.swipeback:library:[email protected] 'compile ' com.sothree.slidinguppanel:library:3.1.1 'compile ' me.dm7.barcodescanner:zbar:1.5 ' * *}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Studio multi-channel packaging, Debug formal package, Build.gradle parsing

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.