/ 开发笔记

Cocos Creator 报错:The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.

问题背景

Cocos Creator项目,在iOS平台上接入Firebase、Admob等SDK时,使用Cocoapod来添加相关的库,安装一切顺利,但是编译时却报错:

The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.

CocosCreator_cocoapod_build_error

解决方法

  1. 按照提示,运行 “pod install”,或者 “pod update”

发现还是不行。

  1. 仔细观察错误信息,发现有奇怪的路径
diff: /Podfile.lock: No such file or directory
diff: /Manifest.lock: No such file or directory

去根目录找文件?似乎不太对劲。

  1. 查看编译出错的步骤,发现有2个环境变量好像没有设置

CocosCreator_cocoapod_build_error02

  1. 回想起pod install时,有一些没仔细看的警告
[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `ColorUp-mobile` to `Target Support Files/Pods-ColorUp-mobile/Pods-ColorUp-mobile.debug.xcconfig` or include the `Target Support Files/Pods-ColorUp-mobile/Pods-ColorUp-mobile.debug.xcconfig` in your build configuration (`ios/UserConfigIOS.debug.xcconfig`).

[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `ColorUp-mobile` to `Target Support Files/Pods-ColorUp-mobile/Pods-ColorUp-mobile.release.xcconfig` or include the `Target Support Files/Pods-ColorUp-mobile/Pods-ColorUp-mobile.release.xcconfig` in your build configuration (`ios/UserConfigIOS.release.xcconfig`).

CocoasPods_warning

如果打开这些.xcconfig文件的话,可以看到 PODS_PODFILE_DIR_PATH 和 PODS_ROOT 的定义。

PODS_PODFILE_DIR_PATH = ${SRCROOT}/.
PODS_ROOT = ${SRCROOT}/Pods

CocosCreator_cocoapod_build_error04

  1. 把pod对应的.xcconfig添加到Cocos Creator的.xcconfig里

CocosCreator_cocoapod_build_error03

// Configuration settings file format documentation can be found at:
// https://help.apple.com/xcode/#/dev745c5c974

#include "/Applications/CocosCreator.app/Contents/Resources/cocos2d-x/cocos/platform/ios/CCModuleConfigIOS.debug.xcconfig"

// 添加这一行
#include "../Pods/Target Support Files/Pods-ColorUp-mobile/Pods-ColorUp-mobile.debug.xcconfig"

  1. 编译,搞定。