gpt4 book ai didi

ios - 基于 pod 的 Swift 通用框架

转载 作者:可可西里 更新时间:2023-11-01 00:40:11 24 4
gpt4 key购买 nike

我正在开发一个依赖于 Alamofire 的小型 Swift 框架。我将它用作属于同一工作区的应用程序的嵌入式框架,并且运行良好。

当我想构建一个具有聚合目标的通用框架时,问题就出现了。然后,在执行生成框架的脚本时失败并显示消息 No such module 'Alamofire'。 ,指的是 import Alamofire在我的一个源文件中。

这是我的 Pod 文件:

platform :ios, '9.0'
use_frameworks!
inhibit_all_warnings!

target 'FSIBackend' do
pod 'SwiftLint'
pod 'Alamofire'
pod 'SwiftyJSON'
end

这是生成框架的脚本。它适用于没有 Pod 依赖项的其他框架,所以我认为没问题:

set -e

# Setup
FRAMEWORK_NAME="${1}"
BUILD_DIR="${SRCROOT}/build"
OUTPUT_DIR="${HOME}/Desktop/"
OUTPUT="${OUTPUT_DIR}/${FRAMEWORK_NAME}.framework"

rm -rf "${BUILD_DIR}"
rm -rf "${OUTPUT}"
mkdir -p "${OUTPUT_DIR}"

# Build
xcodebuild -target "${FRAMEWORK_NAME}" -configuration Release -arch arm64 -arch armv7 -arch armv7s only_active_arch=no defines_module=yes -sdk "iphoneos"
xcodebuild -target "${FRAMEWORK_NAME}" -configuration Release -arch x86_64 -arch i386 only_active_arch=no defines_module=yes -sdk "iphonesimulator"

# Copy the device version of framework to output.
cp -r "${BUILD_DIR}/Release-iphoneos/${FRAMEWORK_NAME}.framework" "${OUTPUT}"

# Replace the framework executable within the framework with a new version created by merging the device and simulator frameworks' executables with lipo.
lipo -create -output "${OUTPUT}/${FRAMEWORK_NAME}" "${BUILD_DIR}/Release-iphoneos/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${BUILD_DIR}/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}"

# Copy the Swift module mappings for the simulator into the framework. The device mappings already exist from step 6.
cp -r "${BUILD_DIR}/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule/" "${OUTPUT}/Modules/${FRAMEWORK_NAME}.swiftmodule"

# Delete build.
rm -rf "${BUILD_DIR}"

问题是我不知道如何根据 Alamofire 构建我的框架。我是否必须为我的框架创建一个 podspec 并通过 CocoaPods 使用它?这是我第一次创建一个依赖于 pod 的通用框架,所以我不知道我是否在做一些不可能的事情。

非常感谢。

最佳答案

在考虑了@mag_zbc 的建议后,终于完成了,谢谢。

我不得不这样修改框架生成:

set -e

# Setup
WORKSPACE="${1}"
FRAMEWORK_NAME="${2}"
BUILD_DIR="${SRCROOT}/build"
OUTPUT_DIR="${HOME}/Desktop/"
OUTPUT="${OUTPUT_DIR}/${FRAMEWORK_NAME}.framework"
CONFIGURATION="${CONFIGURATION}"

rm -rf "${BUILD_DIR}"
rm -rf "${OUTPUT}"
mkdir -p "${OUTPUT_DIR}"

# Build the framework for device and for simulator (using all needed architectures).
xcodebuild -workspace "${WORKSPACE}" -scheme "${FRAMEWORK_NAME}" -configuration ${CONFIGURATION} -arch x86_64 -arch i386 only_active_arch=no defines_module=yes -sdk "iphonesimulator" clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator
xcodebuild -workspace "${WORKSPACE}" -scheme "${FRAMEWORK_NAME}" -configuration ${CONFIGURATION} -arch arm64 -arch armv7 -arch armv7s only_active_arch=no defines_module=yes -sdk "iphoneos" clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos

# Copy the device version of framework to output.
cp -r "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework" "${OUTPUT}"

# Replace the framework executable within the framework with a new version created by merging the device and simulator frameworks' executables with lipo.
lipo -create -output "${OUTPUT}/${FRAMEWORK_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}"

# Copy the Swift module mappings for the simulator into the framework. The device mappings already exist from step 6.
cp -r "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule/" "${OUTPUT}/Modules/${FRAMEWORK_NAME}.swiftmodule"

# Delete build.
rm -rf "${BUILD_DIR}"

生成并添加到消费者应用程序后,唯一剩下要做的就是在消费者应用程序中使用 Cocoapods 来获取 Alamofire 和 SwiftyJSON。

关于ios - 基于 pod 的 Swift 通用框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45192464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com