How to package native library (*.so) in Android Studio

03 Dec

Recently I was working on some projects where the native library (*.so) is used. It builds in Android Studio without any problem, but when I run it on the Android devices, it crashes with the following error message:

Can’t load xxx library: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/“],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn’t find “

After millions of trial and error, here comes the solution:

    1. Create a folder called “lib” (must be exactly this name)
    2. Create subfolders in lib with desired architecture name such as “armeabi-v7a”, “armeabi” etc.
    3. Put all your *.so file in the just created folder
    4. Now your folder structure should be like this:

    5. Zip the lib folder into a file, e.g.;
    6. Rename this –> abc.jar
    7. Copy this abc.jar to your project subfolder, anywhere should do, but I would typically put it in the app\libs\abc,jar
    8. In the build.gradle, add:

dependencies {
compile files(‘libs/abc.jar’)

Rebuild, that is all! Happy Coding!




Posted by on December 3, 2015 in Android, Programming


Tags: , , , , , , , , ,

4 responses to “How to package native library (*.so) in Android Studio

  1. Marcelo Dos Santos López

    July 26, 2016 at 1:34 am

    It worked!
    You deserve a trophy.
    Thank you, you are ninja.

  2. 翰隆

    October 14, 2016 at 10:08 am

    Thank you very much !!!! You saved my life.

  3. zam

    November 22, 2016 at 1:24 am

    bigup! nice shot

  4. Milan's little blacksmith

    December 21, 2018 at 10:15 am

    tnank you!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: