手动(Aapt)将本机库.so添加到APK [英] Manually (aapt) add native library .so to apk
问题描述
出于多种原因,我正在手动构建项目(或多或少地遵循以下步骤 http://geosoft.no/development/android.html ),而没有使用ant.
For multiple reasons I'm building my project manually (more or less following these steps http://geosoft.no/development/android.html), whithout using ant.
我的项目使用NDK并构建了一个 .so
库.
My projects uses the NDK and builds a .so
library.
- 使用Eclipse:
使用Eclipse构建项目时,一切正常:将 libMyNativeLib.so
拖放到 libs/armeabi
目录中,并调用 loadLibrary(MyNativeLib)
正常工作:我可以从Java代码中调用本地方法.
When I use Eclipse to build my project, everything works: I drag&drop libMyNativeLib.so
in the libs/armeabi
directory and when I call loadLibrary(MyNativeLib)
it works fine: I can call native method from my Java code.
- 手动:
现在,我想手动构建 .apk
.除了从本地lib加载,一切都可以正常工作.使用 aapt add
,我在我的apk中添加了 lib/armeabi/libMyNativeLib.so
(我看到Eclipse生成的apk在 lib中包含此.so/armeabi
,因此我在apk中使用了相同的路径).调用 loadLibrary(MyNativeLib)
时,出现以下异常
Now I want to build manually my .apk
. Everything works except from the native lib loading.
Using aapt add
, I have added in my apk : lib/armeabi/libMyNativeLib.so
(I saw that the apk generated by Eclipse contains this .so in lib/armeabi
so I used the same path in the apk).
When calling loadLibrary(MyNativeLib)
, I got the following exception
java.lang.UnsatisfiedLinkError: Couldn't load MyNativeLib from loader dalvik.system.PathClassLoader[DexPathList...
那是为什么?
我是否应该在 dx --dex
步骤中针对本机代码( .so
lib)执行某些操作?我不这样认为,但我可能错了吗?(我只将 dx --dex
与我的 .jar
库一起使用,这是我想的逻辑).
Should I do something in the dx --dex
step regarding the native code (.so
lib) ? I don't think so but I'm maybe wrong ? (I'm only using dx --dex
with my .jar
libs which is logic I guess).
你有什么主意吗?
谢谢
推荐答案
感谢apktool( http://ibotpeaches.github.io/Apktool/)我发现了问题所在.
Thanks to apktool (http://ibotpeaches.github.io/Apktool/) I found out what was wrong.
生成最终 .apk
包的makefile出错.实际上, aapt add
命令在路径中包含 \
而不是/
.在Windows上生成时,我所有的路径都使用 \
作为分隔符.这就是为什么我将 \
用于 aapt add
的原因.但是,由于在Android(Unix)上 .apk
的安装过程中使用了此路径,因此我应该使用/
分隔符.
The makefile that generates the final .apk
bundle had an error. Indeed the aapt add
command contained \
in the path instead of /
. As I'm generating on Windows, all my paths use \
as a separator. That's why I used \
for aapt add
. However as this path is used during the installation of the .apk
on Android (Unix), then I should have used /
separator.
这篇关于手动(Aapt)将本机库.so添加到APK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!