Android Studio uses JNI, so libraries

Source: Internet
Author: User

Android Studio uses JNI, so libraries

After Android Studio1.1, as has already supported the JNI and so library, immediately released the 1.3 official version, but also can be compiled in the clion environment C, C + +, more convenient to use the NDK for development, online there are many speaking on Android The method of using JNI in studio, but mostly before 1.1, did not directly support JNI at that time, so it was necessary to add support by adding a task to gradle. And now, all this is not a thing!!!

Add Lib Library

Switch to the Project tab and copy the jar package directly to the Libs directory and add the dependency.

Add So Library

There are two ways to add an so library. but it is highly recommended to use a simple and rude way.

Simple Rough

In the main directory right click, add folder, named jnilibs, you need to note that a word can not be wrong, this is the default name.

Custom Catalog

Under Main you can customize a directory, for example: XYs. Then, under Build.gradle's Android tab, add the following modifications:

sourceSets {        main {            jniLibs.srcDirs = [‘xys‘]        }    }

Specify a specific directory for the next jnilibs.

Use

In the code, you only need to:

static {        System.loadLibrary("XXXX");    }

and specify the method that corresponds to the native:

publicstaticnativevoidnativeXXXXX();

These should not be talked about.

Warning

There are several places to be aware of when using JNI.

Package Name

In the LoadLibrary program, the package name must be the same as the package name of so library.

So library version

Under Jnilibs, it is best to place:

It's best to have a few versions, but in fact, it's enough to put a armeabi-v7a. But when things go wrong, be sure to go to this place and think.

Android Studio uses JNI, so libraries

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.