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

升级至API Level 31后Cordova无法连接安卓设备调试问题

问题

为满足Google Play商店要求,我将应用的API Level(targetSdkVersion)调整为31,同时在Android Studio中卸载了API Level 30并安装了API Level 31。之后无法通过Cordova将应用运行到设备上调试,报错信息为:Could not find target matching { type: 'device' },命令行输出如下:

C:\htdocs\app\myapp>cordova run android --device
Checking Java JDK and Android SDK versions
ANDROID_HOME=C:\Users\myusr\AppData\Local\Android\Sdk (recommended setting)
ANDROID_SDK_ROOT=undefined (DEPRECATED)
Using Android SDK: undefined
Reading build config file: C:\htdocs\app\verpro\build.json
Subproject Path: CordovaLib
Subproject Path: app

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 960ms
50 actionable tasks: 50 up-to-date
Built the following apk(s):
        C:\htdocs\app\verpro\platforms\android\app\build\outputs\apk\debug\app-debug.apk
Checking Java JDK and Android SDK versions
ANDROID_HOME=C:\Users\ncchi\AppData\Local\Android\Sdk (recommended setting)
ANDROID_SDK_ROOT=undefined (DEPRECATED)
Using Android SDK: undefined
Reading build config file: C:\htdocs\app\verpro\build.json
Could not find target matching { type: 'device' }
解决方案
  • 确认设备USB调试状态:执行adb devices命令,检查电脑是否能识别到连接的设备。若未显示,切换设备USB连接模式为「文件传输」,并确保设备驱动安装正常。
  • 修复SDK环境变量:输出中Using Android SDK: undefined存在异常,需确保ANDROID_HOME指向正确的SDK路径,同时将%ANDROID_HOME%\platform-tools和%ANDROID_HOME%\tools添加到系统PATH环境变量,之后重启命令行窗口。
  • 匹配Cordova Android平台版本:API Level 31对应Cordova Android 11.x版本,执行cordova platform remove android后,再运行cordova platform add android@11.0.0重新添加适配的平台。
  • 检查设备系统版本:API Level 31对应Android 12,若设备系统版本低于Android 12,可更换Android 12及以上的设备调试,或创建对应API Level的模拟器,使用cordova run android --emulator测试。
  • 清理项目缓存:执行cordova clean清理缓存后,重新运行cordova run android --device尝试构建部署。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 21:05:15