1. Home > programming >

Androidstudio3.4 configure the basic tutorial of Android-jni development

First download and configure android studio ndk

1. Open sdkManager to download CMake and LLDB

2. Configure ndk

New project

After the project is created, the project directory is as follows, and the cpp folder is automatically generated by the system

3. Custom navite method

Next, start writing a custom native method , Create a new Hello.java file, and write a native method of add summation in it, as follows

Generate C++ header file

Then enter the directory where hello.java is located in the Windows console Terminal and execute javac hello.java, as follows

< p >

The same level directory of hello.java after execution A Hello.class file will be generated below to prove that this step is successful!

Then it is still under Terminal control Go back to the directory above the console and execute the command under app/src/main

javah -d jni -classpath ./java com.example.myapplication.hello, followed by the package name + The file name does not have a suffix, please change to your own package name, as shown in the figure

After the command is executed, a jni folder will be generated under the app/src/main directory, and there is a .h suffix file under the folder, as shown in the figure:

Create a new cpp file to implement the navtive method

put

 com_example_myapplication_hello.h

This article is published by www.internetweblist.com and does not represent the position of www.internetweblist.com/:http://www.internetweblist.com/programming/82406.html

Contact Us

Online consultation:click here to give a message