https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
k

Kris Wong

10/09/2019, 3:27 PM
has anyone had issues with this:
apply(plugin = "com.android.library")
in build scripts written in Kotlin DSL?
it doesn't recognize
android
a

alex009

10/09/2019, 3:43 PM
https://github.com/icerockdev/moko-template here project with kotlin-dsl, multiplatform, android, ios, multi-module...maybe this help you
k

Kris Wong

10/09/2019, 3:49 PM
it's a nice template. was hoping to avoid this whole buildSrc concept
a

alex009

10/09/2019, 3:55 PM
what in buildSrc should be avoided on your opinion?
k

Kris Wong

10/09/2019, 4:05 PM
I don't want to spend the effort to migrate to that right now
a

alex009

10/09/2019, 5:31 PM
buildsrc in template contains only dependencies definition with versions
k

Kris Wong

10/09/2019, 5:34 PM
I can't get my plugins to apply correctly, and the few examples I am seeing seem to use the buildSrc mechanism
l

louiscad

10/09/2019, 7:34 PM
You need to use the plugins DSL:
Copy code
plugins {
    id("com.android.library") // that
    kotlin("multiplatform") // after all, you posted in MPP channel
    `maven-publish` // If you want
}
k

Kris Wong

10/09/2019, 7:46 PM
that isn't enough as is. it doesn't know what
com.android.library
is
l

louiscad

10/09/2019, 7:54 PM
@Kris Wong It's not published on gradle plugins portal so you need to add a
classpath
dependency in the `buildscript`'s root project, as usual in Android projects.
k

Kris Wong

10/09/2019, 7:55 PM
still not enough. I had to add a condition in the pluginManagement block in the settings.gradle.kts
but the IDE was still showing errors on the whole android block even in that case, which broke code navigation
and I ain't got time for that right now 😛
l

louiscad

10/09/2019, 8:00 PM
In #splitties, it works perfectly. All modules support android (or jvm for a few of them), and the preferences module (on develop branch) supports macOS and iOS too.
k

Kris Wong

10/09/2019, 8:06 PM
dunno, it doesn't work in my project
Copy code
buildscript {
    extra["iosFrameworkName"] = "FeatureModule"

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.5.1")
        classpath("org.jfrog.buildinfo:build-info-extractor-gradle:4.9.10")
    }
}

plugins {
    kotlin("multiplatform")
    id("com.android.library")
    id("maven-publish")
}
* What went wrong: Plugin [id: 'com.android.library'] was not found in any of the following sources: - Gradle Core Plugins (plugin is not in 'org.gradle' namespace) - Plugin Repositories (plugin dependency must include a version number for this source)
I have the same issue with other plugins as well
l

louiscad

10/09/2019, 8:45 PM
Try adding
allprojects { repositories { google() } }
in root project's build file
k

Kris Wong

10/09/2019, 8:48 PM
there's only one build file. it has
google()
in both repositories blocks.
a

alex009

10/10/2019, 1:56 AM
in moko-template android.library plugin already in classpath because included as dependency in buildSrc. but here sample without it: https://github.com/icerockdev/moko-core/blob/cc196f1abc12aaea2fd81ffcb5ff289aa6378926/buildSrc/src/main/kotlin/Deps.kt#L32
k

Kris Wong

10/10/2019, 1:02 PM
yeah it's not awesome to have to map out every plugin in another build script file when Groovy
apply plugin
works like a charm
but thanks for all the info
5 Views