【问题标题】:iOS Universal FrameworkiOS 通用框架
【发布时间】:2024-04-23 01:50:02
【问题描述】:

您好,我正在尝试在 iOS 中制作我的第一个框架。找了几天终于搞定了,我用的是这个Tutorial,非常简单直接。

但我在理解一件事时遇到了一点问题。我使用该框架的应用程序可以使用真实设备构建和运行,但不能使用模拟器

Aggregate Target 脚本将两个静态库(模拟器和设备)放在一个二进制文件中:

xcrun lipo -create "${BUILT_PRODUCTS_DIR}/${SF_EXECUTABLE_PATH}" "${SF_OTHER_BUILT_PRODUCTS_DIR}/${SF_EXECUTABLE_PATH}" -output "${BUILT_PRODUCTS_DIR}/${SF_WRAPPER_NAME}/Versions/A/${SF_TARGET_NAME}"

我构建了聚合器目标并转到我的 Products 文件夹,其中有两个文件夹:

我正在使用 Debug-iphoneos 内部的框架。 不应该只有一个文件夹,因为我编译到一个通用框架? 我错过了什么或做错了什么? 提前谢谢你。

【问题讨论】:

  • 我通过添加脚本创建了通用静态库。更多*.com/questions/3520977/…
  • 我已经尝试过该脚本,但给了我一个错误,命令 /bin/sh 失败,退出代码为 1
  • 看看接受的答案,其实有很多正确答案可供选择
  • 作为替代解决方案,请检查此回购:github.com/gurhub/universal-framework

标签: ios objective-c xcode static-libraries


【解决方案1】:

我用它来构建 Dropbox 通用框架。更改产品和版本信息以适应您的需求。

# Sets the target folders and the final framework product.
FMK_NAME=DropboxSDK
FMK_VERSION=5.5

# Install dir will be the final output to the framework.
# The following line create it in the root folder of the current project.
INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework

# Working dir will be deleted after the framework creation.
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework

# Building both architectures.
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator

# Cleaning the oldest.
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi

# Creates and renews the final product folder.
mkdir -p "${INSTALL_DIR}"
mkdir -p "${INSTALL_DIR}/Versions"
mkdir -p "${INSTALL_DIR}/Versions/${FMK_VERSION}"
mkdir -p "${INSTALL_DIR}/Versions/${FMK_VERSION}/Resources"
mkdir -p "${INSTALL_DIR}/Versions/${FMK_VERSION}/Headers"

# Creates the internal links.
# It MUST uses relative path, otherwise will not work when the folder is copied/moved.
ln -s "${FMK_VERSION}" "${INSTALL_DIR}/Versions/Current"
ln -s "Versions/Current/Headers" "${INSTALL_DIR}/Headers"
ln -s "Versions/Current/Resources" "${INSTALL_DIR}/Resources"
ln -s "Versions/Current/${FMK_NAME}" "${INSTALL_DIR}/${FMK_NAME}"

# Copies the headers and resources files to the final product folder.
cp -R "${DEVICE_DIR}/Headers/" "${INSTALL_DIR}/Versions/${FMK_VERSION}/Headers/"
cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/Versions/${FMK_VERSION}/Resources/"

# Removes the binary and header from the resources folder.
rm -r "${INSTALL_DIR}/Versions/${FMK_VERSION}/Resources/Headers" "${INSTALL_DIR}/Versions/${FMK_VERSION}/Resources/${FMK_NAME}"

# Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.
lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/Versions/${FMK_VERSION}/${FMK_NAME}"

rm -r "${WRK_DIR}"

【讨论】:

  • 如果我的框架名称是 abc.framework 那么要传递什么?我必须在上面的脚本中改变什么