1. Create a new JNI directory in the src/main/directory first
2, here to steal a lazy, directly from other projects to copy Android.mk,application.mk,demo.cpp to the JNI directory
in the application.mk file, configure the following:
App_abi: = Armeabi armeabi-v7a arm64-v8a x86 x86_64 MIPS MIPS64
App_platform: = android-7
3, in the local.properties file configuration: ndk.dir=d\:\\android\\androidstudio\\ndk\\android-ndk-r10e
4, in the Build.gradle file in the Android node Defaultconfig The following configurations are configured in the node:
Android { compilesdkversion buildtoolsversion "22.0.1" defaultconfig { ApplicationID " Com.ycy.ndkdemo " minsdkversion targetsdkversion 1 versionname" 1.0 " NDK { ModuleName "demo" ldlibs "log", "Z", "M" abifilters "Armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86 _64 "," MIPS "," Mips64 "}} }
5, through the above configuration basic OK, and then can be called in Java.
PS: This method calls native through C + + source code, and the resulting. So file is generated after the final compilation in App\build\intermediates\ndk\debug\lib
=================================================================================================
The second way to call C + + is described next
1, this method is on the basis of so library, directly on each CPU platform on the so library files in the src/main/jnilibs directory (new jnilibs directory)
2. Configure in the Android node in the Build.gradle file:
Sourcesets { main {java.srcdirs = [' Src/main/java ', ' Src/main/jnilibs '} }
through the above configuration basic OK, and then you can call it heartily.
Finally, the two methods can only choose one, can not be used together, otherwise it will conflict.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Studio for NDK development