Gradle is a groovy-based dynamic DSL, while the groovy language is a JVM-based dynamic language. Just share the actual development of the scene, you do not need to learn the groovy language, you know Java is very easy to read the groovy language.
The knowledge points of the series blog include: Gradle basic configuration, dependency management, global settings, custom buildconfig, confusion, multi-channel packaging, configuration signature information, unit testing, is not impatient ah, come to learn.
Basic Configuration
Create a new project with the following directory structure:
App/build.gradle
Initialize the Gradle configuration:
Apply plugin: ' Com.android.application ' Android { compilesdkversion & Nbsp;buildtoolsversion "23.0.2" defaultconfig { applicationid " Com.wuxiaolong.gradle4android " minsdkversion targetsdkversion versioncode 1 versionname "1.0" } build Types { release { minifyenabled false &N Bsp proguardfiles getdefaultproguardfile (' proguard-android.txt '), ' Proguard-rules.pro ' } }}dependencies { compile filetree (dir: ' Libs ', include: [' *.jar ']) t Estcompile ' junit:junit:4.12 ' compile ' com.android.support:appcompat-v7:23.2.1 ' compile ' com.android.support:design:23.2.1 '}
apply plugin: ‘com.android.application’,表示该module是一个app module,应用了com.android.application插件,如果是一个android library,那么这里写apply plugin: ‘com.android.library’compileSdkVersion:基于哪个SDK编译,这里是API LEVELbuildToolsVersion:基于哪个构建工具版本进行构建的。defaultConfig:默认配置,如果没有其他的配置覆盖,就会使用这里的。applicationId:配置包名的versionCode:版本号versionName:版本名称buildTypes是构建类型,常用的有release和debug两种,可以在这里面启用混淆,启用zipAlign以及配置签名信息等。dependencies:不属于Android专有的配置了,它定义了该module需要依赖的jar,aar,jcenter库信息。
Gradle-wrapper.properties
Declares the directory and download path for Gradle and the Gradle version used by the current project, which we generally do not change
distributionBase=GRADLE_USER_HOMEdistributionPath=wrapper/distszipStoreBase=GRADLE_USER_HOMEzipStorePath=wrapper/distsdistributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
Build.gradle of the root directory
Define the public properties of all modules under this project
buildscript { repositories { jcenter()//使用jcenter库 } dependencies { classpath ‘com.android.tools.build:gradle:1.5.0‘// 依赖android提供的1.5.0的gradle build // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }}//为所有的工程的repositories配置为jcentersallprojects { repositories { jcenter() }}task clean(type: Delete) { delete rootProject.buildDir}
Setting.gradle
What modules are included, such as apps and libraries:
include ‘:app‘,‘:library‘
Dependency management Local dependent jar
By default, the new Android project will have a Lib folder
dependencies { compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])//即添加所有在libs文件夹中的jar //compile fileTree(‘libs/WuXiaolong.jar‘)//不需要这样一个个去写了}
So package
C or C + + written library will be called so package, Android plugin by default support native package, you need to put the. so file in the corresponding folder
app ├── AndroidManifest.xml └── jniLibs ├── armeabi │ └── libiconv.so ├── armeabi-v7a │ └── libiconv.so ├── mips │ └── libiconv.so └── x86 └── libiconv.so
AAR file
Library output files are. aar files, under Library engineering build/output/aar/
Direct reliance on Library
dependencies { compile project(‘:library名字‘) compile project(‘:libraries:library名字‘)//多个library,libraries是文件夹名字 }
Dependent. aar file
Create a Aars folder, copy the. aar file into the folder, and then add the folder as a dependent library:
repositories { flatDir { dirs ‘aars‘ }}
Or:
dependencies { compile(name:‘libraryname‘, ext:‘aar‘)}
Gradle for Android (i)