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

首次在VSCode打包Flutter Android APK遇keytool未识别错误求助

解决PowerShell中keytool命令未识别的问题

问题描述

首次尝试在VSCode的PowerShell终端发布Flutter Android应用,执行生成签名密钥库的命令:

keytool -genkey -v -keystore C:\Users\Admin\Videos\Halloween_Official - 2\official_halloween\android\app\upload-keystore.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias upload

出现如下错误:

keytool : The term 'keytool' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
At line:1 char:3
+   keytool -genkey -v -keystore C:\Users\Admin\Videos\Halloween_Offici ...
+   ~~~~~~~
    + CategoryInfo          : ObjectNotFound: (keytool:String) [], CommandNotFoundExceptio
   n
    + FullyQualifiedErrorId : CommandNotFoundException

附带flutter doctor检测结果:

[!] Flutter (Channel master, 3.6.0-1.0.pre.38, on Microsoft Windows [Version
    10.0.22000.1219], locale en-US)
    • Flutter version 3.6.0-1.0.pre.38 on channel master at C:\src\flutter
    ! Warning: `dart` on your path resolves to C:\dart-sdk\bin\dart.exe,    
      which is not inside your current Flutter SDK checkout at
      C:\src\flutter. Consider adding C:\src\flutter\bin to the front of    
      your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 338841afd3 (6 days ago), 2022-11-11 10:01:11 -0800 
    • Engine revision 7326e5b335
    • Dart version 2.19.0 (build 2.19.0-389.0.dev)
    • DevTools version 2.19.0
    • If those were intentional, you can disregard the above warnings;
      however it is recommended to use "git" directly to perform update     
      checks and upgrades.

[√] Windows Version (Installed version of Windows is version 10 or higher)

[!] Android toolchain - develop for Android devices (Android SDK version    
    31.0.0)
    • Android SDK at C:\Users\Admin\AppData\Local\Android\sdk
    • Platform android-Sv2, build-tools 31.0.0
    • Java binary at: C:\Program Files\Java\jdk-15.0.1\bin\java
    X Cannot execute C:\Program Files\Java\jdk-15.0.1\bin\java to determine
      the version

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe       

[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows
      development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including 
      all of its default components

[!] Android Studio (not installed)
    • Android Studio not found; download from
      https://developer.android.com/studio/index.html
      (or visit
      https://flutter.dev/docs/get-started/install/windows#android-setup for
      detailed instructions).

[√] IntelliJ IDEA Community Edition (version 2021.3)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition
      2021.3
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart

[√] VS Code (version 1.73.1)
    • VS Code at C:\Users\Admin\AppData\Local\Programs\Microsoft VS Code    
    • Flutter extension version 3.52.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows
      [Version 10.0.22000.1219]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome
      107.0.5304.107
    • Edge (web)        • edge    • web-javascript • Microsoft Edge
      107.0.1418.42

[√] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 4 categories.

解决方法

1. 直接使用keytool完整路径执行命令

从检测结果可知JDK路径为C:\Program Files\Java\jdk-15.0.1,keytool位于该路径的bin目录下,修改命令为:

& "C:\Program Files\Java\jdk-15.0.1\bin\keytool.exe" -genkey -v -keystore "C:\Users\Admin\Videos\Halloween_Official - 2\official_halloween\android\app\upload-keystore.jks" -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias upload

注意:路径包含空格时需用双引号包裹,PowerShell中执行带空格的可执行文件要加&符号。

2. 将JDK的bin目录添加到系统环境变量PATH

  • 右键「此电脑」→ 属性 → 高级系统设置 → 环境变量
  • 在系统变量中找到Path,点击编辑
  • 点击「新建」,添加路径C:\Program Files\Java\jdk-15.0.1\bin
  • 保存后关闭所有终端窗口,重新打开VSCode的PowerShell终端即可直接使用keytool命令

3. 修复Java执行问题

从检测结果看到无法执行Java二进制文件,可按以下步骤处理:

  • 检查C:\Program Files\Java\jdk-15.0.1\bin\java.exe是否存在,不存在则重新安装JDK
  • 确保当前用户对该文件有执行权限
  • 将JDK的bin目录添加到PATH后,flutter doctor的Java版本检测问题也会同步修复

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 21:45:33