Невозможно импортировать зависимости для Kotlin мультиплатформенного общего - PullRequest
1 голос
/ 14 января 2020

Я пробую Kotlin мультиплатформу и пытаюсь настроить все свои зависимости для нее. Начиная с commonMain

Я пытаюсь добавить к общей части зависимости Koin и Ktor, но я не могу использовать ни одну из них.

Это мой Сценарий Gradle

plugins {
    id 'org.jetbrains.kotlin.multiplatform' version '1.3.61'
}
repositories {
    google()
    jcenter()
    mavenCentral()
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId 'org.jetbrains.kotlin.mpp_app_android'
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName '1.0'
        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    }
    buildTypes {
        release {
            minifyEnabled false
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'org.koin:koin-android:2.0.1'
    implementation 'org.koin:koin-androidx-viewmodel:2.0.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel:2.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
}

kotlin {
    android("android")
    // This is for iPhone emulator
    // Switch here to iosArm64 (or iosArm32) to build library for iPhone device
    iosX64("ios") {
        binaries {
            framework()
        }
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation kotlin('stdlib-common')
                implementation 'org.koin:koin-ktor:2.0.1'
                implementation 'org.koin:koin-core:2.0.1'

                // HTTP
                implementation "io.ktor:ktor-client-core:1.2.6"
                implementation "io.ktor:ktor-client-json:1.2.6"
                implementation "io.ktor:ktor-client-serialization:1.2.6"

                // Coroutines
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.2.1"
            }
        }
        commonTest {
            dependencies {
                implementation kotlin('test-common')
                implementation kotlin('test-annotations-common')
            }
        }
        androidMain {
            dependencies {
                implementation kotlin('stdlib')
            }
        }
        androidTest {
            dependencies {
                implementation kotlin('test')
                implementation kotlin('test-junit')
            }
        }
        iosMain {
        }
        iosTest {
        }
    }
}

// This task attaches native framework built from ios module to Xcode project
// (see iosApp directory). Don't run this task directly,
// Xcode runs this task itself during its build process.
// Before opening the project from iosApp directory in Xcode,
// make sure all Gradle infrastructure exists (gradle.wrapper, gradlew).
task copyFramework {
    def buildType = project.findProperty('kotlin.build.type') ?: 'DEBUG'
    def target = project.findProperty('kotlin.target') ?: 'ios'
    dependsOn kotlin.targets."$target".binaries.getFramework(buildType).linkTask

    doLast {
        def srcFile = kotlin.targets."$target".binaries.getFramework(buildType).outputFile
        def targetDir = getProperty('configuration.build.dir')
        copy {
            from srcFile.parent
            into targetDir
            include 'app.framework/**'
            include 'app.framework.dSYM'
        }
    }
}

В файле Sample.kt, который был сгенерирован при создании проекта, я попытался настроить Koin в методе main

fun main() {
    startKoin {
        // declare modules
        modules(myModule)
    }
    println(hello())
}

, но startKoin не может быть решена.

Я очистил / перестроил проект, сделал синхронизацию gradle c и все еще не могу импортировать koin или любую другую зависимость, так что я пропускаю

1 Ответ

2 голосов
/ 14 января 2020

Коин не является мультиплатформенным. У нас есть [мультиплатформенные вилки] [1], но нам нужно поговорить о том, какую использовать и какую версию. Мы все еще обсуждаем многоплатформенную стратегию.

Зависимости Ktor более сложны, чем это. См. ниже. Я удалил ваши другие зависимости для ясности, но вы должны оставить их явно:)

sourceSets {
        commonMain {
            dependencies {
                implementation "io.ktor:ktor-client-core:1.2.6"
                implementation "io.ktor:ktor-client-json:1.2.6"
                implementation "io.ktor:ktor-client-serialization:1.2.6"
            }
        }
        androidMain {
            dependencies {
                implementation "io.ktor:ktor-client-core-jvm:1.2.6"
                implementation "io.ktor:ktor-client-json-jvm:1.2.6"
                implementation "io.ktor:ktor-client-serialization-jvm:1.2.6"
            }
        }
        iosMain {
            dependencies {
                implementation "io.ktor:ktor-client-ios:1.2.6"
                implementation "io.ktor:ktor-client-core-native:1.2.6"
                implementation "io.ktor:ktor-client-json-native:1.2.6"
                implementation "io.ktor:ktor-client-serialization-native:1.2.6"
            }
        }
}


  [1]: https://github.com/kpgalligan/koin/tree/kpg/khan
...