always heard Gradle is very powerful, just occasionally when you create a Demo with Android Studio and see him once, take a moment to complete the recording today.
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 after Module, the latest version of Android Studio will be automatically configured in settings.gradle ,amazing.
the build.gradle of the root directory is richer, with three "nodes" by default,Buildscript,allprojects, and task clean .
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 , andthe Android Studio 1.5 version is Gradle 1.3 by default .
Allprojects is the declaration of all project default warehouse sources.
Task Clean declares a task called clean(which can also be changed), the task type is Delete(or Copy), or whenever you modify Settings.gradle file After clicking Sync, will delete the file under rootproject.builddir ( actually I see the effect is to clear the External Libraries And then add it 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 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 '
Apply in the above statement is a method that passes a parameter plugin to it, and the value of plugin 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 it needs to be confused, Proguardfiles indicates the name of the obfuscation configuration file. Productflavors is a multi-channel package (later written after further study).
Dependencies node:com. The beginning part is 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.
of course, after the development APP It is also necessary to conduct a full range of tests: www.ineice.com
Learn about Gradle in Android studio