在Android Studio中引入第三方aar

这里说的是直接以lib方式引入,放到主工程的lib文件加下面。

然后修改module的gradle文件,必须要首先添加本地仓库的路径:

repositories {
    flatDir {
        dirs 'libs'
    }
}
然后在dependencies中compile相关的arr文件,否则不会识别到库

repositories {
    flatDir {
        dirs 'libs'
    }
}

dependencies {
//    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'

    compile(name: 'news_sdk_release_1.0.14_uc', ext: 'aar')
}

参考:https://jingyan.baidu.com/article/2a13832890d08f074a134ff0.html

  1. 新建好的项目结构如下图:

    其中app是我们的主要module,

    libs下存放外部的library

    build.gradle是配置App module的,接下来主要对其操作。

    如何在Android Studio添加本地aar包引用
  2. 复制外部aar包到libs目录下。

    如何在Android Studio添加本地aar包引用
    如何在Android Studio添加本地aar包引用
  3. 修改build.gradle 配置文件:

    1:添加

    repositories     flatDir {        dirs 'libs'    }}

    这个是添加一个本地仓库,并把libs目录作为仓库的地址。

    如何在Android Studio添加本地aar包引用
  4. 2:修改dependencies:

    添加一行:

    compile(name:'usericonchooserutil', ext:'aar')

    其中name就是libs目录下usericonchooserutil.aar文件名称,

    ext,就是usericonchooserutil.aar的扩展名

    如何在Android Studio添加本地aar包引用
  5. 重新编译项目:

    从工具栏依次选择:"Build"-->"rebuild project"

    如何在Android Studio添加本地aar包引用
  6. 编译完成后,在app/build/intermediates/exploded-aar/ a就可以看见我们引用的aar包内容了,其中jar目录下是jar文件,res下是我们aar包里的资源文件。

    如何在Android Studio添加本地aar包引用
  7. 8

    这个时候我们就可以在项目中使用第三包的类了,如下图:

    如何在Android Studio添加本地aar包引用


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值