Android Studio打开报错“..\native\19\windows-amd64\native-platform.dll.lock 拒绝访问”的处理方法

本文分享了一次解决Android Studio(AS)启动时报错的问题经历,错误信息为C:UsersAQ.gradle ative19windows-amd64 ative-platform.dll.lock拒绝访问。尝试了重命名文件、删除文件夹和以管理员身份运行AS等方法,最终成功解决了问题。

今天电脑有问题重启后, 再次打开AS就报错

error:C:\Users\ZAQ\.gradle\native\19\windows-amd64\native-platform.dll.lock (拒绝访问)

很懵

上网查了一下,解决方法有:

① 进入该目录 把native-platform.dll.lock 重命名为 native-platform.dll

我进去一看 有俩文件,一个.dll 一个.dll.lock 重命名会同名冲突 不行

②把native这个文件夹删了 说AS会自动重新生成

我爽快的删了 结果是它没有帮我再新生成一个! 行叭我就把它从回收站拾回来了

③最后我决定 直接简单粗暴的以管理员身份运行AS

你猜怎么着~

邪笑hiahia~

没再报错啦:)

npm install ffi-napi ref-napi express cors body-parser --save npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'body-parser@2.2.1', npm WARN EBADENGINE required: { node: '>=18' }, npm WARN EBADENGINE current: { node: 'v16.20.0', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'express@5.2.1', npm WARN EBADENGINE required: { node: '>= 18' }, npm WARN EBADENGINE current: { node: 'v16.20.0', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'content-disposition@1.0.1', npm WARN EBADENGINE required: { node: '>=18' }, npm WARN EBADENGINE current: { node: 'v16.20.0', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'finalhandler@2.1.1', npm WARN EBADENGINE required: { node: '>= 18.0.0' }, npm WARN EBADENGINE current: { node: 'v16.20.0', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'merge-descriptors@2.0.0', npm WARN EBADENGINE required: { node: '>=18' }, npm WARN EBADENGINE current: { node: 'v16.20.0', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'mime-types@3.0.2', npm WARN EBADENGINE required: { node: '>=18' }, npm WARN EBADENGINE current: { node: 'v16.20.0', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'router@2.2.0', npm WARN EBADENGINE required: { node: '>= 18' }, npm WARN EBADENGINE current: { node: 'v16.20.0', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'send@1.2.0', npm WARN EBADENGINE required: { node: '>= 18' }, npm WARN EBADENGINE current: { node: 'v16.20.0', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'serve-static@2.2.0', npm WARN EBADENGINE required: { node: '>= 18' }, npm WARN EBADENGINE current: { node: 'v16.20.0', npm: '8.19.4' } npm WARN EBADENGINE } npm ERR! code 1 npm ERR! path D:\Projects\ruoyi\PrinterHelper\PrinterSever\node_modules\ffi-napi npm ERR! command failed npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node-gyp-build npm ERR! nothing.c npm ERR! win_delay_load_hook.cc npm ERR! nothing.vcxproj -> D:\Projects\ruoyi\PrinterHelper\PrinterSever\node_modules\ffi-napi\build\Release\\nothing.lib npm ERR! Preprocessing assembly file ..\..\..\deps\libffi\src\x86\win64_intel.preasm npm ERR! '"call"' 不是内部或外部命令,也不是可运行的程序 npm ERR! 或批处理文件。 npm ERR! D:\Projects\ruoyi\PrinterHelper\PrinterSever\node_modules\ffi-napi\build\deps\libffi\ffi.targets(34,5): error MSB3721: 命令“call "call" "../../../deps/libffi/preprocess_asm.cmd" "../../../deps/libffi/include" "../../../deps/libffi/config/win/x64" "..\..\..\deps\libffi\src\x86\win64_intel.preasm" "Release\obj\ffi\win64_intel.asm"”已退出,返回代码为 1。 [D:\Projects\ruoyi\PrinterHelper\PrinterSever\node_modules\ffi-napi\build\deps\libffi\ffi.vcxproj] npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using node-gyp@10.2.0 npm ERR! gyp info using node@16.20.0 | win32 | x64 npm ERR! gyp info find Python using Python version 3.8.10 found at "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\python.exe" npm ERR! gyp http GET https://nodejs.org/dist/v17.0.0/node-v17.0.0-headers.tar.gz npm ERR! gyp http 200 https://nodejs.org/dist/v17.0.0/node-v17.0.0-headers.tar.gz npm ERR! gyp http GET https://nodejs.org/dist/v17.0.0/SHASUMS256.txt npm ERR! gyp http GET https://nodejs.org/dist/v17.0.0/win-x64/node.lib npm ERR! gyp http 200 https://nodejs.org/dist/v17.0.0/SHASUMS256.txt npm ERR! gyp http 200 https://nodejs.org/dist/v17.0.0/win-x64/node.lib npm ERR! gyp info find VS using VS2022 (17.11.35327.3) found at: npm ERR! gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" npm ERR! gyp info find VS run with --verbose for detailed information npm ERR! gyp info spawn C:\Users\Administrator\AppData\Local\Programs\Python\Python38\python.exe npm ERR! gyp info spawn args [ npm ERR! gyp info spawn args 'D:\\node_global\\node_modules\\node-gyp\\gyp\\gyp_main.py', npm ERR! gyp info spawn args 'binding.gyp', npm ERR! gyp info spawn args '-f', npm ERR! gyp info spawn args 'msvs', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args 'D:\\Projects\\ruoyi\\PrinterHelper\\PrinterSever\\node_modules\\ffi-napi\\build\\config.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args 'D:\\node_global\\node_modules\\node-gyp\\addon.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args 'C:\\Users\\Administrator\\AppData\\Local\\node-gyp\\Cache\\17.0.0\\include\\node\\common.gypi', npm ERR! gyp info spawn args '-Dlibrary=shared_library', npm ERR! gyp info spawn args '-Dvisibility=default', npm ERR! gyp info spawn args '-Dnode_root_dir=C:\\Users\\Administrator\\AppData\\Local\\node-gyp\\Cache\\17.0.0', npm ERR! gyp info spawn args '-Dnode_gyp_dir=D:\\node_global\\node_modules\\node-gyp', npm ERR! gyp info spawn args '-Dnode_lib_file=C:\\\\Users\\\\Administrator\\\\AppData\\\\Local\\\\node-gyp\\\\Cache\\\\17.0.0\\\\<(target_arch)\\\\node.lib', npm ERR! gyp info spawn args '-Dmodule_root_dir=D:\\Projects\\ruoyi\\PrinterHelper\\PrinterSever\\node_modules\\ffi-napi', npm ERR! gyp info spawn args '-Dnode_engine=v8', npm ERR! gyp info spawn args '--depth=.', npm ERR! gyp info spawn args '--no-parallel', npm ERR! gyp info spawn args '--generator-output', npm ERR! gyp info spawn args 'D:\\Projects\\ruoyi\\PrinterHelper\\PrinterSever\\node_modules\\ffi-napi\\build', npm ERR! gyp info spawn args '-Goutput_dir=.' npm ERR! gyp info spawn args ] npm ERR! gyp info spawn C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe npm ERR! gyp info spawn args [ npm ERR! gyp info spawn args 'build\\binding.sln', npm ERR! gyp info spawn args '/clp:Verbosity=minimal', npm ERR! gyp info spawn args '/nologo', npm ERR! gyp info spawn args '/p:Configuration=Release;Platform=x64' npm ERR! gyp info spawn args ] npm ERR! gyp ERR! build error npm ERR! gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1 npm ERR! gyp ERR! stack at ChildProcess.<anonymous> (D:\node_global\node_modules\node-gyp\lib\build.js:216:23) npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:513:28) npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12) npm ERR! gyp ERR! System Windows_NT 10.0.26200 npm ERR! gyp ERR! command "D:\\nodejs\\node.exe" "D:\\node_global\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" npm ERR! gyp ERR! cwd D:\Projects\ruoyi\PrinterHelper\PrinterSever\node_modules\ffi-napi npm ERR! gyp ERR! node -v v16.20.0 npm ERR! gyp ERR! node-gyp -v v10.2.0 npm ERR! gyp ERR! not ok npm ERR! A complete log of this run can be found in: npm ERR! D:\node_cache\_logs\2025-12-08T08_03_51_617Z-debug-0.log
最新发布
12-09
你遇到的问题是典型的 **`ffi-napi` 在 Node.js 环境下编译失败** 的问题,尤其是在 Windows 平台上。我们来一步步分析并解决它。 --- ## ❌ 错误原因分析 ### 1. `npm WARN EBADENGINE Unsupported engine` ```text npm WARN EBADENGINE package: 'express@5.2.1', required: { node: '>=18' } ``` - 表示你安装的 `express@5`, `body-parser@2` 等依赖要求 **Node.js >= v18** - 但你的当前版本是:`v16.20.0` - ⚠️ 虽然只是警告(不是错误),但可能导致未来兼容性问题 ### 2. `ffi-napi` 编译失败核心错误: ```text '"call"' 不是内部或外部命令,也不是可运行的程序或批处理文件。 D:\...\ffi.targets(34,5): error MSB3721: 命令“call "call" ...”已退出,返回代码为 1 ``` 这是由于: - `ffi-napi` 是一个 **原生模块(native addon)**,需要通过 `node-gyp` 使用 Visual Studio 构建工具链进行编译 - 它依赖 `libffi` 这个底层 C 库,在 Windows 上构建时会调用 `.preasm` 预处理脚本 - 而这个脚本中使用了嵌套的 `call call ...` 命令,Windows CMD 解析出错! 👉 这是一个 **已知 bug**:[https://github.com/node-ffi-napi/node-ffi-napi/issues/147](https://github.com/node-ffi-napi/node-ffi-napi/issues/147) --- ## ✅ 解决方案汇总 我们需要从 **降级 + 替代 + 环境修复** 多角度入手。 --- ## ✅ 方案一:降级到稳定版本组合(推荐!) 避免使用最新版导致兼容性问题,改用经过验证的旧版本栈: ### ✔️ 推荐环境配置: | 工具 | 版本 | 说明 | |------|------|------| | Node.js | **v14.21.3** 或 **v16.20.0** | LTS 稳定版 | | npm | 自带 | 不要升级太高 | | ffi-napi | `^2.5.4` | 兼容性强 | | ref-napi | `^2.0.2` | 对应版本 | ### 🛠 步骤: #### 1. 清理项目 ```bash rm -rf node_modules package-lock.json npm cache clean --force ``` #### 2. 修改 `package.json` ```json { "name": "printer-server", "version": "1.0.0", "dependencies": { "express": "^4.18.2", "cors": "^2.8.5", "body-parser": "^1.20.2", "ffi-napi": "^2.5.4", "ref-napi": "^2.0.2" }, "engines": { "node": "16.x" } } ``` > ✅ 注意: > - 使用 `express@4.x` 而非 `5.x` > - 使用 `body-parser@1.x` 而非 `2.x` #### 3. 安装 ```bash npm install ``` --- ## ✅ 方案二:手动修复 `preprocess_asm.cmd` 中的 `call call` 问题 如果必须使用新版 `ffi-napi`,可以手动修改其构建脚本。 ### 步骤: 1. 找到文件路径: ``` node_modules\ffi-napi\deps\libffi\preprocess_asm.cmd ``` 2. 打开该文件,找到类似这行: ```bat call call "%~f0" "%~dp0..\..\include" "%~dp0..\config\%ARCH%" "%~1" "%~2" ``` 3. 改成单层 `call`: ```bat "%~f0" "%~dp0..\..\include" "%~dp0..\config\%ARCH%" "%~1" "%~2" ``` 4. 保存后重新安装: ```bash npm rebuild ffi-napi ``` --- ## ✅ 方案三:使用预编译版本(electron-rebuild 友好) 如果你最终目标是打包成桌面应用,建议使用 Electron,并配合预构建模块。 ### 使用 `@electron-toolkit/utils` + `ffi-napi` 预构建包 ```bash npm install @electron-toolkit/utils # 或直接使用 electron-forge / electron-builder 管理 native 模块 ``` 然后在 Electron 主进程中加载: ```js const { loadFile } = require('@electron-toolkit/utils'); const ffi = require('ffi-napi'); // 如果已正确绑定 ``` --- ## ✅ 方案四:绕过 `ffi-napi` —— 改用 C#/.NET 小程序桥接(最稳!) 既然 `CDFPSK.dll` 是 Windows 原生 DLL,且文档明确支持 C/C++ 调用,我们可以写一个极简的 **C# 控制台程序** 来打印,然后由 Node.js 调用它。 ### 优势: - 完全避开 `node-gyp` 编译难题 - 更稳定、性能更好 - 易于调试和部署 --- ### 示例:C# 打印小程序(`PrinterHelper.cs`) ```csharp using System; using System.Runtime.InteropServices; class Program { [DllImport("CDFPSK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int OpenPort(int portId); [DllImport("CDFPSK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int ClosePort(); [DllImport("CDFPSK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int PTK_ClearBuffer(); [DllImport("CDFPSK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int PTK_SetLabelWidth(uint width); [DllImport("CDFPSK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int PTK_SetLabelHeight(uint height, uint gap); [DllImport("CDFPSK.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] public static extern int PTK_DrawText(uint x, uint y, uint dir, uint font, uint hmul, uint vmul, byte txt, string text); [DllImport("CDFPSK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int PTK_PrintLabel(uint num, uint copies); [DllImport("CDFPSK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int GetErrState(); static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Usage: PrinterHelper.exe \"TEXT\" \"QRDATA\""); return; } string text = args[0]; string qrData = args[1]; try { OpenPort(4); // COM1 PTK_ClearBuffer(); PTK_SetLabelWidth(400); PTK_SetLabelHeight(300, 24); PTK_DrawText(20, 20, 0, 2, 1, 1, (byte)'N', text); // TODO: 绘制条码或图像 PTK_PrintLabel(1, 1); int err = GetErrState(); ClosePort(); Console.WriteLine(err == 0 ? "OK" : "ERROR:" + err); } catch (Exception ex) { Console.WriteLine("EX:" + ex.Message); } } } ``` ### 编译命令(需安装 .NET SDK) ```bash csc PrinterHelper.cs ``` 生成:`PrinterHelper.exe` --- ### Node.js 调用它(无需 ffi-napi!) ```js const { execFile } = require('child_process'); app.post('/print', (req, res) => { const { text, qrData } = req.body; execFile('./PrinterHelper.exe', [text, qrData], (error, stdout, stderr) => { if (stdout.trim() === 'OK') { res.json({ success: true }); } else { res.status(500).json({ error: stdout || stderr }); } }); }); ``` ✅ 完美避开所有编译问题! --- ## ✅ 最终推荐架构(生产可用) ``` Vue App (localhost:8080) ↓ HTTP POST Node.js Server (localhost:3000) ↓ spawn PrinterHelper.exe → CDFPSK.dll → Urovo TK820 (via COM/USB) ``` 优点: - Vue 只负责界面 - Node.js 负责通信协调 - C# 负责调用 DLL(安全、可靠、易维护) --- ##
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值