android studio 使用.so .jar .aar文件

参考> http://www.androidchina.net/2467.html

这里写图片描述

1.使用.jar

(1)利用工具添加jar

将jar拷贝至工程的libs下(若不存在则创建)
这里写图片描述

open module setting>>Dependencies>>+>>File Dependence>> 添加libs下的.jar文件

这里写图片描述
就成功添加了。

(2)手动添加jar

打开module下的build.gradle,在dependencies里面添加依赖文件
第一种方法:添加单个文件

dependencies {
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile files('libs/first.jar') //compile files('jar包的路径')
}

第二种方法:添加目录下符合要求的文件

dependencies {
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile fileTree(include: ['*.jar'], dir: 'libs')//添加libs目录下所有的.jar包
}

该方法在需要导入多jar包的工程中使用更广

2.使用.aar

上文提到的compile fileTree不支持aar,因此需要按照以下步骤操作:
1.将aar放置于libs
2.打开module的build.gradle,添加

repositories {
    flatDir {
        dirs 'libs' //this way we can find the .aar file in libs folder
    }
}

3.在dependencies中添加

 compile(name: 'librarydemo', ext: 'aar')//说明文件名和类型

3.使用.so

添加时有个注意点就是添加的路径要设置正确,Android Studio 默认的so文件路径是app/src/main/jniLibs/armeabi
可以在main下面新建一个jniLibs目录,然后将文件全部复制进去便可以运行程序了
这里写图片描述

如果你想统一管理各种第三方文件,例如放在libs中
这里写图片描述
需要在gradle的android {}中添加以下代码来更改默认路径

 sourceSets {
        main {
            jniLibs.srcDir "libs"
        }
    }

编译或运行时若提示找不到库,clean project再运行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值