I have a KMP library using JNI as a wrapper for a ...
# multiplatform
s
I have a KMP library using JNI as a wrapper for a C library in android (cinterop on other platforms). I'm trying to convert to AGP 9.0.0-rc01 and the new
com.android.kotlin.multiplatform.library
plugin. It deprecates the old android block from
com.android.library
, which had the externalNativeBuild/cmake and defaultConfig/externalNativeBuild/cmake clauses that now need to be converted. The doc page for the new plugin doesn't go into detail for how to do this. Does anyone know of detailed doc or an example project that shows what the new plugin needs for specifying stuff like the NDK version, cmake version, cmake environment vars definition, etc? Or is some other approach intended, like no more JNI, just cinterop, or what? The text below from the KMP library plugin page is too vague for me - I'm unsure what it is telling me to do.
Copy code
Native build support

The new plugin focuses on producing a standard AAR for the Android target. Native code integration in Kotlin Multiplatform is handled directly by KMP's own native targets (such as androidNativeArm64 and androidNativeX86) and its C-interop capabilities. If you need to include native C/C++ code, you should define it as part of a common or native source set and configure the C-interop within the kotlin block, rather than using the Android-specific externalNativeBuild mechanism.

Alternatively, if you need native build support, then our recommendation is to create a separate standalone com.android.library where you can integrate the native code and consume the standalone library from your Kotlin Multiplatform library project.
This kind of sounds like I need to cinterop to the JNI wrapper code (C++) I have, but am unsure if that's correct. Thanks in advance for any info.
j
The recommendation is to move that code to a normal Android library module and then depend on it from your Android variant in the multiplatform module.
s
Hmm, so if the 'normal' new android library module still uses the deprecated com.android.library with the NDK stuff (just no kotlin multiplatform plugin), what's the path forward for that module when the deprecated plugin becomes dead 🙂 ? Is it only deprecated for use with the KMP plugin? The issue you linked sounds like google doesn't want to fix this, although I see it is still in assigned state. Since my project is already a KMP library, it seems easier to just leave it using the deprecated com.android.library stuff for the android targets and see what happens. Unless of course I'm missing something. Thanks for the info!!
j
The library plugin is not deprecated
Using it with KMP in the same module is deprecated
s
Ok cool, thanks. Guess it's time to start rearranging. Thanks again for the quick responses!
137 Views