Carthage我是通过Homebrew来安装的
brew install carthage
1.终端进入项目.xcodeproj
所在的文件夹,创建Cartfile
touch Cartfile
2.编辑Cartfile
,示例如下
#Swift
github "onevcat/Kingfisher" ~> 4.0
github "Alamofire/Alamofire" ~> 4.7
github "danielgindi/Charts" ~> 3.1.1
github "SnapKit/SnapKit" ~> 4.0.0
github "alibaba/HandyJSON" ~> 4.1.1
github "SwiftyJSON/SwiftyJSON" ~> 4.0
github "ReactiveX/RxSwift" ~> 4.0
github "Moya/Moya"
#Objective-C
github "SVProgressHUD/SVProgressHUD"
3.编辑好Cartfile
,通过命令行安装框架
Carthage update
//或者指定平台安装
Carthage update --platform iOS
4.安装完成后多出一个Carthage文件夹
-
Build
:编译出来的framework
二进制代码库 -
Checkouts
:从github或其他源获取的源代码
5.将编译好的框架集成到项目中,打开项目,前往Target -> Build Phases -> Link Library with Libraries
,添加Carthage/Build
目录中的.framework
6.添加编译的脚本(该脚本文件保证在提交归档时会对相关文件和dSYM
进行复制)
-
添加脚本
/usr/local/bin/Carthage copy-frameworks
-
添加Input Files(如:
WX20180531-174531.png$(SRCROOT)/Carthage/Build/iOS/Alamofire.framework
),用到多少个框架,就添加多少
7.更新框架,编辑好Cartfile
后,执行命令行
Carthage update
//或者指定平台安装
Carthage update --platform iOS
//或者指定框架名称
Carthage update Alamofire
8.如果使用Realm数据库,或者为了上架少点坑,建议加上下面这个脚本(直接复制使用即可)
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
EXTRACTED_ARCHS=()
for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done
echo "Merging extracted architectures: ${ARCHS}"
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
rm "${EXTRACTED_ARCHS[@]}"
echo "Replacing original executable with thinned version"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"
done
WX20180531-180927.png
网友评论