arc_react
arc_react

Reputation: 11

custom framework wokring in simulator. Not working in real device

I am creating custom framework in iOS native. This framework will add in to react native projects consider my framework as native module in react. I am using M1 mac

Framework is working fine in simulator ( rosetta destnation simulator & apple silicon simulator ). But not working on real device. got crash before or on loading the framework itself.

my framework project build settings :

Architecture i set to arm64, x86_64

Build active architecture = No

Installation Directory - @executable_path/../Frameworks

** My framework lipo info: **

Architectures in the fat file: /Users/userName/Documents/AbcSourceCode/CustomFramework/CustomFramework.framework/CustomFramework are: x86_64 arm64

My run script :

#!/bin/sh UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal make sure the output directory exists mkdir -p "${UNIVERSAL_OUTPUTFOLDER}" Build for Device xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build Copy framework structure to the universal folder for device cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/" Build for Simulator xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build Copy framework structure to the universal folder for simulator cp -R "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/" Combine the frameworks for device and simulator using lipo lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}"
"${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
"${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" Copy Swift modules from simulator build (if it exists) to the copied framework directory SIMULATOR_SWIFT_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/." if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then cp -R "${SIMULATOR_SWIFT_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule" fi Convenience steps to copy the framework to the project's directory and open in Finder cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}" open "${UNIVERSAL_OUTPUTFOLDER}"

My Error :

dyld[541]: Library not loaded: @rpath/CustomFramework.framework/CustomFramework   Referenced from: <E072FE8A-611F-30AB-A6ED-186777B4B0F1> /private/var/containers/Bundle/Application/8B615D3F-B911-41DB-A630-F74C7737DAC4/App.app/App   Reason: tried: '/usr/lib/swift/CustomFramework.framework/CustomFramework' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/CustomFramework.framework/CustomFramework' (no such file), '/private/var/containers/Bundle/Application/8B615D3F-B911-41DB-A630-F74C7737DAC4/App.app/Frameworks/CustomFramework.framework/CustomFramework' (mach-o file (/private/var/containers/Bundle/Application/8B615D3F-B911-41DB-A630-F74C7737DAC4/App.app/Frameworks/CustomFramework.framework/CustomFramework), but incompatible platform (have 'iOS-sim', need 'iOS')), '/private/var/containers/Bundle/Application/8B615D3F-B911-41DB-A630-F74C7737DAC4/App.app/Frameworks/CustomFramework.framework/CustomFramework' (mach-o file (/private/var/containers/Bundle/Application/8B615D3F-B911-41DB-A630-F74C7737DAC4/App.app/Frameworks/CustomFramework.framework/CustomFramework), but incompatible platform (have 'iOS-sim', need 'iOS')), '/usr/lib/swift/CustomFramework.framework/CustomFramework' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/CustomFramework.framework/CustomFramework' (no such file), '/private/var/containers/Bundle/Application/8B615D3F-B911-41DB-A630-F74C7737DAC4/App.app/Frameworks/CustomFramework.framework/CustomFramework' (mach-o file (/private/var/containers/Bundle/Application/8B615D3F-B911-41DB-A630-F74C7737DAC4/App.app/Frameworks/CustomFramework.framework/CustomFramework), but incompatible platform (have 'iOS-sim', need 'iOS')), '/private/var/containers/Bundle/Application/8B615D3F-B911-41DB-A630-F74C7737DAC4/App.app/Frameworks/CustomFramework.framework/CustomFramework' (mach-o file (/private/var/containers/Bundle/Application/8B615D3F-B911-41DB-A630-F74C7737DAC4/App.app/Frameworks/CustomFramework.framework/CustomFramework), but incompatible platform (have 'iOS-sim', need 'iOS'))

Upvotes: 0

Views: 100

Answers (1)

Hao Liang
Hao Liang

Reputation: 141

Xcode error (have 'iOS-sim', need 'iOS') that it needs a library that is compiled for the iOS device, but the library you are using is for the simulator.
You are using M1Mac for static library compilation, and in the non-rosetta case, the simulator version and the iPhone version are arm64 architecture, how do you distinguish between the two?
XCframework is recommended.

Upvotes: 0

Related Questions