Hi all! I’m trying to make a multiplatform librar...
# multiplatform
a
Hi all! I’m trying to make a multiplatform library which is pure Kotlin (aka no platform-specific code), exported for Android too. To be honest, it is a JVM-pure library so it doesn’t even need to have an Android platform per-se, the problem is if I don’t add it, if I then add it as a dependency for a mpp project that has also Android, it won’t automatically add the jvm dependency to the Android project, at the end not compiling at all
I have added the
com.android.library
plugin, but something clashes, since it throws a
Copy code
A problem occurred configuring project ':projectname'.
> The 'java' plugin has been applied, but it is not compatible with the Android plugins.
j
a KMP library which has no android and has jvm will use the jvm in the android consumer
a
does it? Okay I need to double-check then, since when I tried to add it to the project, it was not building
j
it should, if you get red imports, check via terminal if it is compiling
a
no, more than red imports it was actual gradle errors, but let me try again, just in case it wasn’t exported properly to mavenLocal (using that to try it locally)
yeah it literally gives me:
Copy code
Failed to resolve: group:library:0.1.0
Show in Project Structure dialog
Affected Modules: androidApp, androidWatchApp
and as you can see the only modules affected are the android ones
j
it is weird, it should work, for example you can use turbine in android modules and it doesn’t have android target https://github.com/cashapp/turbine/blob/trunk/build.gradle
a
Turbine is a testing library that also runs on junit tests which are jvm and not android from the consuming app
a
^ yeah that makes sense, it may work just because it at the end runs directly on jvm. Although, it is weird if there’s no way to tell the android module to use the jvm library
j
there are tons of libraries working on android without declaring android and only jvm, turbine is one, apollo is another
even probably the stdlib is not declaring android
a
Why can’t you just directly add the -jvm artifact to the android dsl ?
I guess it is cumbersome
j
koin core is another
a
it says weirdly that is failing to resolve
but again, I’ve got a JVM target in the same MPP project and that works fine
so the jvm artifact is definitely exposed
j
share the whole stacktrace
a
I’ll try getting the stack trace, but I’ve just realised that is just a warning, and the compilation still succeeds… even weirder
e
this may be a weird problem with
mavenLocal()
- I've seen Gradle module metadata not work correctly with it
s
Maybe we can look into this? Is your project public?
a
Unfortunately is not public yet (I’m building it under my company and we’ll open source it later), but it seems the issue is caused by the dependency getting for some reason exported transitively to each and every of the targets, when instead I want it to be only used by the common code. What I mean:
Copy code
mppLibrary [android,jvm,native...] -> sharedModule [android,jvm,native...] -> individualApp
it seems
individualApp
, in this case Android, is adding
mppLibrary
as a dependency from
sharedModule
, which it shouldn’t since I am using an
implement
definition instead than an
api
one
is there any way to avoid that to happen?
s
I could offer help, if you create a sample project that we can both look at 👍