Android NDK development steps, androidndk
NDK development is generally divided into the following steps: (you have installed the NDK and android development environments by default)
1. Create a project
2. Create a JNI directory
3. Compile the nativejava Layer Method
4. Generate the JNI header file
(1) Compile javaNative code
(2) run the javah command.
(3) Add the android. jar package to the Environment Variable
5. Create a. c file to import the corresponding header file
6. Add the mk file in the jni directory.
7. Finally, run the ndk-build command in the project path.
8. Run the code to view the result.
The following are detailed steps and:
Create an android project.
Then we declare an native method.
Next we will add a jni directory under the project.
Then go to the cmd console to enter the current working directory:
Then run the javah command to generate a. h file.
(Where, D: \ android \ android_sdk_windows \ platforms \ android-19 \ android. jar,
Is the directory file under the android sdk directory. To make it simple, you can add the android. jar file directory to the path;
Com. example. hellondk_1.MainActivity is the package name and class name)
Refresh the project and you can see that there is an additional. h file under the jni directory.
Then we create a. c file to implement the. h file definition method.
Create a. c file and import the corresponding header file
(
For example, create a hello. c file.
# Include <stdio. h>
# Include <stdlib. h>
# Include "com_example_hellondk_1_MainActivity.h"
JNIEXPORT jstring JNICALL Java_com_example_hellondk_11_MainActivity_getStringFromC
(JNIEnv * env, jclass ){
Return (* env)-> NewStringUTF (env, "Hello from C !.... ");
}
The method Java_com_example_hellondk_11_MainActivity_getStringFromC (JNIEnv *, jclass) in the header file is implemented );
)
Add the mk file in the jni directory.
(You can import the mk file under the ndk instance and modify it .)
LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS)
LOCAL_MODULE: = hello
LOCAL_SRC_FILES: = hello. c
Include $ (BUILD_SHARED_LIBRARY)
Where,
LOCAL_MODULE indicates the name of The so generated by compilation.
LOCAL_SRC_FILES indicates the. c file to be compiled
Finally, run the ndk-build command in the project path.
After the execution, refresh the project. You can see that there is an additional. so file in the obj directory under the project.
Then add a static code block to the java file. Add the. so file.
Finally, you can see the result by running the code.
If you are using the genymotion simulator, You need to configure genymotion to install a genymotion arm translation. After downloading it, drag and drop it to install it.
:
Http://download.csdn.net/detail/u014132820/9044875