So you have a bunch of questions. Some of these questions are related to the type of personal preference, but I will provide them as my personal choice.
1
This is your choice. I would personally use a compiled .so file. That way, I never have to worry about NDK, CMake, and .mk files. If you have a file, all you have to do is add the file to the libs (not lib ) folder and make minor changes to your build.gradle file. What is it.
Change to build.gradle:
sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] jniLibs.srcDirs = ['libs'] } }
2 and 3
This does not apply to this option.
4
You would need to do something like this, regardless of whether you use files or compiled libraries:
@SuppressWarnings("JniMissingFunction") public class MyNativeMethods { static { System.loadLibrary("my_native_lib"); } public native int native_method_1(int fd); public native int native_method_2(int fd); public native void native_method_3(int fd, int arr[]); public native int[] native_method_4(int fd); }
And then you can call these methods from your Activity / Fragment .
Hope this is clear enough.
EDIT (based on comment below) :
1) .so or .a files are your native libraries.
2) .cpp , .c files, etc. - these are just your source files. If you intend to use these files in a project, you will have to use a build system (e.g. CMake) to use them. CMake will take the source code files and create the .so library, which will again become the native library. That's why I suggested using .so files, because why do I need to work with CMake in your project when you don't need it?
If you want to try CMake or find out in the future, check this answer: C / C ++ with Android Studio version 2.2
3) System.loadLibrary("my_native_lib"); : Here you specify the Java runtime to add this library. This way you create a connection between Java and the C ++ code that is inside the library. The methods below this line should have the same name as in C ++ / C code. Thus, the Java runtime will find and open the library and search for this method in the loadable library. More here