How Android uses so files and imports so in Android studio

Source: Internet
Author: User

Use so files in Android:

Do a PDF reading function, find an open source library, Mupdf. Download is compiled on-line so library, import into their own project time has been error Java.lang.UnsatisfiedLinkError:Couldn ' t load netplayerlibq:findlibrary returned NULL, The method in the so file could not be found. Looking for an afternoon, finally know the reason.

The naming conventions for methods in JNI are

1) Prefix: Java_
2) The fully qualified name of the class, delimited by an underscore (_): Com_lms_jni_jnitest
3) method Name: getteststring

The method naming is related to the package name, so when using the so library, the package name of the class that called the method is changed to the package name written in the so file. This is the simplest way. Of course, the best way to do this is to find the source project source cross-compiled into a so file containing our project package name.

Reference http://blog.csdn.NET/jiabailong/article/details/7986350

There are two ways to import so in Android Studio:

1. Place the so file in the Libs directory and add the following configuration to the app's Build.gradle

Sourcesets {    main {        = ['libs']    }}

The entire configuration file is as follows:

Android {compilesdkversion atbuildtoolsversion'19.1.0'Defaultconfig {ApplicationID"Com.hehe.itlms"minsdkversion thetargetsdkversion atVersioncode1Versionname"1.0.0"} buildtypes {release {minifyenabledtrue//whether to confuseProguardfiles Getdefaultproguardfile ('Proguard-android.txt'),'Proguard-rules.pro'}} sourcesets {main {jnilibs.srcdirs= ['Libs']        }    }}

2. Compress all required. So files into a. zip file (the file directory structure in the ZIP is: lib/armeabi/*.so) Note that if such a path, lib do not write Libs Ah! Then rename the. zip file to the Armeabi.jar file (I'm using So.jar), add the jar package to the project's Libs file, and add Islibrary.

The final directory structure

Libs
^---|xxx.jar
^---|armeabi.jar
^---|lib
^---|armeabi
^---|xxx.so

How Android uses so files and imports so in 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.