lipo 命令

作者: 大风天上来 | 来源:发表于2022-09-02 15:02 被阅读0次

    1.查看静态库支持的CPU架构

    lipo -info libname.a(或者libname.framework/libname)

    2. 合并静态库

    lipo -create 静态库存放路径1 静态库存放路径2 -output 整合后存放的路径

    lipo -create libname-armv7.a libname-armv7s.a libname-i386.a -output libname.a
    或者
    lipo -create arm7/util.framework/util i386/util.framework/util -output util.framework

    3. 静态库拆分

    lipo 静态库源文件路径 -thin CPU架构名称 -output 拆分后文件存放路径
    架构名为armv7/armv7s/arm64等,与lipo -info 输出的架构名一致
    lipo libname.a -thin armv7 -output libname-armv7.a

    4.移除

    使用lipo -info 可以查看包含的架构
    lipo -info AipBase.framework/AipBase

    Architectures in the fat file: AipBase are: i386 x86_64 armv7 armv7s arm64
    

    移除x86_64, i386

    lipo -remove x86_64 AipBase.framework/AipBase -o AipBase.framework/AipBase
    lipo -remove i386 AipBase.framework/AipBase -o AipBase.framework/AipBase
    lipo -remove x86_64 AipOcrSdk.framework/AipOcrSdk -o AipOcrSdk.framework/AipOcrSdk
    lipo -remove i386 AipOcrSdk.framework/AipOcrSdk -o AipOcrSdk.framework/AipOcrSdk

    再次查看

    lipo -info AipBase.framework/AipBase # Architectures in the fat file: AipBase are: armv7 armv7s arm64

    5.扩展:

    发布时,移除特定framework的架构

    if [ $CONFIGURATION == Debug ]; then
        echo "调试的时候不做处理"
        exit
    fi
    
    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"
    
    
    if [ $FRAMEWORK_EXECUTABLE_NAME != XXXXXX ]; then
        #不用处理的库  
        continue
    fi
    
    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
    

    相关文章

      网友评论

        本文标题:lipo 命令

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