Hi I've been struggling to fix a bug for the last ...
# multiplatform
a
Hi I've been struggling to fix a bug for the last 2 weeks. In a KMP project with a modular architecture, module
B
depends on module
A
. Module
A
has some code inside its
commonMain
that module
B
can access, because it depends on
A
. The thing is, the code inside module
A
can be accessed by any
sourceSet
of module
B
, EXCEPT from
androidMain
!!! I can even access the code written in
A
from `B`'s
jvmMain
, but not
androidMain
. When I try to do so, Android Studio (The latest stable version), says:
Unresolved reference: {NameOfTheClass}
---
Add dependency on module '{NameOfMyProject}.A.commonMain'
I don't exactly know when the problem has occurred, but I guess it was after updating the version of some dependencies (especially kotlin 1.6.10 to 1.6.21). I tried changing the versions again and cleaning the project every time; I tried invalidating the caches, I even migrated from a Linux based system to Windows; nothing worked. Some of the current versions:
Copy code
Android build tools: 33.0.0
app compat: 1.4.2
Kotlin: 1.6.21
coroutines: 1.6.2
Kotlinx Datetime: 0.3.2
Kotlinx Serialization: 1.3.3
core ktx: 1.8.0
activity compose: 1.5.0-rc01
coil: 2.1.0
koin: 3.2.0
jvm targets: 11
compose: 1.1.1
Android gradle: 7.2.1
Kotest: 5.3.0
moko resources: 0.20.1
ktor: 2.0.2
...
UPDATE: When I downgraded android gradle to 7.1.3, the app successfully compiles and I can run it inside the emulator. However, the IDE still shows the Unresolved dependency error, even though it compiles! How to fix this? UPDATE: Downgrading the android gradle plugin to
7.1.3
and adding:
kotlin.mpp.hieraricalStructureSupport=false
solved the issue, BUT, made the jb compose not work in `commonMain`s.
e
likely due to Kotlin enabled HMPP by default between those versions. If that's the issue, Gradle build will work fine and IntelliJ should be ok too, it's just a problem in AS. https://issuetracker.google.com/issues/234309878
a
@ephemient Thanks for the answer, there's an update to the question. It's a bug from Android Gradle I guess.
kotlin.mpp.hieraricalStructureSupport=false
Solved the issue that rised from the IDE!
e
you need to enable it in your project in order to make use of certain multiplatform libraries published with it. if that leads to your project is broken in AS, ignore those errors and just rely on Gradle builds, or switch to IntelliJ.
👍 1
the "real" errors will be caught by a Gradle build, but yes, the lack of an IDE that has the latest Android and KMP fixes is definitely a pain