When I wrote the native program in studio today, I found that version 2.2 introduced a External build to build the native project.
The most intuitive performance is that the source code files of C + + is not in a project folder with Java files. And with the previous configuration in the Gradle, and then automatically generated makefile compared to the flexibility greatly increased, no longer have to look for the egg makefile corresponding Gradle statement.
Here's how to use it:
C + + code can be organized in any folder with Android.mk and Application.mk
For example, my file structure is:
---hook---android.mk---application.mk---hook_d------android.mk--- ---main.c---hook_so------android.mk------MAIN.C
Create a new JNI folder in Sudio, which appears as a CPP folder in Android view mode
Right-click to select Link C + + Project with Gradle
Builde system has CMake and ndk-build optional, if you use the Ndk-build option, select the top native file of Android.mk project
After import, the effect is as follows
Finally, I'll mention one of the projects that I just learned. How to compile multiple so files
---hook---android.mk---application.mk---hook_d------ ANDROID.MK------MAIN.C---hook_so------android.mk------main.c
Take the file structure above as an example
Hook/androi.mk
Include $ (call All-subdir-makefiles)
Hook/hook_d/android.mk
Local_path: = $ (call my-dir+ =-pie- fpie+ =-pie-fpie-llogtarget_platform:= android- local_module:= hook_dlocal_src_files:= main.cinclude $ (build_executable)
Hook/hook_so/android.mk
Local_path: = $ (call my-dir) include $ (clear_vars) Arget_platform:= android- Local_module:= hook_solocal_src_files:= main.cinclude $ (build_shared_library)
The principle is all-subdir-makefiles This macro will return the path of all android.mk files under the folder
Android Studio 2.2 External Build