Learn about Gradle and androidgradle in Android Studio

Source: Internet
Author: User
Tags maven central jcenter

Learn about Gradle and androidgradle in Android Studio

I have always heard that Gradle is very powerful, but I only saw it once when I used Android Studio to create a Demo. Today I took a moment to record it completely.

1. gradle location

After the Android Studio project is created, three gradle files are created by default, which are located:

  • /Settings. gradle
  • /Build. gradle
  • /App/build. gradle

2. gradle content

  • By default, settings. gradle has only one line of code, namely:
    include ':app'

    The newly created Project has only one sub-project of the app. If a sub-project (Module) is added to a project, you need to add the corresponding sub-project name in settings. gradle, for example:

    include ':app', ':androidlibrary'

    Tip: After you add a Module, the latest version of Android Studio is automatically configured in settings. gradle, Amazing.

  • The build. gradle in the root directory is rich. By default, there are three "nodes ",Buildscript,AllprojectsAndTask clean.
    buildscript {    repositories {        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:1.3.0'    }}allprojects {    repositories {        jcenter()    }}task clean(type: Delete) {    delete rootProject.buildDir}

BuildscriptThe first sub-"Node" under is the declaration repository source. The default is jcenter, and the previous version is mavenCentral. The two centers can coexist. Jcenter can be understood as a new central remote warehouse, compatible with maven central warehouse, and with better performance. The second sub-node declares the version of Android gradle plugin. The default version of Android Studio 1.5 is gradle 1.3.

Allprojects declares the default repository sources for all projects.

  Task cleanDeclared a task named "clean" (or "other"). The Task Type is "Delete" (or "Copy"), that is, every time you modify settings. click synchronize next to the gradle file to delete the rootProject. files under buildDir (in fact, the effect I see is to clear the packages in External Libraries, and then add the package again ).

  • App/build. gradle is the gradle file of the default android sub-item, and it is also three small nodes: apply, android, and dependencies.
apply plugin: 'com.android.application'android {    compileSdkVersion 15    buildToolsVersion '19.1.0'    defaultConfig {        applicationId "com.nait.picassodemo"        minSdkVersion 4        targetSdkVersion 15        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'

In the preceding statement, apply is a method that passes a parameter plugin. The value of plugin is 'com. android. application '. Multiple parameters are separated by commas (,), for example, compile name: 'volley 'and ext: 'aar '.

Android node: the previous part is easy to understand and can be understood literally. BuildTypes is release by default (or debug can be added). minifyEnabled indicates whether obfuscation is required, and proguardFiles indicates the name of the configuration file. ProductFlavors indicates a multi-channel package (which can be written after deep learning ).

The dependencies node: com. Starts with the reference package added to the Demo project. The rule is namesapce: package name: version. The other two lines are added by default after the project is created.

 

Reference:

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

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.