Android Studio 关联Module打包成aar和使用本地Maven仓库

关联Module打包成aar(创建Maven项目)

  • 理清自己的项目依赖关系
    我的项目
    项目中两个Module(Interact和JsBridge)需要制作成aar;其中 Interact依赖JsBridge.

  • 按照项目依赖关系由下到上依次制作aar

    1.把JsBridge制作成aar

    配置项目:
    gradle.properties设置全局变量

#全局变量
AAR_REPO_PATH=file:///D:/wpf/workspace/project/zhix/AAR
AAR_VERSION=1.0.0
AAR_GROUP_ID=com.wpf
	JsBridge的build.gradle中配置,最下面添加
//打包发布配置开始
apply plugin: 'maven'
uploadArchives {
    repositories.mavenDeployer {
        repository(url: AAR_REPO_PATH)
        pom.project {
            groupId AAR_GROUP_ID
            artifactId project.getName()
            version AAR_VERSION
        }
    }
}

android studio Terminal中运行 gradlew :JsBridge:uploadArchives
查看自己配置的AAR_REPO_PATH路径下是否参数文件如:
在这里插入图片描述

2.Interact引入本地aar(这里使用上面制作的本地Maven仓库)

配置ZhixDemo项目的build.gradle
repositories {
        google()
        jcenter()
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
        jcenter {
            url AAR_REPO_PATH.toString()
        }
    }
引入JsBridge模块的aar, 配置Interact的build.gradle
def isAar = false
//打包发布配置开始
apply plugin: 'maven'
uploadArchives {
    isAar = true
    repositories.mavenDeployer {
        repository(url: AAR_REPO_PATH)
        pom.project {
            groupId AAR_GROUP_ID
            artifactId project.getName()
            version AAR_VERSION
        }
    }
}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 
    implementation 'com.google.code.gson:gson:2.8.5'
    print("isAar:::$isAar")
    if (isAar){
        implementation "${AAR_GROUP_ID}:JsBridge:$AAR_VERSION"
    }else {
        implementation project(path: ':JsBridge')
    }

}

android studio Terminal中运行 gradlew :Interact:uploadArchives
查看自己配置的AAR_REPO_PATH路径下是否参数文件如:

在这里插入图片描述

如果有必要,可搭建远程仓库,使用***Nexus***搭建。这里就不详述

使用本地Maven仓库

其他项目使用本地库。

1.配置项目build.gradle

repositories {
        google()
        jcenter()  
        jcenter {
            url 'file:///D:/wpf/workspace/project/zhix/AAR'
        }
    }

2.需要使用Interact模块的aar的lib配置build.gradle

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation "com.wpf:Interact:1.0.0"
}

使用远程Maven仓库

其他项目使用本地库。

1.配置项目build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
        google()
        jcenter()
        maven{url '远程仓库地址'}
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.1'
    }
}

allprojects {
    buildscript {
        repositories {
            mavenCentral()
            maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
            maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
            maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
            maven {
                url 'https://jitpack.io'
            }
        }
    }

    repositories {
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
        maven{url '远程仓库地址'}
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

2.需要使用Interact模块的aar的lib配置build.gradle

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation "com.wpf:Interact:XXX"
}

用问题欢迎留言。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值