当前位置:   article > 正文

Android Studio 关联Module打包成aar和使用本地Maven仓库_android maven打包aar不依赖三方aar 修改pom

android maven打包aar不依赖三方aar 修改pom

关联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
  • 1
  • 2
  • 3
  • 4
	JsBridge的build.gradle中配置,最下面添加
  • 1
//打包发布配置开始
apply plugin: 'maven'
uploadArchives {
    repositories.mavenDeployer {
        repository(url: AAR_REPO_PATH)
        pom.project {
            groupId AAR_GROUP_ID
            artifactId project.getName()
            version AAR_VERSION
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

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

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

配置ZhixDemo项目的build.gradle
  • 1
  • 2
  • 3
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()
        }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
引入JsBridge模块的aar, 配置Interact的build.gradle
  • 1
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')
    }

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

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'
        }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

使用远程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
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41

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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

用问题欢迎留言。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/331432
推荐阅读
相关标签
  

闽ICP备14008679号