Xcode新增Shell指令碼打包靜態庫和動態庫

weixin_34320159發表於2017-08-04

1.靜態庫

if [ "${ACTION}" = "build" ]

then

#要build的target名

target_Name=${PROJECT_NAME}

echo "target_Name=${target_Name}"

#build之後的資料夾路徑

build_DIR=${SRCROOT}/build

echo "build_DIR=${build_DIR}"

#真機build生成的標頭檔案的資料夾路徑

DEVICE_DIR_INCLUDE=${build_DIR}/Release-iphoneos/include/${PROJECT_NAME}

echo "DEVICE_DIR_INCLUDE=${DEVICE_DIR_INCLUDE}"

#真機build生成的.a檔案路徑

DEVICE_DIR_A=${build_DIR}/Release-iphoneos/lib${PROJECT_NAME}.a

echo "DEVICE_DIR_A=${DEVICE_DIR_A}"

#模擬器build生成的.a檔案路徑

SIMULATOR_DIR_A=${build_DIR}/Release-iphonesimulator/lib${PROJECT_NAME}.a

echo "SIMULATOR_DIR_A=${SIMULATOR_DIR_A}"

#目標資料夾路徑

INSTALL_DIR=${SRCROOT}/Products/${PROJECT_NAME}

echo "INSTALL_DIR=${INSTALL_DIR}"

#目標標頭檔案資料夾路徑

INSTALL_DIR_Headers=${SRCROOT}/Products/${PROJECT_NAME}/Headers

echo "INSTALL_DIR_Headers=${INSTALL_DIR_Headers}"

#目標.a路徑

INSTALL_DIR_A=${SRCROOT}/Products/${PROJECT_NAME}/lib${PROJECT_NAME}.a

echo "INSTALL_DIR_A=${INSTALL_DIR_A}"

#判斷build資料夾是否存在,存在則刪除

if [ -d "${build_DIR}" ]

then

rm -rf "${build_DIR}"

fi

#判斷目標資料夾是否存在,存在則刪除該資料夾

if [ -d "${INSTALL_DIR}" ]

then

rm -rf "${INSTALL_DIR}"

fi

#建立目標資料夾

mkdir -p "${INSTALL_DIR}"

#build之前clean一下

xcodebuild -target ${target_Name} clean

#模擬器build

xcodebuild -target ${target_Name} -configuration Release -sdk iphonesimulator

#真機build

xcodebuild -target ${target_Name} -configuration Release -sdk iphoneos

#複製標頭檔案到目標資料夾

cp -R "${DEVICE_DIR_INCLUDE}" "${INSTALL_DIR_Headers}"

#合成模擬器和真機.a包

lipo -create "${DEVICE_DIR_A}" "${SIMULATOR_DIR_A}" -output "${INSTALL_DIR_A}"

#開啟目標資料夾

open "${INSTALL_DIR}"

fi



2.動態庫

if [ "${ACTION}" = "build" ]

then

#要build的target名

target_Name=${PROJECT_NAME}

echo "target_Name=${target_Name}"

#build之後的資料夾路徑

build_DIR=${SRCROOT}/build

echo "build_DIR=${build_DIR}"

#真機build生成的.framework檔案路徑

DEVICE_DIR_A=${build_DIR}/Release-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}

echo "DEVICE_DIR_A=${DEVICE_DIR_A}"

#模擬器build生成的.framework檔案路徑

SIMULATOR_DIR_A=${build_DIR}/Release-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}

echo "SIMULATOR_DIR_A=${SIMULATOR_DIR_A}"

#目標資料夾路徑

INSTALL_DIR=${SRCROOT}/Products/${PROJECT_NAME}

echo "INSTALL_DIR=${INSTALL_DIR}"

#目標.framework路徑

INSTALL_DIR_A=${SRCROOT}/Products/${PROJECT_NAME}/${PROJECT_NAME}

echo "INSTALL_DIR_A=${INSTALL_DIR_A}"

#判斷build資料夾是否存在,存在則刪除

if [ -d "${build_DIR}" ]

then

rm -rf "${build_DIR}"

fi

#判斷目標資料夾是否存在,存在則刪除該資料夾

if [ -d "${INSTALL_DIR}" ]

then

rm -rf "${INSTALL_DIR}"

fi

#建立目標資料夾

mkdir -p "${INSTALL_DIR}"

#build之前clean一下

xcodebuild -target ${target_Name} clean

#模擬器build

xcodebuild -target ${target_Name} -configuration Release -sdk iphonesimulator

#真機build

xcodebuild -target ${target_Name} -configuration Release -sdk iphoneos

#合成模擬器和真機.framework包

lipo -create "${DEVICE_DIR_A}" "${SIMULATOR_DIR_A}" -output "${INSTALL_DIR_A}"

#開啟目標資料夾

open "${INSTALL_DIR}"

fi

然後在把生成的執行檔案手動替換掉 模擬器或真機的xxxx.framework/xxxx



如果你會寫Shell指令碼也可以完善一下直接用指令碼拷貝到xxx.framework中

相關文章