- Need to download NDK separately
- environment variable configuration, ~/.bash_profile (automatically created if not) enter the above code to configure, exit after executing the source command takes effect
PATH=$PATH:/Users/confiwang/Applications/android-ndk-r11c/ ANDROID_NDK_ROOT=/Users/confiwang/Applications/android-ndk-r11c/ ANDROID_NDK_ROOT
- Create a new project using a blank activity
- Modify Local.properties Add
ndk.dir=/Users/confiwang/Applications/android-ndk-r11c/ android.useDeprecatedNdk=true
- In app module (note not the project root), configure NDK compilation (only ModuleName and platforms are configured here, images can be downloaded for viewing, or zoomed in):
- Create a JNI file, a simple native method add, to calculate the value of two integers added:
- Create a JNI subfolder under the main folder (in parallel with the Java folder, Android will know the underlying code source folder by default)
- Switch to the command line, go to the project's Java directory, execute Java Com.example.confiwang.jni.MathJNI (package name + class name), and copy the generated. h file to the newly created Jin directory, and create the. cpp method to implement this function
- As the JNI and the application layer are in the same project, the direct running system compiles automatically, generating android.mk and corresponding so:! [Write a description of the picture here]
- Write method calls, you can see the output in the log
Android Studio JNI Environment setup