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

Artem Kopan

09/01/2020, 4:45 PM
Hi everyone, I’m trying to use ios() target instead of iosX64+ iosArm64, but I got exception “platform” not resolved. I guess it’s bug in studio or kotlin plugin, because build is successful. I use android studio 4.1 rc2
e

Evan

09/01/2020, 5:13 PM
I am having pretty much the same issue in IntelliJ CE, so it’s probably an issue with the kotlin plugin, kotlin native plugin or your specific build configuration. Does it compile and run? Mine did, even with the IDE errors.
a

Artyom Degtyarev [JB]

09/01/2020, 8:40 PM
Hello, @Artem Kopan! First of all, what Kotlin version you’re using here? I suppose this should work correctly only for 1.4. Also, please tell if you have this option set in the gradle.properties file:
kotlin.mpp.enableGranularSourceSetsMetadata=true
. Just for the record: In my recommendations here, I’m relying on this blogpost.
a

Artem Kopan

09/02/2020, 3:26 PM
@Artyom Degtyarev [JB] I use kotlin 1.4 and I have option enableGranularSourceSetsMetadata=true in gradle.properties My build.gradle file:
Copy code
plugins {
    kotlin("multiplatform")
    id("com.android.library")
    id("kotlin-android-extensions")
    id("org.jetbrains.kotlin.plugin.serialization")
    `maven-publish`
}

repositories {
    gradlePluginPortal()
    google()
    jcenter()
    mavenCentral()
}

kotlin {
    android()
    ios {
        binaries {
            framework {
                baseName = "RadioRecord"
                export(project(":shared:mvi"))
                export(project(":shared:core"))
                transitiveExport = true
            }
        }
        compilations.getByName("main").apply {
            val observer by cinterops.creating {
                val file = project.file("src/nativeInterop/cinterop/observer.def")
                defFile(file)
                packageName("c.observer")
            }
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                api(project(":shared:core"))
                api(project(":shared:mvi"))

                // SERIALIZATION
                implementation(Deps.Jetbrains.Kotlinx.Serialization.Core)

                // KTOR
                implementation(Deps.Ktor.Core)
                implementation(Deps.Ktor.Json)
                implementation(Deps.Ktor.Serialization)
                implementation(Deps.Ktor.Logging)

                api(Deps.Kodein.Di)
            }
        }
        val androidMain by getting {
            dependencies {
                // KTOR
                implementation(Deps.Ktor.Jvm.Okhttp)

                // EXO PLAYER
                api(Deps.Google.Android.ExoPlayer.Core)
                api(Deps.Google.Android.ExoPlayer.Hls)
                api(Deps.Google.Android.ExoPlayer.Ui)

                //ANDROIDX
                implementation(Deps.AndroidX.Core.CoreKtx)
                implementation(Deps.AndroidX.Palette.Palette)

                //GLIDE
                implementation(Deps.Glide.Glide)
            }
        }

        val iosMain by getting {
            dependencies {
                // KTOR
                implementation(Deps.Ktor.Native.Ios)
            }
        }
    }
}

android {
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    sourceSets["main"].res.srcDirs("src/androidMain/res")
    compileSdkVersion(29)
    defaultConfig {
        targetSdkVersion(29)
        minSdkVersion(21)
    }
}

////<https://youtrack.jetbrains.com/issue/KT-27170>
configurations.create("compileClasspath")
//

afterEvaluate {
    publishing {
        publications {
            create<MavenPublication>("maven") {
                groupId = "io.radio.record"
                artifactId = "shared"
                version = "1.0"
                artifact("$buildDir/outputs/aar/app-debug.aar")
            }
        }
    }
}

//val packForXcode by tasks.creating(Sync::class) {
//    group = "build"
//    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
//    val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
//    val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
//    val framework = kotlin.targets.getByName<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget>(targetName).binaries.getFramework(mode)
//    inputs.property("mode", mode)
//    dependsOn(framework.linkTask)
//    val targetDir = File(buildDir, "xcode-frameworks")
//    from({ framework.outputDirectory })
//    into(targetDir)
//}
//tasks.getByName("build").dependsOn(packForXcode)
Invalidate cache doesn’t work
6 Views