Hi. is it possible to use jvm lib in shared if I t...
# amper
g
Hi. is it possible to use jvm lib in shared if I target only jvm and android?
👀 1
I have this amper file
Copy code
product:
  type: lib
  platforms: [jvm, android ]

repositories:
  - <https://jitpack.io>

dependencies:
  - $compose.foundation: exported
  - $compose.material3: exported
  - com.github.shalva97:NewValve:1.5

dependencies@android:
  # Compose integration with Android activities
  - androidx.activity:activity-compose:1.7.2: exported
  - androidx.appcompat:appcompat:1.6.1: exported

settings:
  compose:
    enabled: true
I would expect functions from the lib to show up in shared module.
message has been deleted
k
Could you please show the content of
shared/module.yaml
as well?
g
the above is shared/module.yaml, the root yaml is
Copy code
modules:
  - android-app
  - jvm-app
  - shared
🙏 1
u
Thanks a lot for pointing to the issue! It roots in Amper not handling JVM+Android source sets as somewhat specific and thus only KMP parts of the library are available in it. There should even be a warning (since 0.7.0) about that in the module file, something like "Dependency is not a Kotlin Multiplatform library. It won't be available in multiplatform source sets of the module, but you still can use it in JVM or Android source sets". However, we have filed an issue to loosen that restriction and provide some special treatment for this combination of platforms: AMPER-4474 At the moment, the best workaround that we can suggest is to define expects for the API you need in the common source set and provide actuals with simple delegation. E.g.:
Copy code
// src/lib.kt
expect fun initNewPipe()

// src@jvm/lib.kt
actual fun initNewPipe() = io.github.shalva97.initNewPipe()

// src@android/lib.kt
actual fun initNewPipe() = io.github.shalva97.initNewPipe()
It's enough to mention dependency in the common block of the module file (as you have it now)—it should be available in the platform source sets.
📌 1
👍 1