Gradle Tutorial [Original] (Eclipse/adt non-plug-in non-Android Studio/as) Pure hand hit the third: Gradle complete combat

Source: Internet
Author: User

The address of the last two articles

Installation configuration

Http://www.cnblogs.com/uncle2000/p/4276833.html

Simple combat

Http://www.cnblogs.com/uncle2000/p/4277476.html

I used ant now to use gradle because Ant is packaged to join a third-party dependency project is very very very troublesome, and online about the comparison of the two are countless, we can go to check, fully explain the advantages of Gradle

And there is also a point is Gradle's Chinese information is more than ant, want to add For-each and Switch-case ant, but let me break the heart, about my ant code I will also in the back of the Android packaging to give the source code.

And about Gradle to pack I learned a day already mastered, and Ant with a loop to install support plug-in I wipe! And I hate tagged languages.

Okay, cut the crap. The content of this article is less than the previous article, if gradle This article of these features, eclipse can not be a simple batch of finished yo

A signature
//signature Configuration I'm going to go with the full code back here.Signingconfigs {myconfig{//The signature file, put it in the engineering root directory yoStoreFile file ("Xxxx.keystore")    //the password for the signature fileStorepassword "xxxxx"//name of the project aliasKeyalias "XXXX"//Signed PasswordKeypassword "XXXX"        }}//things to do when you build it, like signing or confusing .buildtypes{Release {//Note that some of the online is wrong, this is the corresponding new 2.2.1 Gradle method//This means that the execution of the signature is performed by Signingconfigs the configuration in the Myconfig is the domain abovesigningconfig Signingconfigs.myconfig}}

Two confusions

About confusing files (proguard-properties.txt) I won't give it to you.

I just said the confusion was in that execution method.

buildtypes{     Release {    // Perform obfuscation confusion configuration in proguard-properties.txt file         under root directory Proguardfile getdefaultproguardfile (' proguard-properties.txt ')// Specify confusing file        }    } 

The first of the two methods of packing in three batches:

Part of the code for bulk packaging I've mentioned it in my last article.

Defaultconfig {manifestplaceholders= [Activitylabel: "DefaultName"]} productflavors {//configuration of Channel Onechannelname1{//Replace the variable value (value) of the "CHANNEL" variable name (key) in manifest with the xxx1//It is also possible to replace "xxx1" with name=> [channel:name], which means replacing value with channelname1//because of the online mess paste copy all the online those who did not say clearly, here the channel must be again manifest and corresponding specific I write in the following code blockManifestplaceholders = [CHANNEL: "Xxx1"]      }//configuration of Channel twochannelname2{manifestplaceholders= [CHANNEL: "Xxx2" ]      }
.... Channel n ...}

Note that it is possible to join such a domain in manifest, but you will take it, I wrote it in <application>

// here's $ for Android compiler is a char but for gradle is the variable meaning, can replace, with what replace? Of course it's the value in the Productflavors field in my last code block. Avoid this channel correspondence with the channel in the previous code block if you change one of them remember to change another <meta-data android:name= "Umeng_channel" android:value= "${ CHANNEL} "/>

This way, this configuration is suitable for each individual configuration, such as different channels of different version numbers, different configurations, but if you do not need so much fancy, you can use a second method

The second type:
defaultconfig {         = [Activitylabel: "DefaultName"]  } productflavors {    channelname1{}    channelname2{}// Execute the All method, loop to assign the channelname* to the variable in manifest all    {flavor         - = [Channel:name]    }}    
Iv. Dependency Engineering/reliance on third-party engineering/reliance on external engineering

What is dependency engineering?

In fact, as long as the original code to add a few lines of code a few files can be achieved, so do not think so difficult

I would like to give an example that my XXX project relies on Appcompat_v7_6 this project situation

Like two projects two files this is the most superior directory

The directory structure is like this

/appcompat_v7_6/1~n Child Files

/xxx/1~n Child Files

/local.properties

/settings.gradle

Besides

Each of the two projects has a build.gradle

One one says.

1 The content in the Local.properties file is the root of your SDK it's easy.

The contents of the 2settings.gradle file are all associated project names

The structure is include ': X1 ', ': X2 ', ': X3 ',......... Be careful not to use Chinese

":" corresponds to "\" in "\xx\" of the folder system

3 then look at the contents of the Build.gradle in my appcompat_v7_6 standard ha

buildscript{repositories{mavencentral (); } dependencies{//where you might need to change.Classpath ' com.android.tools.build:gradle:1.0.0 '} tasks.withtype (javacompile) {options.encoding= "UTF-8"}}apply Plugin:' Android-library 'dependencies{Compile Filetree (dir:' Libs ', include: "*.jar")}android{//where you might need to change.Compilesdkversion 19//where you might need to change.Buildtoolsversion "19.1.0"Enforceuniquepackagename=falselintoptions{Abortonerrorfalse} sourcesets{main{manifest.srcfile' Androidmanifest.xml 'Java.srcdirs= [' src '] Resources.srcdirs= [' src '] Aidl.srcdirs= [' src '] Renderscript.srcdirs= [' src '] Res.srcdirs= [' Res '] Assets.srcdirs= [' Assets ']}} lintoptions{abortonerrorfalse    }}

The above comments may need to change the place in other places will not change, unless you use the Gradle is very old version some methods can not be used

4 finally see the contents of my xxx file

ImportJava.util.regex.Pattern//Some of the Java packages usedImportCom.android.builder.core.DefaultManifestParserbuildscript {repositories {mavencentral ()} Dependenc ies {//where you might need to change.Classpath ' com.android.tools.build:gradle:1.0.0 '}}tasks.withtype (javacompile) {options.encoding= "UTF-8"}apply Plugin:' Android 'Dependencies {Compile Filetree (dir:' Libs ', include: ' *.jar ')//where you might need to change.//here project is to compile the meaning of a project note the name and settings in the method will automatically go to work to find settings fileCompile project (': Appcompat_v7_6 '))}android {//where you might need to change.Compilesdkversion 19//where you might need to change.Buildtoolsversion "19.1.0"Enforceuniquepackagename=falseDefaultconfig {//where you might need to change.Targetsdkversion 19} lintoptions{abortonerrorfalse} dexoptions {predexlibraries=false    }//simplifying the compilation processpackagingoptions {Exclude' Meta-inf/dependencies.txt 'Exclude' Meta-inf/license.txt 'Exclude' Meta-inf/notice.txt 'Exclude' Meta-inf/notice 'Exclude' Meta-inf/license 'Exclude' Meta-inf/dependencies 'Exclude' Meta-inf/notice.txt 'Exclude' Meta-inf/license.txt 'Exclude' Meta-inf/dependencies.txt 'Exclude' meta-inf/lgpl2.1 'Exclude' meta-inf/asl2.0 '} signingconfigs {myconfig{storefile file ("Android.keystore") Storepassword"XXX"Keyalias"XXX"Keypassword"XXX"}} buildtypes{release {signingconfig signingconfigs.myconfig proguardfile getdef Aultproguardfile (' Proguard-properties.txt ')}} defaultconfig {manifestplaceholders= [Activitylabel: "DefaultName"]} sourcesets {main {manifest.srcfile' Androidmanifest.xml 'Java.srcdirs= [' src '] Resources.srcdirs= [' src '] Aidl.srcdirs= [' src '] Renderscript.srcdirs= [' src '] Res.srcdirs= [' Res '] Assets.srcdirs= [' Assets ']        }        //get the whole project together. Compiling includes all the. so Filestask Copynativelibs (type:copy) {//where you might need to change.FromNewFile (Project (': Appcompat_v7_6 '). Getprojectdir (), ' Libs ') {include ' **/*.so '} intoNewFile (BuildDir, ' native-libs ')} tasks.withtype (javacompile) {Compiletask-Compiletask.dependson Copynativelibs} clean.dependson' Cleancopynativelibs 'Tasks.withtype (com.android.build.gradle.tasks.PackageApplication) {Pkgtask-Pkgtask.jnifolders =NewHashset<file>() PkgTask.jniFolders.add (NewFile (BuildDir, ' native-libs ') } productflavors {xxx1{} xxx2{} all {flavor-flavor.manifestplaceholders=[Channel:name]}} }}    

Gradle Tutorial [Original] (Eclipse/adt non-plug-in non-Android Studio/as) Pure hand hit the third: Gradle complete combat

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.