the hands-on tutorial use `jvm("android")` for tar...
# multiplatform
j
the hands-on tutorial use
jvm("android")
for targeting android but I’m reading in the doc that one could also use
android { ... }
. Is the
android
shortcut useful only to be able to configure build variants, dependencies, etc… ? The doc says also
id("com.android.library")
is necessary but gradle can’t resolve it
Copy code
Plugin [id: 'com.android.library'] was not found in any of the following sources:
(and then nothing, it does not say any sources). What if I want to target android and desktop through the jvm? should I just use
jvm()
?
g
Have you add android gradle plugin to build script dependencies?
j
I’ve added this
Copy code
buildscript {
    repositories {
        mavenCentral()
        google()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.1.0-beta03")
    }
}
which makes
apply(plugin = "com.android.library")
works but still not for
id("com.android.library")
in the
plugins
bracket
l
Is the snippet you've shown in the root project's
build.gradle[.kts]
file?
j
yep
I guess it should since I want to be able to use the plugin in the root gradle file to be able to use
android()
target
l
I don't think it is possible, you most likely need to have a subproject for the android library.
j
ok so that would mean the mpp project only use the
jvm()
target and my android project using the shared code should declare a
Copy code
kotlin {
    android { ... }
}
?
l
FYI, if you want to share code between Android and JVM, it's currently best to make a plain Kotlin/JVM library module, and ensure the java APIs you use are available on Android (avoid desktop specific APIs). Then, in the desktop or android specific library/app module, you can use the platform specific APIs, and implement some interfaces if needed using these platform APIs.
☝️ 1
👌 1
j
I’ll keep that in mind, thanks!
l
Haha, you figured it doesn't explain the
jvm("android")
thing 😄
j
yeah no, I guess they could actually use it since their shared code module is inside the android project 🤷‍♂️
l
I think it was easier to test jvm support and fix any issues than android support which they don't control directly, and is more complicated on several levels. I'm hopeful this will improve, especially with 1.4 and 1.4.20
k
use an android target if you need to do any Android things, like use the Android SDK or configure flavors
otherwise use JVM