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