touchlab / KaMPKit

KaMP Kit by Touchlab. A collection of code & tools designed to get your mobile team started quickly w/Kotlin Multiplatform
https://touchlab.co/
Apache License 2.0
2.2k stars 199 forks source link

Koin dependency not found in iosMain #78

Closed ivannador closed 4 years ago

ivannador commented 4 years ago

We are in the progress of transitioning our Kotlin-based Android app to KMP. KaMPKit is a huge help! Our targets are specified basically the same way:

    android()
    val onPhone = System.getenv("SDK_NAME")?.startsWith("iphoneos") ?: false
    val nativeTarget = if (onPhone) {
        iosArm64("ios")
    } else {
        iosX64("ios")
    }
    nativeTarget.compilations {
        val main by getting {
            kotlinOptions.freeCompilerArgs += "-Xobjc-generics"
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(kotlin("stdlib-common"))
                implementation(Dependencies.Koin.koin)
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val iosMain by getting {
            dependencies {
            }
        }

Trying to use Koin on shared module, but in shared ios code, the Koin library as a dependency is not visible. The Koin library is the same 3.0.0-alpha-8 version from the Touchlab bintray. Is this a gradle glitch? The code is compiling, but it's still pretty annoying to see in iosMain. If I specify ios() instead, it is found, but the gradle KMP extensions create a sourceset for iosX64 and iosArm64, and that obviously causes problems with the expect-actual warnings.

russhwolf commented 4 years ago

Just to clarify: it builds in both cases, but has IDE errors in different ways depending on what configuration you use? What IDE and Kotlin plugin version are you using?

ivannador commented 4 years ago

Yep, exactly. The same happens with the KaMPKit code by the way.

import org.koin.core.module.Module
Unresolved reference: koin

I'm using Android Studio 3.6.1 and Kotlin 1.3.70, but it's the same with 1.3.61.

russhwolf commented 4 years ago

I expect an issue if you've updated the IDE plugin to 1.3.70. Seems like using the 1.3.70 plugin breaks native code that's still using 1.3.61. You could also try it in IDEA and see if you see different behavior. A fresh IDEA installation will have the 1.3.70 plugin though so you'd need to manually install 1.3.61 from https://plugins.jetbrains.com/plugin/6954-kotlin/versions

ivannador commented 4 years ago

Yeah...solved, thanks. :) Forgot to downgrade plugin and tried to downgrade just the libraries.