build.gradle
//Set the running environment of the script
buildscript {
//Support java dependency library management (maven/ ivy), used for project dependencies.
repositories {
mavenCentral()
}
//Definition of dependent packages.
Supports maven/ivy, remote and local libraries, and also supports single files
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
//Declare the type of project to be built, here of course it is android
apply plugin: 'android'
//Set parameters for compiling android projects
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
//Android default configuration
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']< /p>
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
//The path where the test is located, assuming it is the tests folder, if not, you don’t need to write this line p>
instrumentTest.setRoot('tests')
}
//This is the code to solve the lint error
lintOptions {
abortOnError false
}
/**
* Signing settings
*/
signingConfigs {
myConfigs {
storeFile file("signature file address")
keyAlias ??"..."
keyPassword ".. ."
storePassword "..."
}
}
/**
* Confusion Settings
*/
buildTypes {
release {
signingConfig signingConfigs.myConfigs
runProguard true p>
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
/**
* Channel packaging (different package names)
*/
productFlavors {
qqqq {
applicationId = 'Package name'
}
hhhhh {
applicationId='Package name'
}
}
}
/**
* Import of .so files
*/
task copyNativeLibs (type: Copy) {
from fileTree(dir: 'libs', include: 'armeabi/*.so') into 'build/lib'
}
tasks.withType(Compile) {
options.encoding = "UTF-8"
}
tasks.withType(Compile) { p>
compileTask -> compileTask.dependsOn copyNativeLibs
}
clean.dependsOn 'cleanCopyNativeLibs'
tasks.withType(com.android.build. gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniFolders = [new File(buildDir, 'lib')]
}
//Dependencies Library
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
gradle as a build tool can easily use local jar packages. The following are the code blocks used.
ependencies {
//Single file dependency
compile files('libs/android-support-v4.jar')
//All dependencies under a certain folder
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
}
gradle supports maven and ivy at the same time. Since I have never used ivy, I use maven as an example. The following is the code block:
repositories {< /p>
//Get dependencies from the central library
mavenCentral()
//Or use the specified local maven library
maven{< /p>
url "file://F:/githubrepo/releases"
}
//Or use the specified remote maven library
maven{
url "remote library address"
}
}
dependencies {
//Application Format: packageName:artifactId:version
compile 'com.google.android:support-v4:r13'}
android {
}
If the project depends on the android library, it is not as simple as relying on a jar. The gradle mulit project mechanism needs to be used here. In the past, the android library did not have a good package management method. To put it simply, before the emergence of gradle, there was no official way to manage the dependency packages of the android library. Generally, we directly downloaded other people's android library projects. Source code is integrated, and the third-party android-maven-plugin uses apklib format.
Now, the official has finally launched a packaging format for android library, with the extension *.aar. As mentioned earlier, the current android gradle plug-in does not support the direct use of *.aar files locally. However, it supports the reference method of the package management library. Below, I will tell you how to publish and use the android library.
Packaging the android library
To package the android library, just use gradle build under the library project. Then, you will see two *. in the build/libs directory. Aar files, one for debug package and one for release, depending on personal needs. Here we use the release version of the .aar file.