V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
ChrisFreeMan
V2EX  ›  程序员

Electron 应用好不容易搞定签名,打包,就卡在最后一步 Transporter 了

  •  
  •   ChrisFreeMan · 256 天前 · 2557 次点击
    这是一个创建于 256 天前的主题,其中的信息可能已经有所发展或是发生改变。

    用的 Electron Forge 脚手架,好不容易搞定签名打包的问题,现在就差最后一步了,但是卡在 Transporter 的校验上了,说我的 plist 文件里面 CFBundleExecutable key 不合法,但是我检查了个遍都是和执行文件一样的名字,网上也没有找到任何有价值的信息。很难受,有知道的老哥吗。

    能解决请一杯咖啡 (免费应用,本人不富有)

    Imgur

    这是我的打包配置

      packagerConfig: {
        appBundleId: `ChrisFreeManDev-hotmail.com.${appName}`,
        appCopyright: `© ${(new Date()).getFullYear()} ${appName}`,
        buildVersion: '8',
        executableName: appName,
        appCategoryType: 'public.app-category.productivity',
        asar: true,
        osxUniversal: {
          x64ArchFiles: 'leveldown.node',
        },
        osxSign: {
          type: 'distribution',
          identity: 'Apple Distribution: MyName (SomeCertID)',
          provisioningProfile: './some-production.provisionprofile',
          optionsForFile: () => {
            return {
              hardenedRuntime: true,
              entitlements: './entitlements',
            }
          }
        },
        icon: './src/resources/icon/AppIcon'
      },
      rebuildConfig: {},
      makers: [
        new MakerPKG({
          identity: '3rd Party Mac Developer Installer: MyName (SomeCertID)',
          install: './out',
          name: appName
        }, ['mas'])
      ],
    

    PS 发在 electron 节点没人看,一晚上才 10 个点击😫

    24 条回复    2023-08-16 19:08:00 +08:00
    NouveauNom
        1
    NouveauNom  
       256 天前
    先看下.app 里面的 info.plist CFBundleExecutable 值是多少
    NouveauNom
        2
    NouveauNom  
       256 天前
    这个看样子是你目前没有这个值
    ChrisFreeMan
        3
    ChrisFreeMan  
    OP
       256 天前
    @NouveauNom 都有的主 plist 里面有 CFBundleExecutable, 然后在 Frameworks 下面的 4 个 helper 以及 Electron Framework 的 plist 都检查过了,所以我觉得很奇怪。。。
    Belmode
        4
    Belmode  
       256 天前
    Belmode
        5
    Belmode  
       256 天前
    还有可能要考虑一下文件编码和 Unicode 零宽字符的问题
    ChrisFreeMan
        6
    ChrisFreeMan  
    OP
       256 天前
    @Belmode 他的第一个图片是针对 Xcode 的环境的,因为它是个占位符,Xcode 会在打包后自动填充,而我已经在打包后的应用检查过了,都没有问题,我在上面解释了。第二个图片也是错的,CFBundleExecutable 是指定的二进制可执行文件的。
    ChrisFreeMan
        7
    ChrisFreeMan  
    OP
       256 天前
    @Belmode 我的应用名称是纯英文的,编码都是 utf-8
    NouveauNom
        8
    NouveauNom  
       256 天前
    把 plist 发下看下,CFBundleExecutable 得值是什么,是否触发了关键词
    ChrisFreeMan
        9
    ChrisFreeMan  
    OP
       256 天前
    @NouveauNom
    ```xml
    <?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>CFBundleDisplayName</key>
    <string>Simark</string>
    <key>CFBundleExecutable</key>
    <string>Simark</string>
    <key>CFBundleIconFile</key>
    <string>electron.icns</string>
    <key>CFBundleIdentifier</key>
    <string>ChrisFreeManDev-hotmail.com.Simark</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>Simark</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0.0</string>
    <key>CFBundleVersion</key>
    <string>8</string>
    <key>DTCompiler</key>
    <string>com.apple.compilers.llvm.clang.1_0</string>
    <key>DTSDKBuild</key>
    <string>22E245</string>
    <key>DTSDKName</key>
    <string>macosx13.3</string>
    <key>DTXcode</key>
    <string>1431</string>
    <key>DTXcodeBuild</key>
    <string>14E300c</string>
    <key>LSApplicationCategoryType</key>
    <string>public.app-category.productivity</string>
    <key>LSEnvironment</key>
    <dict>
    <key>MallocNanoZone</key>
    <string>0</string>
    </dict>
    <key>LSMinimumSystemVersion</key>
    <string>10.13</string>
    <key>NSAppTransportSecurity</key>
    <dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    </dict>
    <key>NSBluetoothAlwaysUsageDescription</key>
    <string>This app needs access to Bluetooth</string>
    <key>NSBluetoothPeripheralUsageDescription</key>
    <string>This app needs access to Bluetooth</string>
    <key>NSCameraUsageDescription</key>
    <string>This app needs access to the camera</string>
    <key>NSHighResolutionCapable</key>
    <true/>
    <key>NSMainNibFile</key>
    <string>MainMenu</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>This app needs access to the microphone</string>
    <key>NSPrincipalClass</key>
    <string>AtomApplication</string>
    <key>NSQuitAlwaysKeepsWindows</key>
    <false/>
    <key>NSRequiresAquaSystemAppearance</key>
    <false/>
    <key>NSSupportsAutomaticGraphicsSwitching</key>
    <true/>
    <key>NSHumanReadableCopyright</key>
    <string>© 2023 Simark</string>
    <key>ElectronAsarIntegrity</key>
    <dict>
    <key>Resources/app.asar</key>
    <dict>
    <key>algorithm</key>
    <string>SHA256</string>
    <key>hash</key>
    <string>5a3b8dd2e1e307b64a7f84579e7fcc78552b1a8c7bb5a659108902410fd96fd8</string>
    </dict>
    </dict>
    </dict>
    </plist>
    ```
    这是主 plist
    BlackHole1
        10
    BlackHole1  
       256 天前
    在 2019 年的时候,forge 修复了类似的问题:
    1. https://github.com/electron/electron-packager/pull/1046
    2. https://github.com/electron/forge/pull/1118

    你可以确认下你的 forge 版本是否是最新的。如果不是尝试升级到最新。如果依旧不行的话,你可以尝试构建 DMG ,而非 PKG ,我怀疑是 MakerPKG 的问题
    ChrisFreeMan
        11
    ChrisFreeMan  
    OP
       256 天前
    @BlackHole1 我用的是 6.3.0 的版本,DMG 不能上传到 Transporter 耶,好像 DMG 是自由分发的格式类似 Zip ,就是方便拖入到应用库
    BlackHole1
        12
    BlackHole1  
       256 天前
    你是想公证还是想上架到 apple store ?如果是公证不需要 pkg 。
    BTW ,你可以在打包之前输入: export DEBUG=* 方便看到详细的日志。
    以及你可以在 electron/forge 里建立一个 issue
    ChrisFreeMan
        13
    ChrisFreeMan  
    OP
       256 天前
    @BlackHole1 Transporter 就是用来上传到 App Store 的,forge issue 也已经提交了😂,我是走投无路才来 v 站的。实在不行我只有去翻 osxSign 的源码了😭
    NouveauNom
        14
    NouveauNom  
       256 天前
    换个名字试试吧,看不出来别的异常了
    BlackHole1
        15
    BlackHole1  
       256 天前
    @ChrisFreeMan #13 方便发下 issues 的 URL 么?
    ChrisFreeMan
        17
    ChrisFreeMan  
    OP
       256 天前
    @NouveauNom 我试试吧
    ChrisFreeMan
        18
    ChrisFreeMan  
    OP
       256 天前
    @NouveauNom 一样的😭,总之还是谢谢了
    sipt
        19
    sipt  
       256 天前
    ```
    optionsForFile: () => {
    return {
    hardenedRuntime: true,
    entitlements: './entitlements',
    }
    }
    ```
    ./entitlements ?
    ./entitlements.plist ??
    ChrisFreeMan
        20
    ChrisFreeMan  
    OP
       256 天前
    @sipt 这里指向的应该是一个目录,因为签名需要有个父证书,和子证书。
    ```md
    entitlements/
    - default.mas.child.plist
    - default.mas.plist
    ```
    BlackHole1
        21
    BlackHole1  
       256 天前   ❤️ 5
    我已经在 Issue 中评论了,为了让 V2EX 其他参与者了解,我这边把相关信息在这里进行同步。

    ----

    我基于你的 repo 进行测试后,一切正常,并没有出现你遇到的情况,如下图:

    https://user-images.githubusercontent.com/8198408/260978001-7931e439-db8e-44f8-b5ca-34586299cae2.png

    但是在测试过程中,我发现了一些 bug 和优化项,你可以进行修改后再进行测试。

    1. MakerPKG class 中的 install 应该是 /Applications 而不是 ./out ,这个参数的用途是安装 pkg 后,app 应该安装的目录,如果需要上传到 App Store 则这个值必须是 /Applications
    2. optionsForFile 函数中的 entitlements 应该是一个文件,而非目录。关于这一点,可以见: https://github.com/electron/osx-sign/blob/013ca00893e13594b87fd66fe865793011453de9/src/util-entitlements.ts#L46-L49
    3. 你其实不需要传入 optionsForFile ,因为 electron-osx-sign 会自动处理 entitlements 。

    最终的改动如下图:
    https://github.com/electron/forge/assets/8198408/7b06a3ad-d23e-4ab0-8978-57ba8442baf2
    ChrisFreeMan
        22
    ChrisFreeMan  
    OP
       256 天前
    @BlackHole1 😂感谢大佬,确实通过了,我以为这个 install 路径是指 pkg 输出的路径。我是直接点外卖送你桌位上,你挑时间,还是我把咖啡钱转给你。❤️
    BlackHole1
        23
    BlackHole1  
       256 天前
    @ChrisFreeMan #22 解决了就好,咖啡就不用啦。也感谢你使用 Electron~
    ChrisFreeMan
        24
    ChrisFreeMan  
    OP
       256 天前
    @BlackHole1 🌹🌹🌹 必须用的,Electron 贼 TM 好用,从开头爽到结束,再也不想用 SwiftUI 了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1263 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 17:49 · PVG 01:49 · LAX 10:49 · JFK 13:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.