1. Create Android libraries

Follow these steps to create a new library module in your project:

  1. Go to File > New > New Module.
  2. In the Create New Module window that appears, click Android Library and Next.
  3. Name your library, select a minimum SDK version for the code in the library, and click Finish.

2. Upload aar package to Maven private server

Open a new modulebuild.gradleFile, modify as follows:
plugins {
    id 'com.android.library'    / / library modules
    id 'kotlin-android'      
    id 'maven'			// Import the Maven plugin
}

def snapshotVersionCode = 101
def snapshotVersion = "1.0.1"

/* Omit android{} configuration */

dependencies {
    // UmENG Base component library (all UMeng business SDKS rely on the base component library)
    implementation "Com. Umeng. Umsdk: common: 9.3.6 shall"
    implementation "Com. Umeng. Umsdk: asms: 1.2.0"
    implementation "Com. Umeng. Umsdk: apm: 1.1.1"
}

/* Snapshot maven upload */
uploadArchives {
    configuration = configurations.archives
    repositories {
        mavenDeployer {
            repository(url: 'http://nexus.xxxxx.com/repository/maven-snapshots') {
                authentication(userName: 'userNameXXXX'.password: 'passwordXXXXX')
            }

            pom.project {
                version snapshotVersion + '-SNAPSHOT'
                artifactId 'lib-umeng'
                groupId 'com.xxxxx'
                packaging 'aar'
                description 'lib-umeng Initial submission'}}}}Copy the code
Upload aar to Maven

Select Gradle > Module Name > Upload on the right and double-click uploadArchives to run

3. For other projects

Gradle adds Maven to Project build.gradle

allprojects {
    repositories {

	/* Other configurations */ are omitted
     
        maven { url 'https://dl.bintray.com/umsdk/release' }   // Umeng. umSDK related maven
        maven { url 'https://nexus.xxxxx.com/repository/maven-snapshots' }   // Maven just uploaded by AAR}}Copy the code

Module reference, build.gradle add the following reference

dependencies {
    api ('com. XXXXX: lib - umeng: - the SNAPSHOT 1.0.1 @ aar') {		// Just generated AAR
        implementation "Com. Umeng. Umsdk: common: 9.3.6 shall"		// Note that the AAR implementation dependencies need to be referenced again
        implementation "Com. Umeng. Umsdk: asms: 1.2.0"
        implementation "Com. Umeng. Umsdk: apm: 1.1.1"}}Copy the code

4, QA

  1. Maven upload error:

    Execution failed for task ':lib-umeng:uploadArchives'. \> Could not publish configuration 'archives' \> Failed to deploy  artifacts: Could not transfer artifact com.xxxxx: Lib-umeng: AAR :1.0.1 from/to remote (http://nexus.xxxxx.asia/repository/maven-snapshots): Failed to transfer file: http://nexus.xxxxx.asia/repository/maven-snapshots/com/xxxxx/lib-umeng/1.0.1/lib-umeng-1.0.1.aar. Return code is: ReasonPhrase: Repository version Policy: SNAPSHOT does not allow version: 1.0.1.Copy the code

    Solution: Version snapshotVersion + ‘-snapshot’ tag: -snapshot

Reference: developer.android.com/studio/proj…