模块拆分(二)

2020-04-14  本文已影响0人  S_Lyu

第二步:新建一个子工程的bundle

1.新建bundle工程:

  • 在指定子模块下新增target


    image.png
  • 新增bundle target


    image.png

2.修改bundle的设置:

  • 因为bundle默认是macOS的所以要改成iOS
    需要将FrameworkBundle->Build Settings->Architectures->Base SDK改为iOS
    image.png
  • 关闭bitcode
    FrameworkBundle->Build Settings->Build Options->Enable Bitcode设置为NO.
    image.png
  • 设置开发环境
    分别将FrameworkBundle->Build Settings->Deployment下的iOS Deployment Target和macOS Deployment Target,选择为你最低支持的版本
    image.png
  • 设置
    将FrameworkBundle->Build Settings->User-Defined->COMBINE_HIDPI_IMAGES设置为NO
    注1:此属性在Base SDK 选择了iOS SDK之后才会出现
    注2:若不设置此项,bundle中的png图片经过编译打包会变成tiff的文件

    image.png
  • 添加资源
    常用资源如.png/.xib等
    image.png

3.添加依赖

  • 将bundle添加为子工程的依赖
    为了编译framework前自动编译bundle
    image.png
  • 将子工程添加为主工程的依赖(上一篇文章已做此操作)
    略...

4.子工程添加脚本

  • 创建脚本


    image.png
  • 将下面脚本内容复制,并做如下修改:

共两处:
1.子工程名称
2.bundle名称

image.png
//脚本内容
//脚本作用:编译子工程时,一并打包bundle,并导出至指定文件夹
#指定 FrameWork 与 bundle的target名称
Bundle_NAME="XHCommonBusinessBundle"

#打包结果存储地址
Products_DIR=${SRCROOT}/Products/

#定义framework与bundle存储路径
Bundle_INSTALL_DIR=${SRCROOT}/Products/${Bundle_NAME}.bundle


#将要生成包的路径
WRK_DIR=build

Bundle_SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${Bundle_NAME}.bundle
Bundle_IPHONEOS_DIR=${WRK_DIR}/Release-iphoneos/${Bundle_NAME}.bundle

#清理下工程
# -configuration ${CONFIGURATION}
# Clean and Building both architectures.

if [ "${CONFIGURATION}" == "Debug" ]; then
xcodebuild -configuration "Release" -target "${Bundle_NAME}" -sdk iphoneos clean build
xcodebuild -configuration "Release" -target "${Bundle_NAME}" -sdk iphonesimulator clean build

#清除下存储路径下的旧包

if [ -d "${Bundle_INSTALL_DIR}" ]
then
rm -rf "${Bundle_INSTALL_DIR}"
fi
mkdir -p "${Bundle_INSTALL_DIR}"

#拷贝bundle
cp -R "${Bundle_SIMULATOR_DIR}" "${Products_DIR}/"


else

xcodebuild -configuration "Release" -target "${Bundle_NAME}" -sdk iphoneos clean build
#清除下存储路径下的旧包

if [ -d "${Bundle_INSTALL_DIR}" ]
then
rm -rf "${Bundle_INSTALL_DIR}"
fi
mkdir -p "${Bundle_INSTALL_DIR}"

#拷贝bundle
cp -R "${Bundle_IPHONEOS_DIR}" "${Products_DIR}/"

fi

#判断release
#移除模拟器架构

rm -r "${WRK_DIR}"

  • 脚本执行后会自动生成"胖bundle"


    image.png
  • 将bundle拖入(引用至)主工程


    image.png

END

上一篇 下一篇

猜你喜欢

热点阅读