赞
踩
理清自己的项目依赖关系
项目中两个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***搭建。这里就不详述
其他项目使用本地库。
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"
}
其他项目使用本地库。
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"
}
用问题欢迎留言。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。