I'm trying to port a snippet to make natives load ...
# gradle
m
I'm trying to port a snippet to make natives load on android: https://github.com/bytedeco/javacv/issues/1117#issuecomment-982336622 However, since this is a multiplatform project, I'm having trouble with
val javacpp by configurations.creating
not being a valid configuration in the androidMain sourceset dependencies. How would I solve this?
v
What do you mean by "not a valid configuration"? That line is creating a new configuration.
m
yes, but it seems calling
javacpp("...")
in a multiplatform dependencies block doesn't work: The reason being that DependencyHandlerScope (non-multiplatform) defines
Copy code
public final operator fun org.gradle.api.artifacts.Configuration.invoke(dependencyNotation: kotlin.Any): org.gradle.api.artifacts.Dependency? { /* compiled code */ }
but there is no such equivalent on KotlinDependencyHandler (multiplatform)
Unfortunately this leaves me confused as to how to deal with bundling natives for android only, as there don't seem to be many docs on adding external natives from jar dependencies
v
Ah, I see. Yeah the KMP dependencies block is different from the normal dependencies block. There it of course does not work. It only provides fixed accessors that are named the same for all source sets, but are actually different ones. You of course cannot access / modify your configuration there, as it does not belong to that source set. Just declare your dependencies for it in the normal dependencies block.
m
But then how do I set up the task dealing with the native libraries for android?
v
What is "the task dealing with the native libraries"?
m
The
javacppExtract
task in the linked github comment, dealing with relocating the natives for android bundles
v
Besides that this task is full of bad practice, I'm not sure what your question is. Why should the task be different? You probably only change the linke where you set the directory and maybe the dependsOn, so that it fits your KMP use-case. As I'm neither into Android nor KMP, I cannot tell you how exactly though.
But the configuration and the task will probably be the same rape, just wired to something else.