LoginSignup
0
0

ElectronのAppXファイル作成ではまったこと

Last updated at Posted at 2023-09-05

パッケージ化したAppXを配布前にテストしたい

  1. 作成したAppXファイルを右クリック、プロパティ
  2. デジタル署名、署名クリック、詳細
  3. 証明書の表示
  4. 証明書のインストール
  5. ローカルコンピューター、証明書を全ての次のストアに配置する、参照
  6. 信頼されたルート証明機関、OK
  7. 上記おわったらappxファイルをダブルクリック

開発用PCだと動くのに、実験機だと動くやつと動かないやつがある。

'.node'ファイルが見つからない?特定できない?感じのエラー

Error: The specified module could not be found.

\\?\C:Program Files\...........\xxxx.node

該当のパスを見てみるけどファイルは存在しているようだった。

問題は、xxxx.nodeはバイナリで、そいつが別のdllを呼び出しているが、そのdllが実験機に存在しないせいだった。

dumpbinコマンドで、どのdllをそのモジュールが必要としているかがわかる。

  1. dumpbinコマンドを実行できるように、VisualStudioのパスを環境変数に通す
例えば
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.37.32822\bin\Hostx86\x64
を環境変数Pathに設定
  1. .nodeファイルのあるフォルダで、下記コマンドを実行する
dumpbin /dependents .\xxxx.node

実行結果として次のような感じ

PS C:\Users\......\node-aead-crypto-win32-x64-msvc> dumpbin /dependents .\node-aead-crypto.win32-x64-msvc.node
Microsoft (R) COFF/PE Dumper Version 14.37.32822.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file .\node-aead-crypto.win32-x64-msvc.node

File Type: DLL

  Image has the following dependencies:

    bcrypt.dll
    KERNEL32.dll
    VCRUNTIME140.dll
    api-ms-win-crt-runtime-l1-1-0.dll
    api-ms-win-crt-heap-l1-1-0.dll

  Summary

        1000 .data
        E000 .pdata
       36000 .rdata
        1000 .reloc
      118000 .text

これで、VCRUNTIME140.dll必須であることが認識できる。

これを実験機にインストールする。

AppXにDLL内包したい

上記と絡むが、Visual C++の再頒布パッケージのDLLを内包したAppXを作りたい。

exeの位置にDLLを置きたいが、extraFilesオプションだとasarの内部になってうまくいかない。

いろいろ調べたけどあまりよさそうなオプションがなく、hookでやれという感じだった。

forge.config.js
  hooks: {
    postPackage: async (config, packageResult) => {
      if (packageResult.platform == 'win32') {
        let src = path.join(__dirname, 'appx', 'vcruntime140.dll');
        let dst = path.join(__dirname, 'out', '<app>-win32-x64', 'vcruntime140.dll');
        fs.copyFileSync(src, dst);
      }
    }
  }

こんな感じで、win32コンパイルの時だけDLL付きにすることができそう。

Asar:trueにすると *.node が見つからないというエラーで落ちる

Native Electron ModuleはAsarに入れるとだめらしい。

asarを直接つかうならこんな感じ

direct
$ asar pack app app.asar --unpack *.node

electron-forgeとか使ってるなら@electron-forge/plugin-auto-unpack-nativesでやる。

Auto Unpack Native Modules Plugin,
https://www.electronforge.io/config/plugins/auto-unpack-natives

install
npm i -D @electron-forge/plugin-auto-unpack-natives

でインストールして、設定ファイルは、

forge.config.js
  packagerConfig: {
    asar: true
  },
  plugins: [
    {
      name: '@electron-forge/plugin-auto-unpack-natives',
      config: {}
    }
  ]

configは空でいいみたい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0