Reputation: 4258
I created a shared library for both iOS and Android using Kotlin Multiplatform and everything was working correctly until I not updated the Xcode to 12.0
As I updated Xcode to 12.0 the framework stopped working for real device (iphone) but working on simulator
my Gradle
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
id("com.android.library")
id("kotlin-android-extensions")
}
group = "com.example.multiplatform_android_ios"
version = "1.0-SNAPSHOT"
repositories {
gradlePluginPortal()
google()
jcenter()
mavenCentral()
}
kotlin {
android()
ios {
binaries {
framework {
baseName = "shared"
}
}
}
sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting {
dependencies {
implementation("com.google.android.material:material:1.2.0")
}
}
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.12")
}
}
val iosMain by getting
val iosTest by getting
}
}
android {
compileSdkVersion(29)
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdkVersion(24)
targetSdkVersion(29)
versionCode = 1
versionName = "1.0"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
}
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)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
val targetDir = File(buildDir, "xcode-frameworks")
from({ framework.outputDirectory })
into(targetDir)
}
tasks.getByName("build").dependsOn(packForXcode)
Xcode 12.0 Android Studio 4.1 RC 3 Kotlin 1.4.10
com.android.tools.build:gradle:4.1.0-rc03
Upvotes: 3
Views: 2225
Reputation: 168
I had the same issue. Open iosApp.xcodeproj with Xcode. Choose tab "Build Settings". Choose subtab "All". Go the section "Architectures". Create item "Excluded Architectures" if not exist. Create entry under Debug "Any iOS Simulator SDK". As value entry "i386". If you need do it in the same manner for Release. Now, you can try to compile with Android Studio without errors. For non intel processor you need to add arm64 to value items.
Upvotes: 1
Reputation: 2888
According to KT-41854, this problem should be fixed in KMM plugin version 0.1.3, available for the Android Studio 4.1 & 4.2. Please check if it is, and comment at the issue tracker if something is still wrong.
Upvotes: 1
Reputation: 181
I also got the same problem, and resolved by following these steps:
cd "$SRCROOT/.."
./gradlew :shared:packForXCode -PXCODE_CONFIGURATION=${CONFIGURATION}
Upvotes: 5