Gradle Library Projects
The Gradle project can depend on other components. These components can be external binary packages, or other Gradle projects.
In this example, App/build.gradle has the following:
dependencies {
compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])
compile ‘com.android.support:appcompat-v7:21.0.3‘
compile project(‘:library‘)
compile ‘com.nineoldandroids:library:2.4.0‘
}
Local Packages (native pack)
compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])
Refer to all. jar files under the Libs directory. If you point to a specified jar in the reference Libs directory, you can set this:
compile files(‘libs/xx.jar‘)
Remote artifacts (remotely file)
compile ‘com.android.support:appcompat-v7:21.0.3‘
Reference 21.0.3 version of APPCOMPAT-V7.
With Android support in Android Studio, Android support Repository needs to be downloaded in the SDK, and the version used in the project cannot be larger than the version in the SDK.
When you have downloaded the specified version of Android support Repository in your SDK, you can also rely on the corresponding files in Android Studio, even if you don't have the Internet.
If your SDK does not download the specified version of Android support Repository, it will go wrong even if you are connected to the Web.
compile ‘com.nineoldandroids:library:2.4.0‘
Reference 2.4.0 version of Nineoldandroids. Requires a networked download.
You need to add a warehouse to the list in Build.gradle when using Maven and Ivy.
buildscript {
repositories {
jcenter()
}
}
allprojects {
repositories {
jcenter()
}
}
- Mavencentral (): Indicates dependency is obtained from the Central Maven 2 warehouse.
- Jcenter (): Indicates dependency is obtained from Bintary's Jcenter Maven repository.
- Mavenlocal (): Indicates dependency is obtained from the local Maven repository.
Library project
Compile project (': library ')
The reference name is the module of the library. It should be noted that the referenced module needs to be registered in the {@projectName}/settings.gradle file.
We can observe that the Apply plugin used in Library/build.gradle is ' com.android.library '. Used to mark this as an Android Library Project.
Of course, you can also rely on a Java Project, apply plugin as ' Java '.
Supplemental content
Additional additions to the dependency are as follows:
dependencies {
Introduce a jar package.
Refers to a specific jar.
Compile files (' Libs/xx.jar ')
Refer to all jars except Xx.jar under the Libs folder.
Compile Filetree (dir: ' Libs ', include: [' *.jar '], exclude: [' Xx.jar '])
The so package changes to @{modulename}/src/main/jnilibs in the 0.8 version of Android Studio directory. And you can not configure so at this point.
Introduced from the MAVEN library.
Compile ' com.github.chrisbanes.actionbarpulltorefresh:extra-abc:0.9.2 '
Reference to the Lib project.
Compile project (': ModuleName ')
Reference Users-library. The Users-library function is used at compile time, but the jar is not packaged into the APK, and the required content is provided by the services installed on Android or Android.
Usage scenarios:
1. Use some of the hidden APIs in Android's Framework-classes.jar.
2. Google's service framework or other service framework. Need to be used in conjunction with Uses-library in Androidmainfest.xml.
Provided files (' Libs/xx.jar ')
Provided ' aaa:bbb:x.x.x '
Reference dependencies in the test environment.
Reference the jar file.
Androidtestcompile files (' Libs/xx.jar ')
Reference maven.
Androidtestcompile ' junit:junit:4.11 '
Reference dependency under the Baidu Productflavors branch.
Reference the jar file.
Baiducompile files (' Libs/xx.jar ')
Reference maven.
Baiducompile ' aaa:bbb:x.x.x '
Under the release Buildtypes branch, refer to dependencies.
Reference the jar file.
Releasecompile files (' Libs/xx.jar ')
Reference maven.
Releasecompile ' aaa:bbb:x.x.x '
}
Android Studio Learning----Add Project Dependency Package Summary