码迷,mamicode.com
首页 > 移动开发 > 详细

Include Native *.so Library in APK With Android Studio

时间:2014-12-26 14:30:47      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

Originally posted on:http://www.kylethielk.com/blog/include-native-so-library-in-apk-with-android-studio/

Using the Android NDK is well documented throughout the internet if you are still using Eclipse. The process is basically the same with Android Studio until the time comes to build your APK. The APK will build fine, but your library *.so file will be missing from the APK and when you attempt to load it with System.loadLibrary(“mylibrary”) you will get:

1
java.lang.UnsatisfiedLinkError: Couldnt load mylibrary from loader dalvik.system.PathClassLoader

You can view the contents of your APK with the following command to verify libmylibrary.so is not in the APK:

1
unzip -l MyApp.apk

Android Studio’s build tool will not look in the usual place:

1
2
SharedLibrary  : libmylibrary.so
Install        : libmylibrary.so => libs/armeabi/libmylibrary.so

The trick (thanks to this thread: https://groups.google.com/forum/#!msg/adt-dev/nQobKd2Gl_8/Z5yWAvCh4h4J) is to move libmylibrary.so to:

1
src/main/jniLibs/armeabi/libmylibrary.so

Voila, your native code is now compiled into your APK. This should work with build tools 0.8+

Include Native *.so Library in APK With Android Studio

标签:

原文地址:http://www.cnblogs.com/GoAhead/p/4186620.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!