Flutter_Library not loaded: @rpath/App.framework/App

问题描述

更新了FlutterSDK,模拟器运行无问题,真机运行崩溃

报错结果如下:

dyld[15588]: 

Library not loaded: @rpath/App.framework/App
 
Referenced from: 
/private/var/containers/Bundle/Application/42B64C9D-DDC4-4DF3-9287-068E4EE2EBDB/Merchant.app/Merchant
  
Reason: tried: 
'/usr/lib/swift/App.framework/App' (no such file), 
'/usr/lib/swift/App.framework/App' (no such file), 
'/private/var/containers/Bundle/Application/42B64C9D-DDC4-4DF3-9287-068E4EE2EBDB/Merchant.app/Frameworks/App.framework/App' (no such file), 
'/private/var/containers/Bundle/Application/42B64C9D-DDC4-4DF3-9287-068E4EE2EBDB/Merchant.app/Frameworks/App.framework/App' (no such file), 
'/private/var/containers/Bundle/Application/42B64C9D-DDC4-4DF3-9287-068E4EE2EBDB/Merchant.app/Frameworks/App.framework/App' (no such file), 
'/usr/lib/swift/App.framework/App' (no such file), 
'/usr/lib/swift/App.framework/App' (no such file), 
'/private/var/containers/Bundle/Application/42B64C9D-DDC4-4DF3-9287-068E4EE2EBDB/Merchant.app/Frameworks/App.framework/App' (no such file), 
'/private/var/containers/Bundle/Application/42B64C9D-DDC4-4DF3-9287-068E4EE2EBDB/Merchant.app/Frameworks/App.framework/App' (no such file), 
'/private/var/containers/Bundle/Application/42B64C9D-DDC4-4DF3-9287-068E4EE2EBDB/Merchant.app/Frameworks/App.framework/App' (no such file), 
'/System/Library/Frameworks/App.framework/App' (no such file)

原因分析:

经过排查,发现是FlutterApp.framework没有导入


解决方案1:

打开 Pods-xx-frameworks.sh,然后添加以下代码

install_framework "${PODS_ROOT}/../merchant_flutter/.ios/Flutter/App.framework"
  • ../merchant_flutter这段路径可以复制 Podfileflutter_application_path

  • xx:工程名称

  • 参考链接

  • 此种解决方式存在弊端:每次工程进行pod install以后Pods-xx-frameworks.sh 文件将会被重置,添加的代码会被删除。可以采用解决方案2

解决方案2:

  • 打开 TARGETS -> Build Phases -> + -> New Run Script Phase
  • 添加指令
install_framework()
{
    
    
  if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then
    local source="${BUILT_PRODUCTS_DIR}/$1"
  elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then
    local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")"
  elif [ -r "$1" ]; then
    local source="$1"
  fi

  local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"

  if [ -L "${source}" ]; then
    echo "Symlinked..."
    source="$(readlink "${
    
    source}")"
  fi

  if [ -d "${source}/${BCSYMBOLMAP_DIR}" ]; then
    # Locate and install any .bcsymbolmaps if present, and remove them from the .framework before the framework is copied
    find "${source}/${BCSYMBOLMAP_DIR}" -name "*.bcsymbolmap"|while read f; do
      echo "Installing $f"
      install_bcsymbolmap "$f" "$destination"
      rm "$f"
    done
    rmdir "${source}/${BCSYMBOLMAP_DIR}"
  fi

  # Use filter instead of exclude so missing patterns don't throw errors.
  echo "rsync --delete -av "${
    
    RSYNC_PROTECT_TMP_FILES[@]}" --links --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\""
  rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}"

  local basename
  basename="$(basename -s .framework "$1")"
  binary="${destination}/${basename}.framework/${basename}"

  if ! [ -r "$binary" ]; then
    binary="${destination}/${basename}"
  elif [ -L "${binary}" ]; then
    echo "Destination binary is symlinked..."
    dirname="$(dirname "${
    
    binary}")"
    binary="${dirname}/$(readlink "${
    
    binary}")"
  fi

  # Strip invalid architectures so "fat" simulator / device frameworks work on device
  if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then
    strip_invalid_archs "$binary"
  fi

  # Resign the code if required by the build settings to avoid unstable apps
  code_sign_if_enabled "${destination}/$(basename "$1")"

  # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7.
  if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then
    local swift_runtime_libs
    swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u)
    for lib in $swift_runtime_libs; do
      echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\""
      rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}"
      code_sign_if_enabled "${destination}/${lib}"
    done
  fi
}

install_framework "../merchant_flutter/.ios/Flutter/App.framework"

猜你喜欢

转载自blog.csdn.net/FlyingKuiKui/article/details/123728932