I have a KMP project (jvm + android) using several gradle modules. If one of these modules has only commonMain source code, should I still add all targets (
) in its build.gradle?
10/11/2023, 8:17 PM
Depends. If it is only jvm and android, you should see if that module needs Android at all.
Does it consume KMP modules or libraries that have both Android and JVM.
If it can built without any Android dependencies, I would probably keep that module as JVM only and not use the KMP plugin. It will build faster and Android modules can consume JVM modules.
But you need to list all targets that you want to build for even if you don't need specific code for that platform.
10/11/2023, 8:21 PM
It's using KMP libraries. I can build it using the KMP Gradle plugin and only the jvm target, and it runs on Android too. So it seems to work alright but it feels a little weird.
P.S. by "it runs on Android" I mean that I can include this jvm-target-only module into another module that is a proper android application
10/11/2023, 8:38 PM
Might work because if the other KMP JVM libraries work on Android, or it could be that the app is picking the Android dependencies at runtime and the compile time differences do matter.
10/11/2023, 9:37 PM
It works the same way when your Android project consumes java pure code, F.E a jar. If your module doesn't use any specific Android API, is ok just target jvm. And it can still be consumed by other module that targets Android.