This has probably been answered already in this ch...
# multiplatform
s
This has probably been answered already in this channel but my search-fu has failed me. If I have two kmp submodules: module1 [androidTarget] module2 [jvm target with code only in the common source set] setting this in module1.gradle:
Copy code
sourceSets {
  androidMain {
    dependencies {
      implementation project(":module2")
    }
  }
}
doesn't work out of the box for some reason. the IDE can see the imports from module2 inside module1 and no compilation erros but when i try to build the app i get an
Unresolved Reference
error should this work out of the box (and thus i have made some sort of error in my module configurations) or am i missing something that i need to add to my gradle files?
j
What's the Unresolved Reference about? Does it only happen with that specific file or with everything?
s
the thing that is unresolved is the package of the import i am trying to reference from the android module. i have only seen this one as this is the first module i am attempting to convert to jvm (i had an android only project that i am slowly converting to kmp)
it's open source so you can replicate it yourself. I have the failing code in a branch: https://github.com/savvasdalkitsis/uhuruphotos-android/tree/jvm-module
image.png
p
What you described should work out of the box. When you depend on 1 module, however, I think your
module-2
depends on other modules that are not being loaded into the App
s
this is not a runtime failure note. shouldn't the IDE show the same error that the gradle output shows?
also, my
module-2
is a leaf node. doesn't depend on anything else πŸ˜•
p
Ah I see, and is not a runtime failure? πŸ€”
s
weird right?
p
Yes, I have a project with that same setup and works ok
s
module-2 only has a commonMain source set as well but a jvm target. i had assumed that would work
my project i linked above should take a bit to build but i believe you should be able to replicate it.
i am using a buildSrc plugin to define the jvm and android libraries. i maybe did something silly in that
p
I just checked and I do use Android target but I swear at some point it was only JVM
Sounds like it could be it. The order in which plugin are applied. Or a missing plugin
s
any ideas on how i could troubleshoot that? πŸ˜•
p
I would start by looking for a project that already does that. I have seen a couple on GitHub applying the KMP plugin from buildSrc. Did you applied default herarchy? This article seems good. https://vaibhav3011.medium.com/effortless-multimodule-configuration-for-kotlin-multiplatform-projects-with-gradle-convention-8e6593dff1d9
j
JFYI: I tried to clone your repo but Windows complained about a too long file path. I've not seen one of those since last being forced to use NPM πŸ˜… Changing the root folder to just "uru" made it work, though.
But: immediately after gradle sync, the import turns red for me. Android Studio 2023.1.1P2
s
that's the error i'm trying to troubleshoot πŸ™‚
weird that you see the error in the IDE and i don't though
j
Yes but you said you don't see it in your IDE, right?
s
i only see it when i build
yes. bizzare
j
As said above: this setup should work. I've done exactly the same yesterday evening (making Android module depend on pure JVM module) which is why I'm looking into it as well. Doing a little test.
s
thanks for trying it out πŸ™
j
So here's my little test: I changed [foundationmathapi]'s
build.gradle
file to this
build.gradle.kts
file:
Copy code
plugins {
    kotlin("multiplatform")
}

kotlin {
    jvm()
}
After sync, the red import goes away. Project eventually fails to build because of JitPack's current incident, but it does get past the breaking point. So the issue must be in your convention plugin. I'm no expert in those but at least this should be useful to know that the setup should work.
s
i can try to inline the plugin contents into the build files and see if that fizes it
nope. same error
image.png
image.png
it seems that inlining them fixed the IDE error for you but if you could build you'd probably get the same
i even tried downgrading the android gradle plugin since the multiplatform plugin was giving me a potential compatibility warning but that also didn't fix it πŸ˜•
j
I would only inline the [foundationmathapi] one, that's where the issue is. The consuming one should be okay. It's too bad Jitpack is still having issues (even though their status page says everything's okay again πŸ™„) so I can't show the green build right now
s
i think it might be me applying the java-application plugin too. i removed it now and it looks promising
java-library not application
j
Uhu
s
holy crap that was it 😁
removing the
id 'java-library'
did the trick.
πŸš€ 2
thank you so much for your help πŸ™
πŸ™‚ 1