Solution 1 :
It’s enough to build your library with an NDK toolchain. Usually it’s OK to use the lowest platform API level supported by NDK. You should produce the binaries for different CPUs. You may skip the 32-bit variants if you wish, but the rules of Android Play Store require that you have a 64-bit version. You don’t need Android Studio for this task, and no changes to your sources are necessary.
If your library exports C++ API, use c++_shared runtime.
Problem :
I’m primarily a C developer who has been tasked with building some C libraries into shared object files that can be built into an Android app. I came across this link which discusses how to add a prebuilt library to an Android Studio project, but very little information on how to actually build a prebuilt library. I did find information saying I can’t just use Linux cross-compilers to do so due to slight differences in ABI. How would I go about doing this? Do I need to use Android Studio? Do my sources need to include some special header? Or can I just use the cross compilers found in the NDK and compile using gcc -shared -fPIC
?
Comments
Comment posted by developer.android.com/studio/projects/add-native-code
Prebuilts is for when you already have an existing .so or .a file that has been built with the NDK, which you don’t. You should be looking at
Comment posted by jaltair9
That link seems to talk about adding the native code to a Studio project. What I’m trying to do is prebuild the native code so some other team (who shouldn’t be able to see my source code) can add it to a project.
Comment posted by jaltair9
So I don’t need to do anything with JNI headers, and the JNIEXPORT macro? If I just straight up compile a so file using the NDK cross-compilers, how would I call its functions from Java?
Comment posted by The Salami Method
To communicate with Java/Kotlin, you need the appropriate API. You can add it manually with JNI, or with the help of JNA or SWIG or whatnot. To keep your development process clean, you may choose to separate the JNI wrapper from the core library, see