在项目中,都会使用到图片
、xib
、storyboatd
等资源,为了便于管理,常会统一放到bundle
中;
在SDK开发中,SDK内部使用的资源,都会创建一个bundle进行统一管理;
打包SDK工程时,代码打包成.framework
,资源用.bundle
;
一、创建Bundle
- 选择`Bundle`,创建时,project选择<开发SDK的project>;
- 命名为`<xxx>Resource`,这里使用`SDKProjectResource`名字;
![](https://img.haomeiwen.com/i1463300/55f698feee4d4c1a.png)
![](https://img.haomeiwen.com/i1463300/ff3ffa5770400c55.png)
![](https://img.haomeiwen.com/i1463300/f9ab28f673adc1cf.png)
二、设置
-
修改
Base SDK
为 iOS,否则编译无法通过;
1- Base SDK
-
修改
COMBINE_HIDPI_IMAGES
为NO
,否则Bundle中的图片就是tff格式
;
2- COMBINE_HIDPI_IMAGES
-
删除
安装路径Installation Directory
的值;作为资源包,不需要安装,只要编译就好;
Skip Install
为Yes;
3- Installation Directory
-
Enable Bitcode
设置为No
;
4- Enable Bitcode
-
Supports Mac Catalyst
设置为No
;
5- Supports Mac Catalyst
-
Code Signing Identify
改成iOS developer
;
6- code signing identify
-
在
Scheme
中,将Run
改成Release
;
7- Run
三、添加脚本,填写生成资源.bundle插入路径;
在SDK工程路径,创建一个Products文件夹
,之后生成的bundle文件,会被存储到这个文件夹中;
![](https://img.haomeiwen.com/i1463300/aad99402bbc48902.png)
![](https://img.haomeiwen.com/i1463300/614de222fadbbc2c.png)
- 脚本源码:
# Type a script or drag a script file from your workspace to insert its path.
if [ "${ACTION}" = "build" ]
then
INSTALL_DIR=${SRCROOT}/Products/${PROJECT_NAME}Resource.bundle
DEVICE_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}Resource.bundle
SIMULATOR_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}Resource.bundle
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
echo 拷贝bundle包 ${DEVICE_DIR}
cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"
#open "${DEVICE_DIR}"
open "${SRCROOT}/Products"
fi
-
生成的文件:
指定生成路径.png
四、创建放资源Resources的文件夹,关联bundle
- 在bundle中生成图片、字体:
- 在SDK开发目录创建`Resources文件夹`,所有图片、字体等资源都放在其中;
- 将Resources手动导入项目时,`只勾选bundle`;
- `新增、删除`图片,选中SDKProjectResource对应的target,编译成功后,会更新到.bundle中;
![](https://img.haomeiwen.com/i1463300/19444e62491c8d7a.png)
![](https://img.haomeiwen.com/i1463300/46bcbecf14652568.png)
- 2- 在bundle中生成xib、storyboard:
- 如果资源是`xib、storyboard`,不方便放到Resources目录中,在创建时,需要`勾选`对应的bundle;
- 选择SDKProjectResource对应的target,`编译成功后`,这个xib就会在`.bundle`中生成`对应的nib`;
![](https://img.haomeiwen.com/i1463300/826355b0454db172.png)
![](https://img.haomeiwen.com/i1463300/17373dae5ac42a08.png)
五、生成.bundle文件
选中SDKProjectResource的Target,device选择Any iOS Device (arm64 arm 7)
编译成功后,就会生成SDKProjectResource.bundle文件
;
![](https://img.haomeiwen.com/i1463300/2aedcaf64c7b9b72.png)
六、将.bundle文件导入主工程
- 将`Products`文件夹中的`SDKProjectResource.bundle`,拖到工程目录下,选择`Create folder references`;
- 在SDK项目中的Resources目录下添加新增/删除图片、字体文件,或创建新的xib文件,
选择SDKProjectResource对应的target,编译成功后,会同步到.bundle中,在`主工程`就可以使用.bundle中的资源;
![](https://img.haomeiwen.com/i1463300/5234c6267bc2b14b.png)
![](https://img.haomeiwen.com/i1463300/68f132589a0ec3bd.png)
细节注意点:
1- 上传ipa,.bundle中报错
![](https://img.haomeiwen.com/i1463300/61db8df4c3b7677e.png)
场景:
依赖SDK,pod集成到项目中,上传ipa到App Connection、TestFlight
时,会报错;
- Xcode报错信息
App Store Connect Operation Error
ERROR ITMS-90166: "Missing Code Signing Entitlements. No entitlements found in bundle 'com.db. SDKProjectResource' for executable 'Payload/SDKDev.app/SDKProjectResource.bundle/SDKProjectResource."
- 问题出现原因:
- .bundle中包含了可执行文件;
- 事实上,.bundle里面的可执行文件是没有必要的;
- 解决方案:
- 在SDKResource这个target里`build setting`中,设置`Versioning System为None`;
- 在SDKResource这个target里的`info`中,需要删除掉`Executable file`;
- 在SDKResource文件夹的`info.plist`中,`删除Executable file`,可以搜索`CFBundleExecutable`;
- 在和.bundle文件关联的Resource文件加下,查看有没包含`可执行文件exec`,如果有,删除掉;
![](https://img.haomeiwen.com/i1463300/1ad6ebd3bae6350a.png)
![](https://img.haomeiwen.com/i1463300/7b1db311102b3b45.png)
![](https://img.haomeiwen.com/i1463300/b2c0596d862dc9a8.png)
![](https://img.haomeiwen.com/i1463300/d4d166472d5d0603.png)
网友评论