如何将cocos2d-x js打包部署到ios上 Mac M1系统

项目环境

cocos2d-x 3.13

xcode 12

mac m1 big sur

先找到你的项目

使用xcode软件打开上面这个文件

打开后应该是这个样子

执行编译运行就好了

可能会碰到的错误

在xcode11版本以上都会有这个错误,这是因为iOS11+废弃了system。

将上面代码修改为

cpp 复制代码
#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)
#include <ftw.h>
#endif

namespace
{
#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)
    int unlink_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
    {
        int rv = remove(fpath);

        if (rv)
            perror(fpath);

        return rv;
    }
#endif
}

bool FileUtils::removeDirectory(const std::string& path)
{
#if !defined(CC_TARGET_OS_TVOS)

#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)
    if (nftw(path.c_str(), unlink_cb, 64, FTW_DEPTH | FTW_PHYS) == -1)
        return false;
    else
        return true;
#else
    std::string command = "rm -r ";
    // Path may include space.
    command += "\"" + path + "\"";
    if (system(command.c_str()) >= 0)
        return true;
    else
        return false;
#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)

#else
    return false;
#endif // !defined(CC_TARGET_OS_TVOS)
}

解决方案地址

remove "system" usage by minggo · Pull Request #17921 · cocos2d/cocos2d-x · GitHub

继续运行碰到错误

building for iOS Simulator, but linking in object file built for iOS,

找到配置项的这一行添加arm64

再继续运行 又出现错误

解决方法 删除全部VALID_ARCHS 配置项 全局搜索 VALID_ARCHS 然后整行删除。

继续运行 报错

解决方法

找到42行代码

改成下面

再运行 报错

解决方法

找到ios info.list 添加version值

再运行,终于运行成功

相关推荐
汤姆yu1 小时前
Mac 上 2026 版 OpenClaw 安装与配置全流程
macos·openclasw安装
MonkeyKing_sunyuhua2 小时前
K8S执行MAC打出的本地镜像错误:exec /usr/local/bin/uvicorn: exec format error
macos·容器·kubernetes
Zender Han6 小时前
Flutter Bloc / Cubit 最新详解与实战指南(2026版)
android·flutter·ios
小路恢弘7 小时前
xcode替换LLVM插件
ide·macos·xcode
ChengQianO8 小时前
从 0 开始:Mac 下 UTM 虚拟机安装 ROS Noetic(Ubuntu 20.04)
linux·ubuntu·macos
tangweiguo030519879 小时前
iOS vs Android 开发对照手册
android·ios
草帽lufei10 小时前
macOS中的Cursor等软件突然不能用了
macos·cursor
weixin_4434785110 小时前
flutter组件学习之Cupertino 组件(iOS风格)
学习·flutter·ios
Rabbit_QL10 小时前
【Warp+Claude】任务完成自动通知(macOS + Warp 版)
macos·策略模式
X档案库12 小时前
【ROS2】Mac M4 虚拟机 Ubuntu 24.04 安装 ROS2 Jazzy 新手教程
macos·机器人·ros