Android Studio uses the jni and so libraries and androidjni

Source: Internet
Author: User

Android Studio uses the jni and so libraries and androidjni
Android Studio uses the jni and so Libraries

After Android Studio1.1, AS has already supported the jni and so libraries. The official version 1.3 is now released. It can compile c and c ++ in the clion environment, it is more convenient to use NDK for development. There are many examples on the Internet that use jni in Android Studio, but most of them were earlier than 1.1. At that time, jni was not directly supported, therefore, you need to add support by adding tasks to gradle. Now, this is not a thing !!!

Add lib Library

Switch to the project tag, copy the jar package to the libs directory, and add the dependency.

Add so Library

There are two methods to add the so library.However, we strongly recommend that you use a simple and crude method.

Simple and crude

Right-click the main directory and add a folder namedJniLibsNote that a word cannot be wrong. This is the default name.

Custom directory

In main, you can customize a directory, for example, xys. Add the following changes under the Android tag of build. gradle:

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

Specify the directory of jniLibs.

Use

In the code, you only need:

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

And specify the native method:

public static native void nativeXXXXX();

This should be skipped.

Warning

When using jni, there are several points worth attention.

Package name

The program in loadLibrary, package nameMust be the same as the so library package name.

So library version

In jniLibs, it is best to place:

It's best to have a few of these versions, but in fact, it's enough to put a armeabi-v7a. But when an error occurs, you must think about it in this place.

Related Article

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.