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

已安装Gradle但Cordova requirements仍提示未安装的问题求助

Fixing Cordova's "Gradle Not Installed" Error Despite Manual Gradle Installation

Hey there, I’ve run into this exact head-scratcher before—let’s break down why Cordova isn’t picking up your manually installed Gradle 4.7 and how to fix it step by step:

1. Double-Check Environment Variables (Most Likely Culprit)

Even if gradle -v works in your terminal, Cordova might not be reading the right environment variables. Here’s what to verify:

  • Set GRADLE_HOME: Point this variable directly to your Gradle 4.7 installation folder (e.g., C:\gradle-4.7 on Windows, /usr/local/gradle-4.7 on macOS/Linux).
  • Update PATH: Add %GRADLE_HOME%\bin (Windows) or $GRADLE_HOME/bin (macOS/Linux) to your system PATH. Ensure this entry comes before any other Gradle-related paths (like those from the npm gradle package).
  • Restart Your Terminal: Environment variable changes won’t apply to open windows—close and reopen it, then re-run gradle -v to confirm, followed by cordova requirements.

2. Uninstall the npm gradle Package (Resolve Conflicts)

The npm install gradle command installs a Node.js wrapper for Gradle, which often clashes with system-level installations and causes weird errors like Cannot read property 'length' of undefined. Let’s remove it:

npm uninstall -g gradle

This ensures Cordova prioritizes your manually installed Gradle instead of the problematic npm wrapper.

3. Explicitly Tell Cordova Where Your Gradle Lives

If environment variables still don’t do the trick, force Cordova to use your Gradle path directly:

  • Per-Command Fix: Run your requirements check with the --gradle-path flag:
    cordova requirements android --gradle-path /path/to/gradle-4.7/bin/gradle
    
  • Project-Wide Fix: Add this configuration to your project’s config.xml to make it permanent:
    <platform name="android">
        <preference name="GradlePath" value="/path/to/gradle-4.7/bin/gradle" />
    </platform>
    

4. Refresh Cordova’s Android Platform

Corrupted platform files can throw off detection. Let’s rebuild the Android platform from scratch:

# Remove the existing Android platform
cordova platform remove android

# Add a compatible version (Gradle 4.7 works best with cordova-android@7.1.0+)
cordova platform add android@7.1.0

This ensures fresh, compatible platform files that play nice with your Gradle version.

5. Verify Android SDK Compatibility

Gradle 4.7 needs specific Android SDK components to work with Cordova:

  • Android SDK Build Tools version 27.0.3 or higher
  • Up-to-date Android SDK Platform Tools
    Run sdkmanager --list to check for missing components and update them if needed.

After trying these steps, re-run cordova requirements—it should finally detect your Gradle 4.7 installation correctly.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 09:40:52