Objective-C 中不支持的 Swift 架构

unsupported Swift architecture in Objective-C

提问人:Dhanaseelan V 提问时间:11/17/2023 最后编辑:HangarRashDhanaseelan V 更新时间:11/17/2023 访问量:35

问:

我一直在使用 iOS 中用 Swift 编写的静态库。下面是我一直使用的脚本,用于将库构建成一个胖框架(通用)。

# Type a script or drag a script file from your workspace to insert its path.

#1. After then, make a fresh directory directory 

UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal

# make sure the output directory exists

mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"

# 2. Copy Device (arm64) Framework to a fresh universal folder location 

cp -a "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"

#3. Copy Sim (x86_64) Frameworks's "MyFramework.swiftmodule" folder content and paste it in Fat (x86_64 + arm64) Frameworks's "MyFramework.swiftmodule" folder.

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

# Step 4: Create universal binary file using lipo and place the combined executable in the copied framework directory

lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"

# Step 5: Copy output to the project directory.

cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"

# Step 6: Open Project Directory

open "${PROJECT_DIR}"#1. After then, make a fresh directory directory 

UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal

# make sure the output directory exists

mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"

# 2. Copy Device (arm64) Framework to a fresh universal folder location 

cp -a "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"

#3. Copy Sim (x86_64) Frameworks's "MyFramework.swiftmodule" folder content & paste it in Fat(x86_64 + arm64) Frameworks's  "MyFramework.swiftmodule" folder.

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

# Step 4: Create universal binary file using lipo and place the combined executable in the copied framework directory

lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"

# Step 5: Copy output to the project directory.

cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"

# Step 6. Open Project Directory

open "${PROJECT_DIR}"

当与 Swift 应用程序集成时,该库可以无缝地用于模拟器和设备。但是,当我尝试在模拟器上的 Objective-C 应用程序中使用该库时,我遇到了一个问题。错误消息指出“不支持的 Swift 架构”。奇怪的是,它在设备上工作正常。

如果有人能就此问题提供帮助,我将不胜感激。提前致谢。

iOS Swift Objective-C iOS框架 IOS

评论


答: 暂无答案