Include Native *.so Library in APK with Android Studio

Source: Internet
Author: User

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 your is still using Eclipse. The process is basically, the same with Android Studio until, the time comes to build your APK. The APK would build fine, but your library *.so file would be a missing from the APK and if you attempt to load it with Syst Em.loadlibrary ("MyLibrary") you'll get:

1
java.lang.UnsatisfiedLinkError: Couldn‘t load mylibrary from loader dalvik.system.PathClassLoader

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

1
unzip -l MyApp.apk

Android Studio ' s build tool would not look in the usual place:

12
SharedLibrary  : libmylibrary.soInstall        : libmylibrary.so => libs/armeabi/libmylibrary.so

The trick (thanks to this thread:https://groups.google.com/forum/#!msg/adt-dev/nqobkd2gl_8/z5ywavch4h4j) are 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.