Hello kotlin community.
I’m using Android Studio Bumblebee 2021.1.1 Patch 2.
I’ve created a kmm project via File->New Project->Kotlin Multiplatform App for Android and iOS.
My project has buildSrc, androidApp, shared, iosApp modules.
- buildSrc module:
here the build.gradle.kts from buildSrc:
plugins {
`kotlin-dsl`
}
repositories {
mavenCentral()
}
And Dependencies.kt from src/main/kotlin:
object Versions {
const val appVersionCode = 1
const val appVersionName = "1.0"
const val appVersionNameSuffix = ""
const val androidMinSdk = 23
const val androidCompileSdk = 31
const val androidTargetSdk = androidCompileSdk
const val buildTool = "31.0.0"
const val kotlin = "1.6.10"
const val kotlinCompilerExtension = "1.1.1"
const val kotlinCoroutines = "1.6.0"
const val ktor = "2.0.0-eap-337"/*"1.6.7"*/
const val koin = /*"3.1.5"*/"3.2.0-beta-1"
const val koinExt = "3.0.2"
const val compose = "1.1.1"
const val navigationCompose = "2.4.1"
const val activityCompose = "1.4.0"
const val sqlDelight = "1.5.3"
const val material = "1.5.0"
const val appCompat = "1.4.1"
const val constraintLayout = "2.1.3"
const val lifecycleKtx = "2.4.1"
const val lifecycleRuntimeKtx = lifecycleKtx
const val lifecycleViewmodelKtx = lifecycleKtx
const val slf4j = "1.7.30"
const val logback = "1.2.3"
const val kermit = "1.0.0"
const val junit = "4.13.2"
const val androidXTestJUnit = "1.1.3"
const val testCore = "1.4.0"
const val mockito = "3.12.4"
const val robolectric = "4.7.3"
}
object Dependencies {
object Gradle {
const val kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
const val sqlDelight = "com.squareup.sqldelight:gradle-plugin:${Versions.sqlDelight}"
}
object Coroutines {
const val android =
"org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.kotlinCoroutines}"
const val core =
"org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.kotlinCoroutines}"
const val test =
"org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.kotlinCoroutines}"
}
object Android {
const val material = "com.google.android.material:material:${Versions.material}"
}
object AndroidX {
const val appCompat = "androidx.appcompat:appcompat:${Versions.appCompat}"
const val constraintLayout =
"androidx.constraintlayout:constraintlayout:${Versions.constraintLayout}"
const val lifecycleRuntimeKtx =
"androidx.lifecycle:lifecycle-runtime-ktx:${Versions.lifecycleRuntimeKtx}"
const val lifecycleViewmodelKtx =
"androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions.lifecycleViewmodelKtx}"
}
object Compose {
const val animation = "androidx.compose.animation:animation:${Versions.compose}"
const val compiler = "androidx.compose.compiler:compiler:${Versions.compose}"
const val foundation = "androidx.compose.foundation:foundation:${Versions.compose}"
const val foundationLayout =
"androidx.compose.foundation:foundation-layout:${Versions.compose}"
const val material = "androidx.compose.material:material:${Versions.compose}"
const val materialIconsExtended =
"androidx.compose.material:material-icons-extended:${Versions.compose}"
const val runtime = "androidx.compose.runtime:runtime:${Versions.compose}"
const val ui = "androidx.compose.ui:ui:${Versions.compose}"
const val uiGraphics = "androidx.compose.ui:ui-graphics:${Versions.compose}"
const val uiTooling = "androidx.compose.ui:ui-tooling:${Versions.compose}"
const val activity = "androidx.activity:activity-compose:${Versions.activityCompose}"
const val navigation =
"androidx.navigation:navigation-compose:${Versions.navigationCompose}"
}
object Koin {
const val android = "io.insert-koin:koin-android:${Versions.koin}"
const val androidExt = "io.insert-koin:koin-android-ext:${Versions.koinExt}"
const val compose = "io.insert-koin:koin-androidx-compose:${Versions.koin}"
const val core = "io.insert-koin:koin-core:${Versions.koin}"
const val coreExt = "io.insert-koin:koin-core-ext:${Versions.koinExt}"
const val ktor = "io.insert-koin:koin-ktor:${Versions.koin}"
const val test = "io.insert-koin:koin-test:${Versions.koin}"
const val testJUnit4 = "io.insert-koin:koin-test-junit4:${Versions.koin}"
}
object Ktor {
const val clientCore = "io.ktor:ktor-client-core:${Versions.ktor}"
const val clientAndroid = "io.ktor:ktor-client-android:${Versions.ktor}"
const val clientCio = "io.ktor:ktor-client-cio:${Versions.ktor}"
const val clientDarwin = "io.ktor:ktor-client-darwin:${Versions.ktor}"
const val clientIOS = "io.ktor:ktor-client-ios:${Versions.ktor}"
const val clientJava = "io.ktor:ktor-client-java:${Versions.ktor}"
const val clientJson = "io.ktor:ktor-client-json:${Versions.ktor}"
const val clientOkHttp = "io.ktor:ktor-client-okhttp:${Versions.ktor}"
const val clientSerialization = "io.ktor:ktor-client-serialization:${Versions.ktor}"
const val clientLogging = "io.ktor:ktor-client-logging:${Versions.ktor}"
const val contentNegotiation = "io.ktor:ktor-client-content-negotiation:${Versions.ktor}"
const val json = "io.ktor:ktor-serialization-kotlinx-json:${Versions.ktor}"
const val websockets = "io.ktor:ktor-websockets:${Versions.ktor}"
}
object SQLDelight {
const val runtime = "com.squareup.sqldelight:runtime:${Versions.sqlDelight}"
const val coroutineExtensions =
"com.squareup.sqldelight:coroutines-extensions:${Versions.sqlDelight}"
const val androidDriver = "com.squareup.sqldelight:android-driver:${Versions.sqlDelight}"
const val nativeDriver = "com.squareup.sqldelight:native-driver:${Versions.sqlDelight}"
const val sqliteDriver = "com.squareup.sqldelight:sqlite-driver:${Versions.sqlDelight}"
}
object Log {
const val slf4j = "org.slf4j:slf4j-simple:${Versions.slf4j}"
const val logback = "ch.qos.logback:logback-classic:${Versions.logback}"
const val kermit = "co.touchlab:kermit:${Versions.kermit}"
}
object Test {
const val junit = "junit:junit:${Versions.junit}"
const val androidXTestJUnit = "androidx.test.ext:junit:${Versions.androidXTestJUnit}"
const val mockito = "org.mockito:mockito-inline:${Versions.mockito}"
const val robolectric = "org.robolectric:robolectric:${Versions.robolectric}"
const val testCore = "androidx.test:core:${Versions.testCore}"
const val composeUiTest = "androidx.compose.ui:ui-test:${Versions.compose}"
const val composeUiTestJUnit = "androidx.compose.ui:ui-test-junit4:${Versions.compose}"
const val composeUiTestManifest = "androidx.compose.ui:ui-test-manifest:${Versions.compose}"
}
}
- root-directory:
build.grade.kts:
buildscript {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.1.2")
with(Dependencies.Gradle) {
classpath(kotlin)
classpath(sqlDelight)
}
}
}
allprojects {
repositories {
google()
mavenCentral()
maven(url = uri("https://maven.pkg.jetbrains.space/public/p/ktor/eap"))
maven(url = uri("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev"))
}
}
tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
gradle.properties:
#Kotlin
kotlin.code.style=official
#Android
android.useAndroidX=true
android.enableJetifier=true
#MPP
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
kotlin.mpp.enableCInteropCommonization=true
settings.gradle:
pluginManagement {
repositories {
google()
gradlePluginPortal()
mavenCentral()
}
}
rootProject.name = "AnotherKMM"
include(":androidApp")
include(":shared")
- shared:
build.gradle.kts:
plugins {
kotlin("multiplatform")
id("com.android.library")
id("com.squareup.sqldelight")
}
sqldelight {
database("Database") {
packageName = "com.example.anotherkmm.database"
}
}
kotlin {
android()
ios()
sourceSets {
val commonMain by getting {
dependencies {
with(Dependencies.Ktor) {
implementation(clientCore)
// implementation(clientCio)
implementation(clientLogging)
}
with(Dependencies.Coroutines) {
implementation(core)
}
with(Dependencies.Koin) {
implementation(core)
// implementation(ktor)
implementation(test)
}
with(Dependencies.SQLDelight) {
implementation(runtime)
implementation(coroutineExtensions)
}
with(Dependencies.Compose) {
implementation(runtime)
}
with(Dependencies.AndroidX) {
implementation(lifecycleRuntimeKtx)
implementation(lifecycleViewmodelKtx)
}
}
}
val androidMain by getting {
dependencies {
with(Dependencies.Ktor) {
// implementation(clientAndroid)
implementation(clientOkHttp)
}
with(Dependencies.SQLDelight) {
implementation(androidDriver)
}
}
}
val iosMain by getting {
dependencies {
with(Dependencies.Ktor) {
implementation(clientIOS)
// implementation(clientDarwin)
}
with(Dependencies.SQLDelight) {
implementation(nativeDriver)
}
}
}
val commonTest by getting {
dependencies {
implementation(Dependencies.Koin.test)
implementation(Dependencies.Coroutines.test)
implementation(kotlin("test"))
}
}
val androidTest by getting
val iosTest by getting
}
}
android {
compileSdk = Versions.androidCompileSdk
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdk = Versions.androidMinSdk
targetSdk = Versions.androidTargetSdk
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
buildFeatures {
compose = true
}
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
}
}
- androidApp
build.gradle.kts:
plugins {
id("com.android.application")
kotlin("android")
}
android {
compileSdk = Versions.androidCompileSdk
defaultConfig {
applicationId = "com.example.anotherkmm.android"
minSdk = Versions.androidMinSdk
targetSdk = Versions.androidTargetSdk
versionCode = Versions.appVersionCode
versionName = Versions.appVersionName
versionNameSuffix = Versions.appVersionNameSuffix
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
buildToolsVersion = Versions.buildTool
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = Versions.kotlinCompilerExtension
}
}
dependencies {
with(Dependencies.Android) {
implementation(material)
}
with(Dependencies.AndroidX) {
implementation(appCompat)
implementation(constraintLayout)
implementation(lifecycleRuntimeKtx)
implementation(lifecycleViewmodelKtx)
}
with(Dependencies.Compose) {
implementation(animation)
implementation(compiler)
implementation(foundation)
implementation(foundationLayout)
implementation(material)
implementation(materialIconsExtended)
implementation(runtime)
implementation(ui)
implementation(uiTooling)
implementation(uiGraphics)
implementation(activity)
implementation(navigation)
}
with(Dependencies.Coroutines) {
implementation(android)
implementation(core)
}
with(Dependencies.Koin) {
implementation(core)
// implementation(coreExt)
implementation(android)
implementation(androidExt)
implementation(compose)
testImplementation(test)
testImplementation(testJUnit4)
}
with(Dependencies.Test) {
testImplementation(junit)
androidTestImplementation(androidXTestJUnit)
testImplementation(testCore)
testImplementation(robolectric)
testImplementation(mockito)
// Compose testing dependencies
androidTestImplementation(composeUiTest)
androidTestImplementation(composeUiTestJUnit)
debugImplementation(composeUiTestManifest)
}
implementation(project(":shared"))
}
- in shared module in commonMain I’ve created PlatformModule.kt:
package com.example.anotherkmm.modules
import org.koin.core.module.Module
expect fun platformModule(): Module
Module is marked as unresolved reference and in import the “koin” word is red.
The same happens to all libraries, which are used via “implementation” in build.gradle.kts(shared).
In androidMain I can use koin and the other libraries without problem, only in commonMain are all classes from libraries like Koin, Ktor unresolved.
In iosMain all “kotlin” classes are unresolved too.
I also see strange error by gradle sync. IN my project I’m using coroutines 1.6.0
I’ve already created another project from the scratch, where I don’t use buildSrc with Dependecies.kt etc.
But the problem is the same.
can anyone tell me, what the problem is and how can I solve it?