jean

    jean

    2 years ago
    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
    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()
    ?
    gildor

    gildor

    2 years ago
    Have you add android gradle plugin to build script dependencies?
    jean

    jean

    2 years ago
    I’ve added this
    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
    louiscad

    louiscad

    2 years ago
    Is the snippet you've shown in the root project's
    build.gradle[.kts]
    file?
    jean

    jean

    2 years ago
    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
    louiscad

    louiscad

    2 years ago
    I don't think it is possible, you most likely need to have a subproject for the android library.
    jean

    jean

    2 years ago
    ok so that would mean the mpp project only use the
    jvm()
    target and my android project using the shared code should declare a
    kotlin {
        android { ... }
    }
    ?
    louiscad

    louiscad

    2 years ago
    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.
    jean

    jean

    2 years ago
    I’ll keep that in mind, thanks!
    louiscad

    louiscad

    2 years ago
    Haha, you figured it doesn't explain the
    jvm("android")
    thing 😄
    jean

    jean

    2 years ago
    yeah no, I guess they could actually use it since their shared code module is inside the android project 🤷‍♂️
    louiscad

    louiscad

    2 years ago
    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
    Kris Wong

    Kris Wong

    2 years ago
    use an android target if you need to do any Android things, like use the Android SDK or configure flavors
    otherwise use JVM