美文网首页
iOS打包脚本移除动态库中的(i386,X64)虚拟机架构

iOS打包脚本移除动态库中的(i386,X64)虚拟机架构

作者: 何景根 | 来源:发表于2020-11-24 17:13 被阅读0次

在你想打包的目标APP中添加RunScript,如下图


image.png

复制下面代码到刚刚新建的RunScript中,其中'XXXX.framework' 为你的动态库,如果有多个动态怎么办呢?你可以把XXXX改成*

APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
find "$APP_PATH" -name 'XXXX.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

image.png

注意的是你的RunScript要一定要按如下图,放在Embed Frameworks后面,否则会失败;原因很简单,因为必需等动态库复制到包里面才能find命令才能正常返回。

image.png

相关文章

网友评论

      本文标题:iOS打包脚本移除动态库中的(i386,X64)虚拟机架构

      本文链接:https://www.haomeiwen.com/subject/sdxwiktx.html