In the previous article we contacted CMake, which wrote about the use of ndk-build. Just use it and think about where to write it.
Environmental background
Android Development IDE Version: Androidstudio 2.2 or higher (currently upgraded to 2.2.3)
Computer environment: Window 64-bit system
Creation and setup of Demo Project 1. Create a new project and create a new JNI folder under the App/src/main path.
2. In Java code, create a new Ndkbuildtest class (containing the native method) and use the Javah command to generate the header file.
Here are a few things to note:
(1) Javah is a program in the JDK, so you need to add the bin path of the JDK to your computer's environment variable path in order to use this command in terminal.
(2) Javah command,-d specifies the path to create the header file,-classpath specifies the path of the class, and because the current path is main, specify Java in it.
The effect is as follows:
3. Create a new C file to implement the native method
4. Create a new Android.mk file under the JNI path
5. Ndk-build configuration in the Build.gradle of Module (APP)
Here are the main configuration two points:
(1) In the Defaultconfig node, add the NDK, where an ABI filter is made (the default ABI appears to be MIPS)
(2) in the Android node, add the Externalnativebuild node and configure the Ndkbuild makefile path inside. (with CMake, it is also configured here)
6. After the configuration is complete, synchronous engineering, programming in the C file, you can introduce the corresponding header files, and there will be corresponding code hints.
Note: After the general synchronization project, the editor can find the corresponding header file, will not be marked red error.
Of course, even if the red error, the hint to find the end of the file, as long as the compile can build Success, the project can be normal operation.
Other 1.Google developers China website
Just yesterday, Google developers China website opened, hi-Big Ben ~~23333~~
Its public number is Google developer
2. About ANDROID.MK
About android.mk writing, Androidstudio seems to be unable to automatically generate, has always been manual coding.
Yesterday just found a website about android.mk, first record, another day to study.
Here are some of the lessons you'll have to use this time:
(1) If there are multiple folders, a android.mk file is required to include all subfolders under the Android.mk file:
This file is a file that is configured in Build.gradle.
(2) If you need to link a non-system so library (a library that is not found in the Android system) in the project, pre-compile the library in android.mk and then link the library in the module that you currently need to generate:
This way, in the generated apk, you can see that both the libready.so and the currently generated libcurrent.so are packaged in the Libs path.
NDK notes (ii)-using Ndk-build in Android Studio