You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从零创建.app文件?Lua脚本打包为.app后运行失败求助

Lua脚本打包成.app后启动失败问题

问题详情

我正在开发一个将Lua脚本打包为.app文件的工具,但遇到了启动故障。测试时,我将一个可正常运行的带UI程序放置在MyApp.app/Contents/MacOS/main路径下,同时配置了MyApp.app/Contents/Info.plist文件,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>English</string>
    <key>CFBundleExecutable</key>
    <string>msain</string>

    <key>CFBundleIconFile</key>
    <string></string>
    <key>CFBundleIdentifier</key>
    <string>net.frityet.test</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>Test</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSMinimumSystemVersion</key>
    <string>10.14</string>
    <key>NSHighResolutionCapable</key>
    <true/>
    <key>NSPrincipalClass</key>
    <string>NSApplication</string>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
</dict>
</plist>

使用open命令启动应用时,出现以下错误:

The application cannot be opened for an unexpected reason, error=Error Domain=RBSRequestErrorDomain Code=5 "Launch failed." UserInfo={NSLocalizedFailureReason=Launch failed., NSUnderlyingError=0x7fa445911ca0 {Error Domain=NSPOSIXErrorDomain Code=111 "Unknown error: 111" UserInfo={NSLocalizedDescription=Launchd job spawn failed}}}

解决方案

  • 修正可执行文件名称匹配:Info.plist中的CFBundleExecutable字段值为msain,但实际放置的可执行文件名为main,两者不匹配导致系统无法定位启动程序。请将CFBundleExecutable的值修改为main,或者将MacOS目录下的可执行文件重命名为msain。
  • 添加可执行权限:确保MyApp.app/Contents/MacOS/main拥有可执行权限,在终端执行以下命令:
    chmod +x MyApp.app/Contents/MacOS/main
    
  • 检查架构兼容性:确认Lua程序的编译架构与当前macOS设备兼容(例如ARM架构的M系列芯片需确保程序支持Rosetta或原生ARM)。
  • 查看详细日志:若问题仍存在,打开「控制台.app」搜索MyApp或launchd相关日志,获取更具体的错误信息以定位问题。

内容的提问来源于stack exchange,提问作者Frityet

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 05:05:36