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" echo "Extracting to $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[@]}" echo "merged to ${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
後續:以上腳本存在問題,具體以下:xcode
fatal error: lipo: -extract armv7 specified but fat file: /Users/yaozhaofeng/Library/Developer/Xcode/DerivedData/TKLobby-hhxvnfiigsbhwbairrsjlyhytkaa/Build/Products/Debug-iphoneos/TKLobby.app/Frameworks/AliThirdparty.framework/AliThirdparty does not contain that architecture
緣由是xcode並不會每次編譯的時候都embeded內置的framwork,第一次編譯後已經將framwork修改成只有某一種arm的版本,等下次編譯另外一種arm的時候,就會發現找不到對應的arm了。架構
針對第一個問題,有網友進行了補充以下,可是該方案目前看依然沒法解決問題2app
後續:找到問題2解決方案: Run Script的執行順序,取決於它在build phases中添加的位置,針對問題2,將腳本位置放到Embed Frameworks以後便可iphone
cho "Target architectures: $ARCHS" APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}" 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" echo $(lipo -info "$FRAMEWORK_EXECUTABLE_PATH") FRAMEWORK_TMP_PATH="$FRAMEWORK_EXECUTABLE_PATH-tmp" # remove simulator's archs if location is not simulator's directory case "${TARGET_BUILD_DIR}" in *"iphonesimulator") echo "No need to remove archs" ;; *) if $(lipo "$FRAMEWORK_EXECUTABLE_PATH" -verify_arch "i386") ; then lipo -output "$FRAMEWORK_TMP_PATH" -remove "i386" "$FRAMEWORK_EXECUTABLE_PATH" echo "i386 architecture removed" rm "$FRAMEWORK_EXECUTABLE_PATH" mv "$FRAMEWORK_TMP_PATH" "$FRAMEWORK_EXECUTABLE_PATH" fi if $(lipo "$FRAMEWORK_EXECUTABLE_PATH" -verify_arch "x86_64") ; then lipo -output "$FRAMEWORK_TMP_PATH" -remove "x86_64" "$FRAMEWORK_EXECUTABLE_PATH" echo "x86_64 architecture removed" rm "$FRAMEWORK_EXECUTABLE_PATH" mv "$FRAMEWORK_TMP_PATH" "$FRAMEWORK_EXECUTABLE_PATH" fi ;; esac echo "Completed for executable $FRAMEWORK_EXECUTABLE_PATH" echo $(lipo -info "$FRAMEWORK_EXECUTABLE_PATH") done