Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Building for iOS Simulator-arm64 but attempting to link with file built for iOS Simulator-x86_64 (M1) #60

Open
avjiang opened this issue Jul 8, 2021 · 0 comments

Comments

@avjiang
Copy link

avjiang commented Jul 8, 2021

Hi, I am trying to integrate KMM project as a pod to my sample Xcode Project. I can link the KMM Pod to my Xcode project. However if I try to call one of the function, below error yielded. If I do not call any of the KMM function, it can run the app in my simulator.

ViewController

import UIKit
import Multiplatform

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        let a = Greeting()
        a.greeting()
    }
}
ld: warning: ignoring file /Users/avjiang/Developments/Multiplatform/SharedCode/build/cocoapods/framework/Multiplatform.framework/Multiplatform, building for iOS Simulator-arm64 but attempting to link with file built for iOS Simulator-x86_64
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_MultiplatformGreeting", referenced from:
      objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The KMM application is just a simple app. There is a Greeting class inside SharedCode -> commonMain -> kotlin -> Greeting

Below is my configuration for build.gradle.kts

import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    id("com.android.library")
}

version = "1.0"

kotlin {
    android()

    cocoapods {
        // Configure fields required by CocoaPods.
        summary = "Some description for a Kotlin/Native module"
        homepage = "Link to a Kotlin/Native module homepage"
        frameworkName = "Multiplatform"
        ios.deploymentTarget = "13.5"
        podfile = project.file("/Users/avjiang/Developments/TestKotlinMultiplatformPod/Podfile")
    }

    val iosTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
        if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
            ::iosArm64
        else
            ::iosX64

    iosTarget("ios") { }

    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val androidMain by getting
        val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.13.2")
            }
        }
        val iosMain by getting
        val iosTest by getting
    }
}

android {
    compileSdkVersion(30)
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdkVersion(19)
        targetSdkVersion(30)
    }
}

And this is my project build.gradle.kts

buildscript {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20")
        classpath("com.android.tools.build:gradle:4.2.2")
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

tasks.register("clean", Delete::class) {
    delete(rootProject.buildDir)
}

Basically I am just following the tutorial from https://kotlinlang.org/docs/mobile/create-first-app.html. Nothing complex yet. Is there anything I missed out?

My machine configuration:
Mac mini M1
Xcode 13 beta 2
MacOS 11.4

Thank you

@avjiang avjiang changed the title Error: Building for iOS Simulator-arm64 but attempting to link with file built for iOS Simulator-x86_64 Error: Building for iOS Simulator-arm64 but attempting to link with file built for iOS Simulator-x86_64 (M1) Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant