Carthage的使用

2018-05-31  本文已影响104人  帆动世界

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文件夹

5.将编译好的框架集成到项目中,打开项目,前往Target -> Build Phases -> Link Library with Libraries,添加Carthage/Build目录中的.framework

.framework

6.添加编译的脚本(该脚本文件保证在提交归档时会对相关文件和dSYM进行复制)

WX20180531-173915.png

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
上一篇下一篇

猜你喜欢

热点阅读