Android Gradle Plugin Learning

Source: Internet
Author: User
Tags maven central jcenter eventbus

Introduction Java Engineering There are three major building tools ant, Maven, Gradle. Ant needs to write too many things by hand, and Maven relies on project building for a policy management project that uses conventions over configuration, and has a MAVEN central repository. Gradle is also a task-driven type of policy that uses conventions over configuration. and can manage dependencies and remove load dependencies from the MAVEN central repository or jcenter (or customize the MAVEN warehouse address) recommend that Android works with the Jcenter,java project using MAVEN warehouse。 Build an automated project. The acquaintance of Gradle started from Androidstudio. Using Gradle as a target for the new building system:
    • Make it easier to reuse code and resources.
    • Making it easier to create different versions of the same application, whether it's multiple APK release versions or different custom versions of the same app.
    • Make the build process easier to configure, extend, and customize.
    • Integrate the best Ides
Use
Buildscript {//Set warehouse address repositories {//If using MAVEN Central warehouse mavencentral ()//Custom MAVEN warehouse address/** maven {*url "/HTTP/    Maven.petrikainulainen.net/repo "*}*///recommended Android project using Jcenter,java project using MAVEN warehouse Jcenter ()}//set Gradle version, not app dependency, dependencies {//If there is a version inconsistency issue, you can write this://classpath ' com.android.tools.build:gradle:1.2.+ ' classpath ' com.android.tools. build:gradle:1.2.2 '//Note:do not place your application dependencies here; They belong//in the individual module Build.gradle files}//Sometimes, our code uses UTF-8 to save, but the environment for Gradle build is GBK such, This will include the following error://encoding GBK characters. This time we need to manually set the compile-time encoding type. Tasks.withtype (javacompile) {options.encoding = "UTF-8"}}//apply plugin: ' Android '//apply plugin: ' Android-library ' AP Ply plugin: ' Com.android.application ' android {compilesdkversion buildtoolsversion ' 22.0.1 '//To avoid introducing third-party libraries is an error, excluding possible duplicates License file packagingoptions {exclude ' meta-inf/dependencies ' exclude ' meta-inf/notice ' Exclude ' ME Ta-inf/license ' Exclude ' meta-inf/license.txt ' Exclude ' meta-inf/notice.txt '} defaultconfig {ApplicationID ' NET.XBYNET.SETW Allpaper "Minsdkversion targetsdkversion-Versioncode 1 Versionname" 1.0 "}//build type, you can construct Configure PR for Proguard files, such as release version or debug version or multi-channel package Buildtypes {release {minifyenabled false// Oguardfiles getdefaultproguardfile (' proguard-android.txt '), ' Proguard-rules.pro ' minifyenabled true ZipAlignEna Bled true//Remove useless resource file shrinkresources truesigningconfig signingconfigs.release}hiapk     {packagenamesuffix ". hiapk"} playstore {Packagenamesuffix ". Playstore"} }//multi-channel packaging, in the case of Friends Alliance, of course, there is a placeholder/***<meta-data*android:name= "Umeng_channel" *android:value= "${" in the manifest file Umeng_channel_value} "/>*//** can also be used this way * productflavors {* Xiaomi {* Manifestplaceholders = [Umeng_chan   Nel_value: "Xiaomi"] *} * _360 {* Manifestplaceholders = [umeng_channel_value: "_360"] *} * Baidu {* MANIFESTPLA Ceholders = [Umeng_channel_value: "Baidu"] *} * Wandoujia {* Manifestplaceholders = [Umeng_channel_va LUE: "Wandoujia"] *} *} */productflavors {wandoujia {} _360 {} Baidu {} Xiaomi { }} productflavors.all {flavor, flavor.manifestplaceholders = [Umeng_channel_value:name]}}//sign Name related Signingconfigs {debug {//No debug config} release {//Do not display log Buildco Nfigfield "Boolean", "Log_debug", "false" StoreFile file (".  /yourapp.keystore ") Storepassword" Your password "Keyalias" your alias "Keypassword" Your Password "}}}//dependent settings, not part of the Android child element. dependencies {//comment out the following sentence, as this can cause multiple problems with ANDROID.SUPPORT-V4. Compile Filetree (dir: ' Libs ', include: ' *.jar ')//replaced by the following form: GroupID in Maven warehouse is different com.google.anDroidcompile ' com.android.support:appcompat-v7:22.0.0 ' Compile files (' Libs/eventbus-2.4.0.jar ')// Dependent on the local engineering libs directory Eventbus-2.4.0.jar compile ' com.android.support:appcompat-v7:22.0.0 '//download dependency provided ' from MAVEN Central Library ' ORG.R oboguice:roboblender:3.0 '//download dependent compile ' org.roboguice:roboguice:3.0 ' from MAVEN Central Library//download dependent compile project from MAVEN Central Library (': Li BRARIES:LIB1 ')//dependent on an item}

Reference: http://blog.csdn.net/changemyself/article/details/39927381http://blog.jobbole.com/72992/
Http://www.cnblogs.com/youxilua/p/3348162.html
Http://www.cnblogs.com/youxilua/archive/2013/05/20/3087935.html
http://blog.csdn.net/ljchlx/article/details/43059467

Android Gradle Plugin Learning

Related Article

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.