Learn about Gradle in Android studio

Source: Internet
Author: User
Tags maven central jcenter

Always heard that Gradle is very powerful, just occasionally when you create a demo with Android studio to see him once, today take a full record of time.

1.gradle position

After the Android Studio project is created, the default is 3 Gradle files, located at:

    • /settings.gradle
    • /build.gradle
    • /app/build.gradle

2.gradle Content

    • Settings.gradle default is only one line of code, namely:
      Include ': App '

      The newly created project has only one child item for the app. If you add a sub-project (Module) to project, you should add the corresponding subproject name to the Settings.gradle, such as:

      Include ': App ', ': Androidlibrary '

      Tip: When you add a module, the latest version of Android Studio will automatically be configured in Settings.gradle, amazing.

    • The root directory is rich in Build.gradle, with three "nodes",buildscript,allprojects , and task clean by default .
      Buildscript {    repositories {        jcenter ()    }    dependencies {        classpath ' com.android.tools.build: gradle:1.3.0 '    }}allprojects {    repositories {        jcenter ()    }}task Clean (type:delete) {    Delete Rootproject.builddir}

The first child "node" under buildscript is the Declaration warehouse source, the default is Jcenter, the previous version is mavencentral, or two center co-exist. Jcenter can be understood as a new central remote repository, compatible with the MAVEN central repository, and with better performance. The second child "Node" is the version that declares Android Gradle plugin, and Android Studio version 1.5 defaults to Gradle 1.3.

Allprojects is the declaration of all project default warehouse sources.

   Task Clean declares a task called clean (which can also be changed), and the task type is delete (or copy). That is, whenever you click Sync after modifying the Settings.gradle file, the files under Rootproject.builddir will be deleted (actually I see the effect is to clear the external libraries in the package, and then added again).

    • App/build.gradle is the Gradle file for the default Android subproject, and it is also a three-bar point: Apply, Android, and dependencies.
Apply plugin: ' Com.android.application ' android {    compilesdkversion    buildtoolsversion ' 19.1.0 '    defaultconfig {        ApplicationID "Com.nait.picassodemo"        minsdkversion 4        targetsdkversion        Versioncode 1        versionname "1.0"    }    buildtypes {        release {            minifyenabled false            Proguardfiles getdefaultproguardfile (' proguard-android.txt '), ' Proguard-rules.pro '        }    }    productflavors {    }}dependencies {    compile filetree (dir: ' Libs ', include: [' *.jar '])    compile ' com.squareup.picasso:picasso:2.5.2 '    compile ' com.squareup.okhttp:okhttp:2.5.0 '    compile ' com.umeng.analytics:analytics:5.6.1 '    testcompile ' junit:junit:4.12 '}

Appley node: Apply plugin: ' Com.android.application '

Apply in the above statement is a method that passes a parameter to it plugin,plugin the value is ' com.android.application '. If there are multiple parameters, it is separated by commas, for example: Compile name: ' Volley ', ext: ' AAR '.

Android node: The front section is well understood and can be understood literally. Buildtypes default is release (You can also add Debug), minifyenabled Indicates whether confusion is required, proguardfiles indicates a confusing configuration file name. Productflavors is a multi-channel package (later written after further study).

Dependencies node: COM. The beginning part is the reference package that is added to the demo project, the rule is Namesapce:package name:version, and the other two lines are added by default after the project is created.

Reference Documentation:

Http://www.cnblogs.com/youxilua/archive/2013/05/22/3092657.html

Http://www.blogjava.net/wldandan/archive/2012/07/12/382792.html

Http://www.android100.org/html/201502/16/119379.html

Learn about Gradle in Android studio

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.