Android Studio打包.so库到apk中实例详解
作者:lqh 时间:2022-06-25 19:19:25
Android Studio打包.so库到apk中实例详解
由于在原来的ADT的Eclipse环境中,用ndk_build工具生成了相应的各个.so库文件之后,eclipse工具就会自动把这些库导入到apk中。而Android Studio目前为止(1.1.0版本)还无法做到那么自动,但是我们可以通过以下方式进行。
首先在Android Studio工程的app目录下创建整个jni目录,jni目录里写Android.mk、Application.mk以及各类C/C++和汇编源文件。然后跟原来一样,用ndk_build工具去编,然后工具会自动生成libs目录,里面还有每个你在Application.mk里所指定处理器架构的so文件。
完成之后,编辑你对应module(类似eclipse中的project)目录下的build.gradle文件,为其添加以下代码:
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
比如本人module完整的build.gradle文件如下所示:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.example.way.aligesture"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':acra')
compile project(':hwdroid')
}
最后记得选中对应的module右击synchronize同步一下,以便使其生效。如下图所示,module目录下回生成一个jniLibs目录,再打包生成的apk就会带上.so了。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
标签:Android,Studio,打包.so库
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android实现图片设置圆角形式
2023-07-29 16:37:32
![](https://img.aspxhome.com/file/2023/6/85456_0s.jpg)
Springboot集成graylog及配置过程解析
2023-06-18 17:15:02
![](https://img.aspxhome.com/file/2023/7/64167_0s.png)
C#中常用的运算符总结
2023-10-10 04:09:32
android使用gesturedetector手势识别示例分享
2023-08-08 15:06:11
springcloud之自定义简易消费服务组件
2022-01-29 00:18:24
![](https://img.aspxhome.com/file/2023/8/61878_0s.png)
C#实现Word转换TXT的方法详解
2022-12-26 04:27:57
![](https://img.aspxhome.com/file/2023/4/85714_0s.png)
C#实现文件与字符串互转的方法详解
2023-04-26 03:18:12
![](https://img.aspxhome.com/file/2023/2/70402_0s.png)
Java基于ShardingSphere实现分库分表的实例详解
2022-04-20 18:43:37
![](https://img.aspxhome.com/file/2023/0/76270_0s.jpg)
java开发ShardingSphere的路由引擎类型示例详解
2023-11-29 01:18:56
Android实现图像切换器
2023-11-27 00:45:41
![](https://img.aspxhome.com/file/2023/7/108247_0s.jpg)
C#字体池技术实现代码详解
2022-12-30 06:18:02
浅谈Spring Cloud Ribbon的原理
2023-07-23 04:11:25
![](https://img.aspxhome.com/file/2023/6/76506_0s.png)
Android编程实现canvas绘制饼状统计图功能示例【自动适应条目数量与大小】
2023-05-10 23:27:41
![](https://img.aspxhome.com/file/2023/9/113299_0s.jpg)
Java 数组获取最大和最小值的实例实现
2021-06-18 15:53:06
![](https://img.aspxhome.com/file/2023/2/77462_0s.png)
Spring-boot 2.3.x源码基于Gradle编译过程详解
2022-04-07 15:41:36
![](https://img.aspxhome.com/file/2023/2/66032_0s.png)
基于Springboot实现JWT认证的示例代码
2023-04-01 09:46:40
![](https://img.aspxhome.com/file/2023/9/83029_0s.jpg)
Springboot上传文件时提示405问题及排坑过程
2022-12-13 03:03:58
![](https://img.aspxhome.com/file/2023/7/63627_0s.png)
深入XPath的详解以及Java示例代码分析
2021-11-01 13:42:33
Java实现简单登陆界面
2022-11-25 05:47:47
![](https://img.aspxhome.com/file/2023/8/63398_0s.png)
详解Java如何实现在PDF中插入,替换或删除图像
2022-04-07 22:40:36
![](https://img.aspxhome.com/file/2023/4/80864_0s.jpg)