Nikita Khlebushkin
11/18/2020, 10:15 PMmobile-shared [SharedLogic]
|____ ModuleShared
|____ TestAndroidApp
|____ TestIosApp
I can build and compile KMM library, assemble .jar, Cocoapods - no problem here.
Lately I've been trying to add this project as a module dependency to an Android project, which used to have the following structure:
MyApp
|____ app
and now has the following structure:
MyApp
|____ app
|____ mobile-shared [SharedLogic]
|____|____ ModuleShared
|____|____ TestAndroidApp
|____|____ TestIosApp
How I was trying to do it:
Option 1:
MyApp/settings.gradle.kts:
pluginManagement {
repositories {
gradlePluginPortal()
google()
jcenter()
mavenCentral()
}
resolutionStrategy {
eachPlugin {
if (requested.id.namespace == "com.android" || requested.id.name == "kotlin-android-extensions") {
useModule("com.android.tools.build:gradle:4.0.1")
}
}
}
}
include(":app")
include(":SharedLogic")
project(":SharedLogic").projectDir = File("mobile-shared")
include(":SharedLogic:ModuleShared")
MyApp/app/build.gradle.kts:
...
android {
dependencies {
implementation(project(":SharedLogic:ModuleShared"))
Option 2:
MyApp/settings.gradle.kts:
pluginManagement {
repositories {
gradlePluginPortal()
google()
jcenter()
mavenCentral()
}
resolutionStrategy {
eachPlugin {
if (requested.id.namespace == "com.android" || requested.id.name == "kotlin-android-extensions") {
useModule("com.android.tools.build:gradle:4.0.1")
}
}
}
}
include(":app")
include(":ModuleShared")
project(":ModuleShared").projectDir = File("mobile-shared/ModuleShared")
MyApp/app/build.gradle.kts:
...
android {
dependencies {
implementation(project(":ModuleShared"))
Error I encounter:
A problem occurred configuring project ':SharedLogic:ModuleShared'.
* Where:
Build file '/home/xlebnick/projects/MyApp/mobile-shared/ModuleShared/build.gradle.kts' line: 40
* What went wrong:
This version of the kotlin-serialization Gradle plugin is built for a newer Kotlin version. Please use an older version of kotlin-serialization or upgrade the Kotlin Gradle plugin version to make them match.
In ModuleShared/build.gradle.kts:
plugins {
kotlin("plugin.serialization") version "1.4.10"
}
In mobile-shared/build.gradle.kts:
buildscript {
repositories {
gradlePluginPortal()
jcenter()
google()
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10")
classpath("com.android.tools.build:gradle:4.1.0")
}
}
And in MyApp/build.gradle.kts:
uildscript {
apply(from = "versions.gradle.kts")
val kotlinVersion: String by extra // 1.4.10
val rootClasspath: List<String> by extra
repositories {
mavenCentral()
google()
jcenter()
maven("<https://plugins.gradle.org/m2/>")
maven("<https://maven.fabric.io/public>")
}
dependencies {
classpath(kotlin("gradle-plugin", version = kotlinVersion))
for (rc in rootClasspath) {
classpath(rc)
}
}
}
What am I doing wrong?
P.S. Found this issue, but it doesn't help at all