I have a project with native C++ code and a JNI wrapper. Works just fine. I have one project/repository that builds and publishes the library for Android using the com.android.library plugin, producing an AAR artifact. I also have another project/repository that does the same thing for server side using the java-library and cpp-library plugins, but producing a Jar file with the native library bundled and then it gets loaded from the Jar. The C++ code is included as a git submodule so that isn’t duplicated but all the other code like the JNI wrapper is. Basically other than the project layout and the build.gradle differences for the plugins there’s no difference. I’d like to combine into one project/repository that can produce and publish either the Android or the server side artifacts depending on what I choose. I’ve tried looking into variations of different flavors or external builds but have not been able to make it work correctly in a combined repository. The main difficulty seems to be the need for the android plugin in order to see the NDK to do cross compilation of the native library since the cpp-plugin does not seem to support the NDK yet. Is there a way to accomplish this without a lot of heavy external build scripts, installations etc? Thanks!
May I ask how is it that you are including the C++ code and JNI wrapper into your AAR artifacts, in the first place?
I’m stuck trying to do that – my resulting AAR file only contains my Java/Kotlin classes, but not the rest of the native layer of my code.
I cannot really resolve your question, but I’d love it if you could do mine!
Thanks
I’m using externalNativeBuild in build.gradle and cmake to drive the C++ compilation and inclusion. You can see the setup in this OSS library:
https://github.com/EOSIO/eosio-java-android-abieos-serialization-provider
Perhaps I worded my question wrong, my library is already using C/C++ libraries with a JNI layer.
My problem is whenever I attempt to pack it all up into an AAR and publish it using the maven-publish
plugin, it only takes the application layer of my library but not the native code.
I posted a question with more details here, if you don’t mind me bothering. I’ll take a look at the project and maybe be able to find what I’m missing by comparing it with my own.
Thanks for your answer!
I’m not publishing at the application layer, which might be the difference. My publish directives are at the eosio-java-android-abieos-serialization-provider layer where the build.gradle utilizes the com.android.library plugin.