Thread
#multiplatform
    a

    Arthur Brum

    2 years ago
    Hi everyone, I'm facing problems to export my .framework to be used in xcode projects (without the need of Run Script in gradle) When I just drag&drop the framework file from the <my-kmp-project>/build/framework/ and try to run, I get the following errors:
    ld: warning: ignoring file /Users/.../BC_lib Demo/BC_lib.framework/BC_lib, building for iOS-arm64 but attempting to link with file built for iOS Simulator-x86_64
    Undefined symbols for architecture arm64:
     "_OBJC_CLASS_$_KotlinMutableDictionary", referenced from:
       objc-class-ref in ViewController.o
     "_OBJC_CLASS_$_BC_libPinpadOutput", referenced from:
       objc-class-ref in ViewController.o
     "_OBJC_CLASS_$_BC_libCommonKt", referenced from:
       objc-class-ref in ViewController.o
     "_OBJC_CLASS_$_BC_libPinpadCompanion", referenced from:
       objc-class-ref in ViewController.o
    ld: symbol(s) not found for architecture arm64
    Are there any extra steps that I should do to be able to use my framework when developing to devices (on simulators things work)
    Artyom Degtyarev [JB]

    Artyom Degtyarev [JB]

    2 years ago
    Hello, @Arthur Brum! Can you tell if this framework is a result of targeting
    iosArm<64 | 32>
    or an
    iosX64
    ? On a first sight, it seems like you’re feeding Xcode with incorrect framework. If you are sure that that’s not the problem… Maybe Xcode cached the simulator framework somewhere inside, and you should clean build folder etc. Check the project folder contents manually and make sure that correct framework is in place.
    a

    Arthur Brum

    2 years ago
    Oh, thanks @Artyom Degtyarev [JB]! Indeed it was just a wrong cached version for some reason... And FYI, I was setting the target conditionally, so I could build to simulator and device.. Thats probably why it happened... even though I made sure to build for physical device before copying the framework
    (...)
    def iosTarget = System.getenv('SDK_NAME')?.startsWith('iphoneos') ? presets.iosArm64 : presets.iosX64
    
    fromPreset(iosTarget, 'ios') {
        binaries {
            framework('BC_lib')
        }
    }
    Artyom Degtyarev [JB]

    Artyom Degtyarev [JB]

    2 years ago
    This is fine, Xcode build process can be unintuitive sometimes 🙂 About this code snippet. In the end, you used the Gradle task from the Xcode, am I right? Or you are setting this
    SDK_NAME
    manually? Because usually this construction is being used along with some
    copyFramework
    task, to automate the process.
    a

    Arthur Brum

    2 years ago
    Yes yes, at the end of my build file I have the task.
    task packForXCode(type: Sync) {
        final File frameworkDir = new File(buildDir, "xcode-frameworks")
        final String mode = project.findProperty("XCODE_CONFIGURATION")?.toUpperCase() ?: 'DEBUG'
        final def framework = kotlin.targets.ios.binaries.getFramework("BC_lib", mode)
    
        inputs.property "mode", mode
        dependsOn framework.linkTask
    
        from { framework.outputFile.parentFile }
        into frameworkDir
    
        doLast {
            new File(frameworkDir, 'gradlew').with {
                text = "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$@\n"
                setExecutable(true)
            }
        }
    }
    Now that I tried to build to simulator just to make some UI changes I get the related error saying that I dont have symbols for
    Simulator-x86_64
    I've read somewhere saying that apple don't accept apps which their included frameworks have extra symbols to different archtecture mixed up. What would be the best way to set this so that I can build to both simulator and device without having to switch framework files?
    Artyom Degtyarev [JB]

    Artyom Degtyarev [JB]

    2 years ago
    you can use the
    FatFramework
    , I suppose. See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#building-final-native-binaries, Building universal frameworks subsection.