Gradle 升级 7.0及以上,本地.aar依赖的两种方式
2023-06-05 本文已影响0人
踏雪鸿雁
-
方式一:本地直接依赖
新建library,并将xxx.aar文件复制到对应目录中,在目录下新建build.gradle文件,并添加如下代码:
img.pngconfigurations.maybeCreate("default") artifacts.add("default", file('xxx.aar'))
settings.gradle中加入
include ':localRepos:Adview_aar' include ':localRepos:GDT_Mob_aar' include ':localRepos:IadSDK_aar' include ':localRepos:JAD_Yun_aar' include ':localRepos:Kd_aar' include ':localRepos:Kssdk_Ad_aar' include ':localRepos:Open_Ad_aar'
引入依赖库
implementation project(':localRepos:Adview_aar') implementation project(':localRepos:GDT_Mob_aar') implementation project(':localRepos:IadSDK_aar') implementation project(':localRepos:JAD_Yun_aar') implementation project(':localRepos:Kd_aar') implementation project(':localRepos:Kssdk_Ad_aar') implementation project(':localRepos:Open_Ad_aar')
-
方式二:将.aar文件发布到MavenLocal库进行依赖
img_1.png1、新建PublishMaven目录
2、新建libs目录,将所有的.aar文件复制到libs目录下
3、新建build.gradle文件
4、build.gradle加入如下代码
```groovy
apply plugin: 'maven-publish'
/*将本地.aar文件通过maven-publish发布到mavenLocal*/
publishing {
publications {
Production_A(MavenPublication) {
// 使用方引用 implementation 'com.hongwen.lib:adview:4.4.4'
groupId = "com.hongwen.lib"
artifactId = "adview"
version = "4.4.4"
artifact file('libs/adview-android-4.4.4.aar')
}
Production_B(MavenPublication) {
// 使用方引用 implementation 'com.hongwen.lib:gdt_mob_release:2.0.20'
groupId = "com.hongwen.lib"
artifactId = "gdt_mob_release"
version = "2.0.20"
artifact file('libs/gdt_mob_release.aar')
}
Production_C(MavenPublication) {
// 使用方引用 implementation 'com.hongwen.lib:iadsdk:2.0.20'
groupId = "com.hongwen.lib"
artifactId = "iadsdk"
version = "2.0.20"
artifact file('libs/iadsdk.aar')
}
Production_D(MavenPublication) {
// 使用方引用 implementation 'com.hongwen.lib:jad_yun_sdk:2.0.20'
groupId = "com.hongwen.lib"
artifactId = "jad_yun_sdk"
version = "2.0.20"
artifact file('libs/jad_yun_sdk.aar')
}
Production_E(MavenPublication) {
// 使用方引用 implementation 'com.hongwen.lib:kd:2.0.20'
groupId = "com.hongwen.lib"
artifactId = "kd"
version = "2.0.20"
artifact file('libs/kd.aar')
}
Production_F(MavenPublication) {
// 使用方引用 implementation 'com.hongwen.lib:kssdk-ad:2.0.20'
groupId = "com.hongwen.lib"
artifactId = "kssdk-ad"
version = "2.0.20"
artifact file('libs/kssdk-ad.aar')
}
Production_G(MavenPublication) {
// 使用方引用 implementation 'com.hongwen.lib:open_ad_sdk:2.0.20'
groupId = "com.hongwen.lib"
artifactId = "open_ad_sdk"
version = "4.7.0.8"
artifact file('libs/open_ad_sdk_4.7.0.8.aar')
}
}
repositories {
maven {
// url = "$rootDir/repos"
url = "${rootDir.parent}/repos"
// url = "../../../repos"
}
mavenLocal()
}
}
```
5、项目跟目录下build.gradle 添加本地Maven仓库存放的路径,如:
//maven本地仓库
maven { url "file://${LOCAL_REPOS}" }
6、依赖库的使用
直接全部依赖
implementation 'com.hongwen.lib:+'
或者分开选择性依赖
implementation 'com.hongwen.lib:adview:+'
implementation 'com.hongwen.lib:gdt_mob_release:+'
implementation 'com.hongwen.lib:iadsdk:+'
implementation 'com.hongwen.lib:jad_yun_sdk:+'
implementation 'com.hongwen.lib:kd:+'
implementation 'com.hongwen.lib:kssdk-ad:+'
implementation 'com.hongwen.lib:open_ad_sdk:+'