Personal blog: www.milovetingting.cn
Android Gradle builds multiple projects
Android Project Differences
Android project generally divided into library project, application project, the test project, Android Gradle according to these projects respectively corresponding to three kinds of plug-ins: com. Android. Library, com. Android. Application, com. Android. Test.
Android multi-project Settings
In Gradle, there are no restrictions on the structure of the projects. Just configure the projects in settings. Gradle.
Configuration referenced by the library project
Reference to the Android library project, implemented in Dependencies:
dependencies{
implements project(':plugin')}Copy the code
The library project is released separately
Maven private server setup
To build your own Maven private server, we recommend Nexus Repositories Manager.
The specific construction is as follows:
1. Download. At https://www.sonatype.com/ to choose corresponding software type, here I choose is OSS3 version, namely the free version. On the https://www.sonatype.com/download-nexus-repo-oss page select need to download the application according to the operating system.
2. Decompress. There are two folders, nexus-3.13.0-01 and Sonatype -work.
3. Start. Go to the bin directory in nexus-3.13.0-01 and enter./nexus start on the command line interface to start the Nexus.
4. Visit http://localhost:8081 by browser. If the visit is successful, the Nexus is successfully built. Log in with the default administrator account admin and password admin123 to view the default repository.
The specific configuration of the Nexus is not explained here. You can find relevant resources on the Internet for details, and only use the default configuration here.
Library project release
Create a new Android Library named TestLib and configure it in the root directory of gradle.properties as follows:
# maven local config # versionName=1.0.0# Snapshot version snapshotVersionName=1.0MavenSnapshotUrl = HTTP://localhost:8081/repository/maven-snapshots/MavenReleasesUrl = HTTP://localhost:8081/repository/maven-releases/Maven_local_username =admin maven_local_password=admin123 # project id maven_pom_groupId=com.wangyz.plugins # Project name Maven_pom__artifactId =testlib # Package type maven_pom__packaging=aar maven_pom__description=test uploadCopy the code
Add the following configuration to the build.gradle Android node in the TestLib directory:
// type Displays the specified task type or task, which specifies that the Javadoc task is to be executed. This task is defined in Gradle
task androidJavadocs(type: Javadoc) {
// Set the location of the source code
source = android.sourceSets.main.java.sourceFiles
}
/ / generated javadoc. Jar
task androidJavadocsJar(type: Jar) {
// Specify the document name
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
/ / generated sources. The jar
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
// The task that generates the relevant configuration file
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}
// Upload tasks to Maven
uploadArchives {
repositories.mavenDeployer {
repository(url: mavenReleasesUrl) {
authentication(userName: maven_local_username, password: maven_local_password)
}
snapshotRepository(url: mavenSnapshotUrl) {
authentication(userName: maven_local_username, password: maven_local_password)
}
pom.project {
// Note: this is done by switching the assignment of versionName to distinguish between the uploaded snapshot package and the official package (the snapshot version must end with -snapshot).
//version snapshotVersionName
version versionName
artifactId maven_pom__artifactId
groupId maven_pom_groupId
packaging maven_pom__packaging
description maven_pom__description
}
}
}
Copy the code
Switch to the TestLib directory and run the gradle uploadArchives command. After the command is successfully executed, you can view the upload success in the browser.
Library project references
In the project to reference, such as app, add the following configuration to the allProjects node in the build.gradle root directory of the project:
allprojects {
repositories {
google()
jcenter()
mavenCentral()
mavenLocal()
maven {
url mavenReleasesUrl
}
maven {
url mavenSnapshotUrl
}
maven {
url 'https://maven.google.com'}}}Copy the code
Then add a dependency to your app’s build.gradle:
dependencies {
implementation 'com. Wangyz. Plugins: testlib: 1.0'
}
Copy the code
After the project is synchronized, you can reference the related resources of TestLib.
Refer to the following resources, thank you!
www.jianshu.com/p/33d986121…