Gradle 升级 7.0及以上,本地.aar依赖的两种方式

2023-06-05  本文已影响0人  踏雪鸿雁
```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}" }

img_2.png
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:+'
上一篇下一篇

猜你喜欢

热点阅读