美文网首页
生成aar并上传到github中供其他项目调用

生成aar并上传到github中供其他项目调用

作者: 明年的我会感谢今年的我 | 来源:发表于2020-05-14 00:02 被阅读0次

    本文仅供自己参考,所以不详细写,只追求自己看的懂

    一、生成aar并上传到github

    1、把项目改为library或者在项目下新建一个File--new module--android library,如果是项目改的注意删除启动标签,

    没有activity的把manifest中的application也删了,用不到的第三方库全删了,测试模块也可以删了。

    点击studio右侧gradle 插件,点击library模块 build下的 assemble 可以生成aar(因为是项目改的所以library模块名就叫app没有重新再改),在library的build--outputs下,这个就可以直接用添加用了


    image.png

    2、如果是要生成上传到GitHub的,在library 的gradle 末尾 添加

    
    applyplugin:'maven'
    uploadArchives {
    repositories.mavenDeployer {
    
            // 本地存放目录(自行选择),可放在gradle.properties文件中引用
            def mavenDirPath = file('F:\\mavendir')  
    
            // 必须双引号,单引号不会转义$
            repository(url:"file://${mavenDirPath.absolutePath}")
    pom.project {
              // 可以随意取,一般取包名
                groupId"com.example.testcreatearr"
    
                // 可以随意取,一般取库的名字
                artifactId"app"
    
                // 版本号
                version"1.0.0"
            }
        }
    }
    
    

    然后在gradle插架,library下点击uploadArchives


    image.png

    文件就保存在,设置的本地目录下
    def mavenDirPath = file('F:\mavendir')
    为这个文件夹添加git控制,在GitHub中创建一个仓库,把文件传上去,如果要在项目中引用则在package的gradle中添加
    maven { url "https://raw.githubusercontent.com/wozaihu/testmaven/master" }

    不同仓库链接当然不同,用户名是这个仓库所有者的github用户名,
    maven { url "https://raw.githubusercontent.com/用户名/仓库名/master" }

    image.png

    在app的gradle下引用
    implementation 'com.example.testcreatearr:app:1.0.0'

    这里就是上面写的
    implementation 'groupId:artifactId:version'

    如果出现 unable to resolve dependency for app@......

    看能不能访问https://raw.githubusercontent.com
    不能就在C:\Windows\System32\drivers\etc路径下找到hosts文件

    添加 以下内容并保存即可访问(如果这个地址也用不了了,就在找其他的)

    199.232.68.133 raw.githubusercontent.com

    相关文章

      网友评论

          本文标题:生成aar并上传到github中供其他项目调用

          本文链接:https://www.haomeiwen.com/subject/ghbanhtx.html