On the development of NDK in Android studio

Source: Internet
Author: User

On the development of NDK in Android studio
    1. Environment configuration
      1) Download NDK
      2) Configure the NDK path in Android studio

      3) configuration Gradle
      Add Android.usedeprecatedndk=true configuration to the gradle.properties to open the NDK
      In the development process we will sometimes use C + + to the STL library then we need to add in the Build.gradle
      Defaultconfig {
      NDK {
      ModuleName "Jnitest"
      STL "Stlport_static"
      Abifilters "Armeabi", "armeabi-v7a", "x86"
      }
      }
      Because Android.mk files in Android Studio are not configurable. Instead, the Android.mk file is automatically generated based on the configuration in Gradle
    2. New Project
      Right-click in the project catalog main to create a new JNI folder, which is then used in this folder
      Create a new class under the Java folder under the main folder for example: Jniutils
      and add code public static native String Getstringfromjni ();
      Then make the module, the purpose is to compile the corresponding class file. Then, based on the generated class file, the corresponding. h header file is generated using Javah.
      Click on the Terminal tab of Android Studio and go to the project's app folder by default. If you enter CD Src/main in this directory, switch to the main directory.
      javah-d JNI com.vvgool.jni.JniUtils (-D generates a JNI directory and generates it in the directory even if the JNI directory is not manually generated in case of using-D)
/* Don't EDIT this file-it are machine generated * /#include <jni.h>/ * Header for class com_vvgool_jnitest_jniutils * /#ifndef _included_com_vvgool_jnitest_jniutils#define _included_com_vvgool_jnitest_jniutils#ifdef __cplusplusextern"C"{#endif/* * class:com_vvgool_jnitest_jniutils * METHOD:GETSTRINGFROMJNI * Signature: () ljava/lang/string; */Jniexport jstringJnicallJava_com_vvgool_jnitest_jniutils_getstringfromjni (jnienv *, jclass);#ifdef __cplusplus}#endif#endif

Then we can create a new. cpp file or a. c file in the Jni file. I'm here to create a new file to Test.cpp.

Finally added in the Jniutils
static{
System.loadlibrary ("Jnitest");
The Jniutils.getstringfromjni () method is called in the activity to get the string.

On the development of NDK 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.