Sau*_*tia 4 cocoa-touch objective-c ios cocoapods podspec
我想创建一个为模拟器和设备构建的输出框架的私有cocoapod.
我创建了一个Cocoa触摸框架,其中我使用Cocoapods集成了CocoaLumberjack.我想为所有可能的架构(模拟器和设备)构建框架.
默认情况下,构建设置,
'Build Active Architectures Only' is set to (Debug - Yes, Release - No).
Run Code Online (Sandbox Code Playgroud)
只要我将debug的此设置设置为No,构建就会失败,并显示以下链接器错误:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_DDASLLogger", referenced from:
objc-class-ref in MyManager.o
"_OBJC_CLASS_$_DDLog", referenced from:
objc-class-ref in MyManager.o
"_OBJC_CLASS_$_DDTTYLogger", referenced from:
objc-class-ref in MyManager.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
我知道CocoaLumberjack仅适用于调试版本中的活动架构.
因此,我将用于调试的Build active架构切换回Yes,并成功构建框架.
为了构建所有架构的框架,我使用在Build阶段添加的运行脚本,该脚本还声称将ios-device和ios-simulator构建合并为一个.这是脚本:
set -e
set +u
# Avoid recursively calling this script.
if [[ $SF_MASTER_SCRIPT_RUNNING ]]
then
exit 0
fi
set -u
export SF_MASTER_SCRIPT_RUNNING=1
# Constants
SF_TARGET_NAME=${PROJECT_NAME}
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# Take build target
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]
then
SF_SDK_PLATFORM=${BASH_REMATCH[1]}
else
echo "Could not find platform name from SDK_NAME: $SDK_NAME"
exit 1
fi
if [[ "$SF_SDK_PLATFORM" = "iphoneos" ]]
then
echo "Please choose iPhone simulator as the build target."
exit 1
fi
IPHONE_DEVICE_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos
# Build the other (non-simulator) platform
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}" -configuration "${CONFIGURATION}" -sdk iphoneos BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}/arm64" SYMROOT="${SYMROOT}" ARCHS='arm64' VALID_ARCHS='arm64' $ACTION
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}" -configuration "${CONFIGURATION}" -sdk iphoneos BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}/armv7" SYMROOT="${SYMROOT}" ARCHS='armv7 armv7s' VALID_ARCHS='armv7 armv7s' $ACTION
# Copy the framework structure to the universal folder (clean it first)
rm -rf "${UNIVERSAL_OUTPUTFOLDER}"
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework"
# Smash them together to combine all architectures
lipo -create "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/arm64/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/armv7/${PROJECT_NAME}.framework/${PROJECT_NAME}" -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}"
Run Code Online (Sandbox Code Playgroud)
我检查运行脚本下方的"仅在安装时运行脚本"复选框.现在我为Generic iOS设备构建框架.现在,我单击Project层次结构中的Products组,选择MyFramework.framework文件,右键单击并选择show in finder.它在finder中打开〜/ Library/Developer/Xcode/DerivedData/MyFramework-dlpsipmxkqmemwgqrfeovlzgyhca/Build/Products/Debug-iphoneos/MyFramework.framework.
Now, I create a new tag 'MyFramework-v0.0.1' containing the commit where I added MyFramework.framework file.
Run Code Online (Sandbox Code Playgroud)
我去〜/ .cocoapods/repos/MyRepoName /并创建一个podspec文件MyFramework.podspec如下:
Pod::Spec.new do |s|
s.name = "MyFramework"
s.version = "0.0.1"
s.summary = "A pod for MyFramework"
s.description = "A pod designed for MyFramework"
s.homepage = "My_Private_Repo_Path"
s.license = { :type => "MIT", :file => "FILE_LICENSE" }
s.authors = { "My_Username" => "my_email_address"
}
s.platform = :ios, "8.0"
s.ios.deployment_target = "8.0"
s.source = { :git => "My_Private_Repo_Path", :tag => 'MyFramework-v'+String(s.version) }
s.requires_arc = true
s.vendored_frameworks = "MyFramework.framework"
s.dependency "CocoaLumberjack"
end
Run Code Online (Sandbox Code Playgroud)
现在,当我在终端中运行以下命令时:
pod repo push MyRepoName MyFramework.podspec
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Validating spec
-> MyFramework (0.0.1)
- ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use ` --verbose` for more information.
- NOTE | [iOS] xcodebuild: ld: warning: ignoring file MyFramework/MyFramework.framework/MyFramework, missing required architecture i386 in file MyFramework/MyFramework.framework/MyFramework (2 slices)
- NOTE | [iOS] xcodebuild: ld: warning: ignoring file MyFramework/MyFramework.framework/MyFramework, missing required architecture x86_64 in file MyFramework/MyFramework.framework/MyFramework (2 slices)
- NOTE | [iOS] xcodebuild: fatal error: lipo: -remove's specified would result in an empty fat file
[!] The `MyFramework.podspec` specification does not validate.
Run Code Online (Sandbox Code Playgroud)
如何为所有设备和模拟器构建可可触摸框架,这取决于使用cocoapods添加的另一个框架(CocoaLumberjack)?我需要创建一个输出框架的私有pod.
Sau*_*tia 37
所以基本上我发现我只需要遵循这些简单的步骤.
1. Create a cocoa touch framework.
2. Set bitcode enabled to No.
3. Select your target and choose edit schemes. Select Run and choose Release from Info tab.
4. No other setting required.
5. Now build the framework for any simulator as simulator runs on x86 architecture.
6. Click on Products group in Project Navigator and find the .framework file.
7. Right click on it and click on Show in finder. Copy and paste it in any folder, I personally prefer the name 'simulator'.
8. Now build the framework for Generic iOS Device and follow the steps 6 through
9. Just rename the folder to 'device' instead of 'simulator'.
10. Copy the device .framework file and paste in any other directory. I prefer the immediate super directory of both.
Run Code Online (Sandbox Code Playgroud)
所以目录结构现在变成:
- Desktop
- device
- MyFramework.framework
- simulator
- MyFramework.framework
- MyFramework.framework
Run Code Online (Sandbox Code Playgroud)
现在打开终端并cd到桌面.现在开始输入以下命令:
lipo -create 'device/MyFramework.framework/MyFramework' 'simulator/MyFramework.framework/MyFramework' -output 'MyFramework.framework/MyFramework'
Run Code Online (Sandbox Code Playgroud)
就是这样.在这里,我们合并MyFramework.framework中存在的MyFramework二进制文件的模拟器和设备版本.我们获得了一个通用框架,可以为包括模拟器和设备在内的所有架构构建.
现在,为这个框架创建一个pod没有任何区别.它就像一个魅力.还请注意,还有可用的运行脚本来实现相同的功能,但我花了很多时间来寻找正确的脚本.所以我建议你使用这种方法.
| 归档时间: |
|
| 查看次数: |
5792 次 |
| 最近记录: |