streetsofboston
09/29/2020, 2:35 PMKris Wong
09/29/2020, 2:35 PMKris Wong
09/29/2020, 2:36 PMzalewski.se
09/29/2020, 2:37 PMgradle.properties
settings?Kris Wong
09/29/2020, 2:37 PMkotlin.code.style=official
streetsofboston
09/29/2020, 2:38 PMorg.gradle.jvmargs=-Xmx1536m
android.enableJetifier=true
kotlin.code.style=official
xcodeproj=./iosApp
#kotlin.mpp.enableGranularSourceSetsMetadata=true
#kotlin.native.enableDependencyPropagation=false
Kris Wong
09/29/2020, 2:40 PMiosMain
has the same problemstreetsofboston
09/29/2020, 2:41 PMExternal Libraries
section of the ‘Project’ browser looks different. I can find the the ‘Foundation’ library, but it looks quite different in the IDE now…streetsofboston
09/29/2020, 3:01 PMkotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
Kris Wong
09/29/2020, 3:02 PMstreetsofboston
09/29/2020, 3:05 PM5:49 PM Incompatible Kotlin/Native libraries
There are 2 third-party libraries attached to the project that were compiled with an older Kotlin/Native compiler and cant be read in IDE:
Gradle: com.russhwolf:multiplatform-settings-metadata:apple64Main:0.6.2
Gradle: com.russhwolf:multiplatform-settings-metadata:appleMain:0.6.2
Please edit Gradle buildfile(s) and specify library a version compatible with Kotlin/Native 1.4.10. Then re-import the project in IDE.
But that build-error no longer appears with these properties re-enabled… odd…zalewski.se
09/29/2020, 3:06 PMzalewski.se
09/29/2020, 3:06 PMKris Wong
09/29/2020, 3:07 PMstreetsofboston
09/29/2020, 3:07 PMimport kolinx.coroutines.xxxxxx
are red now)streetsofboston
09/29/2020, 3:07 PMKris Wong
09/29/2020, 3:08 PMKris Wong
09/29/2020, 3:08 PMstreetsofboston
09/29/2020, 3:09 PMkotlin.native.enableDependencyPropagation=false
This one enabled: I get import kolinx.coroutines.xxxxxx
red-lines in the IDE.
This one disabled: I get import platform.xxxxx
red-lines in the IDE.zalewski.se
09/29/2020, 3:09 PMKris Wong
09/29/2020, 3:10 PMKris Wong
09/29/2020, 3:11 PMstreetsofboston
09/29/2020, 3:11 PMstreetsofboston
09/29/2020, 3:12 PMzalewski.se
09/29/2020, 3:12 PMstreetsofboston
09/29/2020, 3:13 PMKris Wong
09/29/2020, 3:15 PMstreetsofboston
09/29/2020, 3:16 PMkotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
and did a sync-with-gradle.
Most red-lines went away, except for one:`import okio.toByteString`. All the import platform…
are now fine…
Then a ‘Rebuild Project’ and the import kotlinx.coroutines.suspendCanncellableCoroutine
went red as well….zalewski.se
09/29/2020, 3:17 PMios()
but when we changed it to something like:
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64
iOSTarget("ios") {...}
The issue got solvedstreetsofboston
09/29/2020, 3:19 PMios()
when moving to use the KMM plugin and it all looked good until today.
Let me use that pattern again and see if it solves stuff. Thanks!zalewski.se
09/29/2020, 3:21 PMstreetsofboston
09/29/2020, 3:21 PMKotlinTarget with name 'iosX64' not found.
zalewski.se
09/29/2020, 3:23 PMrusshwolf
09/29/2020, 3:25 PMios()
because it's setting up an intermediate source-set. Those gradle properties should help but it's still often spotty for me. Try in IDEA for comparison, and maybe try beta/canary Android Studio since newer AS is based off of newer IDEA. Also make sure your Kotlin IDE plugin matches the Kotlin language version you're using.zalewski.se
09/29/2020, 3:26 PMstreetsofboston
09/29/2020, 3:31 PMstreetsofboston
09/29/2020, 3:32 PMval isiOSDevice = sdkName.orEmpty().startsWith("iphoneos")
if (isiOSDevice) {
iosArm64("iOS64")
} else {
iosX64("iOS")
}
will give me that build-error KotlinTarget with name 'iosX64' not found.
russhwolf
09/29/2020, 3:36 PMios()
is working since it uses that target internallystreetsofboston
09/29/2020, 3:40 PMzalewski.se
09/29/2020, 3:41 PMstreetsofboston
09/29/2020, 4:24 PMios()
with the if (isIosDevice) ….
, i get that error.streetsofboston
09/29/2020, 4:26 PMzalewski.se
09/29/2020, 4:28 PMstreetsofboston
09/29/2020, 4:32 PMimport org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("multiplatform")
kotlin("native.cocoapods")
id("com.android.library")
id("kotlin-android-extensions")
id("com.apollographql.apollo")
id("kotlinx-serialization")
}
group = "com.mycompany"
version = "1.0-SNAPSHOT"
repositories {
gradlePluginPortal()
google()
jcenter()
mavenCentral()
}
kotlin {
android()
ios()
sourceSets {
all {
val isTestSource = name.contains("Test")
languageSettings.apply {
useExperimentalAnnotation("kotlin.RequiresOptIn")
useExperimentalAnnotation("kotlinx.coroutines.ExperimentalCoroutinesApi")
if (isTestSource) {
useExperimentalAnnotation("com.accenture.fetch.VisibleForTestingOnly")
}
}
}
val commonMain by getting {
dependencies {
implementation(Deps.Coroutines.core)
implementation(Deps.stately)
implementation(Deps.statelyConcurrency)
implementation(Deps.multiplatformSettings)
implementation(Deps.koinCore)
implementation(Deps.Apollo.api)
implementation(Deps.coreSerialization)
api(Deps.kermit)
}
}
val commonTest by getting {
dependencies {
implementation(Deps.KotlinTest.common)
implementation(Deps.KotlinTest.annotations)
implementation(Deps.multiplatformSettingsTest)
implementation(Deps.koinTest)
}
}
val androidMain by getting {
dependencies {
implementation(Deps.app_compat_x)
implementation(Deps.Coroutines.android)
implementation(Deps.Apollo.api)
implementation(Deps.Apollo.runtime)
implementation(Deps.Apollo.okHttpLoggingInterceptor)
}
}
val androidTest by getting {
dependencies {
implementation(Deps.junit)
implementation(Deps.KotlinTest.jvm)
implementation(Deps.KotlinTest.junit)
implementation(Deps.AndroidXTest.core)
implementation(Deps.AndroidXTest.junit)
implementation(Deps.AndroidXTest.runner)
implementation(Deps.AndroidXTest.rules)
implementation(Deps.Coroutines.test)
implementation(Deps.mockk)
implementation("org.robolectric:robolectric:4.3")
}
}
val iosMain by getting {
dependencies {
implementation(Deps.Coroutines.core) {
version { strictly(Versions.coroutines) }
}
implementation(Deps.Apollo.api)
}
}
val iosTest by getting
}
cocoapods {
summary = "Common library for the KaMP starter kit"
homepage = "<https://github.com/touchlab/KaMPStarter>"
ios.deploymentTarget = "9.0"
podfile = project.file("../iosApp/Podfile")
}
}
android {
compileSdkVersion(Versions.compile_sdk)
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdkVersion(Versions.min_sdk)
targetSdkVersion(Versions.target_sdk)
versionCode = 1
versionName = "1.0"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
compileOptions {
sourceCompatibility = Versions.java
targetCompatibility = Versions.java
}
}
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<KotlinNativeTarget>(targetName).binaries.getFramework(mode).apply {
export(Deps.kermit)
transitiveExport = true
}
inputs.property("mode", mode)
dependsOn(framework.linkTask)
val targetDir = File(buildDir, "xcode-frameworks")
from({ framework.outputDirectory })
into(targetDir)
}
tasks.getByName("build").dependsOn(packForXcode)
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = Versions.java.toString()
}
apollo {
generateKotlinModels.set(true)
}
tasks.withType<Test> {
testLogging {
events(TestLogEvent.FAILED, TestLogEvent.STANDARD_OUT, TestLogEvent.STANDARD_ERROR)
}
}
zalewski.se
09/29/2020, 4:40 PMzalewski.se
09/29/2020, 4:41 PMstreetsofboston
09/29/2020, 4:41 PMrusshwolf
09/29/2020, 4:43 PMid("com.android.library")
first in your plugins
block?streetsofboston
09/29/2020, 4:44 PMzalewski.se
09/29/2020, 4:45 PMstreetsofboston
09/29/2020, 4:46 PMstreetsofboston
09/29/2020, 4:49 PMstreetsofboston
09/29/2020, 4:52 PMkotlin.targets.getByName<KotlinNativeTarget>(targetName)
is the culprit when using the if (isiOSDevice) … …
snippet 🙂russhwolf
09/29/2020, 4:55 PMios()
or iosArm64()
or iosX64()
zalewski.se
09/29/2020, 4:56 PMstreetsofboston
09/29/2020, 4:57 PMstreetsofboston
09/29/2020, 4:57 PMif (isiOSDevice)… …
snippet.zalewski.se
09/29/2020, 5:05 PMstreetsofboston
09/29/2020, 5:57 PMios()
instruction. 🙂Tijl
09/29/2020, 8:29 PMrusshwolf
09/29/2020, 8:56 PMkotlin.targets.getByName<KotlinNativeTarget>("ios").binaries.getFramework(mode)
and not need the framework()
funstreetsofboston
09/29/2020, 8:59 PMkotlin.targets.getByName<KotlinNativeTarget>(targetName)
throws an error that the target name is not found (the only target is available is ios
, without the architecture-postfix when using the if (onPhone) … …
code, and you’ll have to examine the `konanTarget`….).streetsofboston
09/29/2020, 9:01 PMgetFramework(mode)
on the `binaries`…. let me check…
Checked: Yup!russhwolf
09/29/2020, 9:12 PMgetByName<KotlinNativeTarget>("ios")
it's looking for the target that you named "ios", which you're doing in both branches of
if (onPhone) {
iosArm64("ios")
} else {
iosX64("ios")
}
streetsofboston
09/30/2020, 7:47 PMiosMain
source-set, but now I get red-lines in the `commonMain`….. Ugh!streetsofboston
09/30/2020, 7:58 PM