Basic process of eclipse NDK development

Create Android project - > complete the preparation of Java functions, add JNI interface functions (native functions) - > Add JNI folder, add android.mk file and source file -- > implement interface functions in source file -- > translate source files into lib library with NDK build -- > start Android simulator, install and run the project.

1. Open eclipse and add an Android project. The name of the project is idettest, and then fill in the activity name (idetest) and java package (COM. Test. Idetest) according to the prompts. Note that it is best not to have an underscore in the name of the java package, which may fail in subsequent JNI calls, because the format of the JNI interface function is Java_. The name of the java package_ Activity name_ Declared function

2. Complete the preparation of Java code, and introduce NDK cross compiled calls into the classes requiring JNI calls:

}

At the same time, declare the native function in the class (created in the C file and cross compiled with NDK)

public native String generateID(String label);

The complete java file is as follows:

}

3. Add a folder named JNI in the idetest project. In the JNI folder, add the implementation file of C module (. File project of C and. H) and android.mk file

C module file (idetest. C)

#include <string.h>

Android.mk file

4. Compile the source code as a library file.

Enter project directory

root@XXX -laptop:~/IDETest# ls

The compiled library file is right here.

5. Start the Android simulator to run the project.

Reproduced at: https://www.cnblogs.com/imagelab/archive/2011/08/20/2147023.html

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>