提交 APP store 報錯 Unsupported Architecture x86
晚上打包歸檔提交APP store,報了3個錯誤一個警告蛤织,如下:
1.ERROR ITMS-90087: "Unsupported Architecture. Your executable contains unsupported architecture '[x86_64, i386]'."
2.ERROR ITMS-90209: "Invalid segment Alignment. The App Binary at SJAPP.app/Frameworks/PLPlayerKit.framework/Buy does not have proper segment alignment. Try rebuilding the app with the latest xcode version."
3.ERROR ITMS-90125: "The Binary is invalid. The encryption info in the LC_ENCRYPTION_INFO load command is either missing or invalid, or the binary is already encrypted. This binary does not seem to have been built with Apple's Linker."
4.WARNING ITMS-90080: "The Executable Payload/..../PLPlayerKit.framework is not a Position Independent Executable. Please ensure that ur build settings are configured to create PIE executables."
原因很明顯赴叹,是集成的第三方庫PLPlayerKit.framework的問題。
坑爹玩意指蚜,模擬器乞巧、真機(jī)編譯都正常,就是歸檔提交APP store 報錯摊鸡。
開始漫長的查找原因和解決方法的路程绽媒。。免猾。
原因:
在build setting的link library導(dǎo)入PLPlayerKit.framework后是辕,無法讀取framework中的圖片資源,編譯運行會報如下錯誤:
dyld: Library not loaded: @rpath/PLPlayerKit.framework/PLPlayerKit
Referenced from: /private/var/mobile/Containers/Bundle/Application/107B34E6-F250-4511-9FA9-31526F8E7B84/Test.app/Test
Reason: image not found
這是因為以前iOS上用的framework猎提,實際上都是static library打包成framework結(jié)構(gòu)获三,圖片資源打包為bundle。直接在工程中導(dǎo)入framework和bundle資源即可锨苏。然而動態(tài)包直接將圖片資源編譯打包進(jìn)framework疙教,需要在導(dǎo)入的工程中做下面兩個配置。
- 將包含圖片的framework加載到bundle resource伞租。
- 在build setting界面:target-〉Build Phases -〉左上角+號 -〉New Copy Files Phase 然后在Copy Files下 Destination選擇Frameworks -〉添加動態(tài)庫或在已有的embed frameworks添加該動態(tài)庫贞谓。
到這里L(fēng)ibrary not loaded的錯誤解決了,模擬器和真機(jī)的運行也都一切OK葵诈。
BUT ...
在今天歸檔提交 APP store 時经宏,驗證資源的過程中一下報了開頭那4個錯。驯击。烁兰。
錯誤的原因很明顯,動態(tài)庫不支持 architecture '[x86_64, i386]' 徊都。
解決:
在Build Phases里點擊左上角+號添加Run Script沪斟,然后粘貼如下腳本文件:
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
然后編譯,如果工程中引用的第三方庫比較多的話暇矫,可能會報一堆錯:
例如:
fatal error: lipo: input file (/...Frameworks/*.framework/Bolts) must be a fat file when the -extract option is specified
...
顯然上面的腳本導(dǎo)致的其他的庫文件報錯主之。
解決辦法:
現(xiàn)在只有 PLPlayerKit.framework 這個動態(tài)庫提交時有問題,所以這里把
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
換成
find "$APP_PATH" -name 'PLPlayerKit.framework' -type d | while read -r FRAMEWORK
就可以了李根。
或者槽奕,使用下面的腳本文件,跳過不適用的庫文件:
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"
if [ ! -f "${FRAMEWORK_EXECUTABLE_PATH}" ]; then
continue
fi
if xcrun lipo -info "${FRAMEWORK_EXECUTABLE_PATH}" | grep --silent "Non-fat"; then
echo "Framework non-fat, skipping: $FRAMEWORK_EXECUTABLE_NAME"
continue
fi
echo "Thinning framework $FRAMEWORK_EXECUTABLE_NAME"
EXTRACTED_ARCHS=()
for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
xcrun lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done
echo "Merging extracted architectures: ${ARCHS}"
xcrun 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
Done.