iOS开发之dyld: Library not loaded: Reason: image not found错误

今天添加第三方framework之后出现如下错误

dyld: Library not loaded: @rpath/FBSDKCoreKit.framework/FBSDKCoreKit
  Referenced from: /Users/hecanlin/Library/Developer/CoreSimulator/Devices/3BF8EFEC-EE8A-417C-918C-54E33800B316/data/Containers/Bundle/Application/BAA178E8-8263-420F-B8F8-4FDEDA9DF1BA/IF-Quick.app/IF-Quick
  Reason: image not found

解决方法(如下图,添加framework到Build Phases下的Copy Files)

但需要注意的是可能会遇到打包报错,打包没报错则不用看后面的步骤啦

解决方法

在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

 

posted @ 2020-04-23 17:44  kawerd  阅读(1846)  评论(0编辑  收藏  举报