2016-12-06 74 views
1

我嘗試構建靜態框架。未能運行'lipo',Lib具有相同的體系結構

所以我運行下面的命令:

的設備

xcodebuild 
      -project MyAppLib.xcodeproj 
      -sdk iphoneos 
      -target $PRODUCT_FRAMEWORK 
      -configuration Release clean build 

的模擬器

xcodebuild 
      -project MyAppLib.xcodeproj 
      -sdk iphonesimulator 
      -target $PRODUCT_FRAMEWORK 
      -configuration Release clean build 

然而,當我嘗試運行lipo

lipo -create build/Release-iphonesimulator/MyAppLib.framework/MyAppLib 
     build/Release-iphoneos/MyAppLib.framework/MyAppLib 
    -output MyAppLib.framework 

我得到一個錯誤:

fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: build/Release-iphonesimulator/MyAppLib.framework/MyAppLib and build/Release-iphoneos/MyAppLib.framework/MyAppLib have the same architectures (i386) and can't be in the same fat output file

在Xcode我的成功建立,但來自CLI都具有相同的結構。

$ file MyAppLib.framework給我:

MyAppLib.framework: Mach-O universal binary with 4 architectures: [i386: current ar archive] [arm_v7: current ar archive] [x86_64: current ar archive] [arm64] 
MyAppLib.framework (for architecture i386): current ar archive 
MyAppLib.framework (for architecture armv7): current ar archive 
MyAppLib.framework (for architecture x86_64): current ar archive 
MyAppLib.framework (for architecture arm64): current ar archive 

enter image description here


如果我嘗試運行只爲一個平臺,打造的是成功了,但是我得到了奇怪的框架,我甚至不能探索它:

enter image description here

編輯:

多腳本:

set -e 

# If we're already inside this script then die 
if [ -n "$RW_MULTIPLATFORM_BUILD_IN_PROGRESS" ]; then 
exit 0 
fi 
export RW_MULTIPLATFORM_BUILD_IN_PROGRESS=1 

RW_FRAMEWORK_NAME=${PROJECT_NAME} 
RW_INPUT_STATIC_LIB="lib${PROJECT_NAME}.a" 
RW_FRAMEWORK_LOCATION="${BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.framework" 

function build_static_library { 
    # Will rebuild the static library as specified 
    #  build_static_library sdk 
    xcrun xcodebuild -project "${PROJECT_FILE_PATH}" \ 
    -target "${TARGET_NAME}" \ 
    -configuration "${CONFIGURATION}" \ 
    -sdk "${1}" \ 
    ONLY_ACTIVE_ARCH=NO \ 
    BUILD_DIR="${BUILD_DIR}" \ 
    OBJROOT="${OBJROOT}" \ 
    BUILD_ROOT="${BUILD_ROOT}" \ 
    SYMROOT="${SYMROOT}" $ACTION 
} 

function make_fat_library { 
    # Will smash 2 static libs together 
    #  make_fat_library in1 in2 out 
    xcrun lipo -create "${1}" "${2}" -output "${3}" 
} 

# 1 - Extract the platform (iphoneos/iphonesimulator) from the SDK name 
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]; then 
RW_SDK_PLATFORM=${BASH_REMATCH[1]} 
else 
echo "Could not find platform name from SDK_NAME: $SDK_NAME" 
exit 1 
fi 

# 2 - Extract the version from the SDK 
if [[ "$SDK_NAME" =~ ([0-9]+.*$) ]]; then 
RW_SDK_VERSION=${BASH_REMATCH[1]} 
else 
echo "Could not find sdk version from SDK_NAME: $SDK_NAME" 
exit 1 
fi 

# 3 - Determine the other platform 
if [ "$RW_SDK_PLATFORM" == "iphoneos" ]; then 
RW_OTHER_PLATFORM=iphonesimulator 
else 
RW_OTHER_PLATFORM=iphoneos 
fi 

# 4 - Find the build directory 
if [[ "$BUILT_PRODUCTS_DIR" =~ (.*)$RW_SDK_PLATFORM$ ]]; then 
RW_OTHER_BUILT_PRODUCTS_DIR="${BASH_REMATCH[1]}${RW_OTHER_PLATFORM}" 
else 
echo "Could not find other platform build directory." 
exit 1 
fi 

# Build the other platform. 
build_static_library "${RW_OTHER_PLATFORM}${RW_SDK_VERSION}" 

# If we're currently building for iphonesimulator, then need to rebuild 
# to ensure that we get both i386 and x86_64 
if [ "$RW_SDK_PLATFORM" == "iphonesimulator" ]; then 
build_static_library "${SDK_NAME}" 
fi 

# Join the 2 static libs into 1 and push into the .framework 
make_fat_library "${BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \ 
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \ 
"${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}" 

# Ensure that the framework is present in both platform's build directories 
cp -a "${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}" \ 
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.framework/Versions/A/${RW_FRAMEWORK_NAME}" 

# Copy the framework to the user's desktop 
ditto "${RW_FRAMEWORK_LOCATION}" "${HOME}/Desktop/${RW_FRAMEWORK_NAME}.framework" 
+0

我不知道Xcode會用所示的設置吐出所有架構。我懷疑你正在運行一個構建階段腳本。如果不是: 將'i386,x86_64'添加到您有效的體系結構中,並將'僅生成活動體系結構'設置爲'釋放'爲'否'。另外:什麼是'文件'輸出。 Xcode構建或CLI構建?另外,「奇怪的框架」有什麼問題? – shallowThought

+0

@shallowThought我只爲'調試版和發佈版'構建僅有''YES''。我還發布了'多平臺腳本'。我是否需要爲iOS和模擬器運行構建靜態框架?在奇怪的框架下,我的意思是'MyAppLib.framework'是一個文件而不是文件夾。 – snaggs

+0

如果您想在應用程序中使用此庫,您希望能夠在設備上使用它,並且還可以在模擬器中調試您的應用程序。所以是的,你確實想要建立設備和模擬器。 – shallowThought

回答

1

解決方案:

你沒有問題。在構建項目後出現的MyAppLib.framework您的靜態庫,包含所有必需體系結構的片。

構建項目後無需使用lipo

問題:

構建腳本「自動」建立你的目標兩次,一次設備和一次模擬。之後,它使用lipo將兩個構建文物合併到一個胖文庫(make_fat_library)。

然後它會將結果周圍:

#Ensure that the framework is present in both platform's build directories

其結果是,你有一個脂肪LIB框架,建立兩者的目錄。

現在你正試圖合併這兩個(已經合併)脂肪庫。由於兩者都包含相同的切片,因此會出現錯誤。

相關問題