- Gradle download and Configuration
Http://www.gradle.org/downloads download path
Configuration: After downloading gradle, decompress it to your directory disk, open the bin directory of gradle, copy its path, open the environment variable, and add the copied content to the path.
After the configuration is complete, open the CMD command tool and run gradle-version. If the correct version number is displayed, the configuration is successful!
- Introduction to gradle simple commands
Build compilation command: run the CMD command to enter the project directory, and then run gradle build. After compilation is successful, you can view the file under build/project.
Run the clean command: gradle clean to clear files after the previous build.
Check command: gradle check allows you to use a checkstyle file similar to the checkstyle file for project check.
- Build. gradle code details
Hide row number copy code? Build. gradle
buildscript {
##### The general idea is to support Java dependency library management (Maven/Ivy) for project dependencies. This is where gradle is powerful...
## How does Gradle find the files for external dependencies? Gradle looks for them in a repository.
## A repository is really just a collection of files, organized by group, name and version.
## Gradle understands several different repository formats, such as Maven and Ivy,
## and several different ways of accessing the repository, such as using the local file system or HTTP.
repositories {
#### Declare at least one type. If Maven is not used, this is the default type. ####
mavenCentral()
## a remote Maven repository ##
maven{
url "http://10.10.20.10:8080/nexus/content/groups/public"
}
}
### Version of The gradle compilation tool ###
dependencies {
classpath ‘com.android.tools.build:gradle:0.9.2‘
}
}
#### Compile the project type ####
apply plugin: ‘android‘
### Compile a third-party package ###
dependencies {
# Compile third-party packages under all libs #
compile fileTree(dir: ‘libs‘, include: ‘*.jar‘)
# Compile a lib package #
compile files("libs\android-support-v4.jar");
}
### Configuration items ###
android {
compileSdkVersion 19
buildToolsVersion "19"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
#### Configure the release signature project and code obfuscation ####
signingConfigs {
myConfig{
storeFile file("gradle.keystore")
storePassword "gradle"
keyAlias "gradle"
keyPassword "gradle"
### Use code obfuscation ###
runProguard true
proguardFile ‘proguard-android.txt‘
}
}
#### Compiled versions (Release and DEBUG Versions )####
buildTypes{
release {
signingConfig signingConfigs.myConfig
}
debug {
packageNameSuffix ".debug"
}
}
#### Change the package name of different channels through multiple channels (playstore and hiapk ####
productFlavors {
playstore {
packageName=‘com.youxiachai.androidgradle.playstore‘
}
hiapk {
packageName=‘com.youxiachai.androidgradle.amazonappstore‘
}
}
sourceSets {
main {
manifest.srcFile ‘AndroidManifest.xml‘
java.srcDirs = [‘src‘]
resources.srcDirs = [‘src‘]
aidl.srcDirs = [‘src‘]
renderscript.srcDirs = [‘src‘]
res.srcDirs = [‘res‘]
assets.srcDirs = [‘assets‘]
jniLibs.srcDirs = [‘libs‘]
}
### Different files can be applied through different channels ###
hiapk {
manifest.srcFile ‘hiapk/AndroidManifest.xml‘
}
playstore {
manifest.srcFile ‘hiapk/AndroidManifest.xml‘
}
### Configure Android testing ###
instrumentTest.setRoot(‘tests‘)
}
### Use lint detection ###
lintOptions {
abortOnError false
}
}
- References source declaration 1. https://gist.github.com/youxiachai/5608223
2. http://www.cnblogs.com/youxilua/archive/2013/05/20/3087935.html
3. https://github.com/Goddchen/Android-Gradle-Examples
Maven usage:
Address: http://jingyan.baidu.com/article/60ccbceb01de4d64cbb19756.html
Build private servers for nexus:
Address: http://www.blogjava.net/ldwblog/archive/2013/11/19/406529.html
JDK 6 selects the Nexus 2.6 version. Otherwise, it cannot be started. JDK 7 is required for nexus2.6 and later versions.