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

开发Ionic 4+Capacitor安卓APP时,Android Studio报Gradle模块找不到错误

Fix for "Unable to find module with Gradle path ':capacitor-cordova-android-plugins'" in Ionic 4 + Capacitor

Hey there, I’ve faced this exact headache when working with Ionic 4, Capacitor, and Cordova plugins on Android. Let’s break down the step-by-step fixes that usually resolve this Gradle module issue:

1. Re-sync Cordova plugins with Capacitor

First, make sure all your Cordova plugins are properly installed, then run this command from your project root to sync them into the Android platform:

npx cap sync android

This command generates the capacitor-cordova-android-plugins module and links it to your Android project—this is usually the first fix to try because missing sync is the most common cause.

2. Verify the plugin module exists in your Android project

Check if the android/capacitor-cordova-android-plugins directory is present. If it’s missing:

  • Uninstall any problematic Cordova plugins (use npm uninstall <plugin-name>)
  • Reinstall them with npm install <plugin-name>
  • Run npx cap sync android again to regenerate the module

3. Refresh Gradle and clear Android Studio caches

Android Studio sometimes fails to pick up new module changes. Try these steps:

  • Click the Sync Project with Gradle Files button (looks like a refresh arrow in the top-right corner)
  • If that doesn’t work, go to File > Invalidate Caches / Restart—this clears stale IDE caches and often fixes weird Gradle linking issues

4. Double-check Gradle configuration files

If the module exists but Gradle still can’t find it, verify these files:

  • Open android/settings.gradle and ensure it includes these lines:
    include ':capacitor-cordova-android-plugins'
    project(':capacitor-cordova-android-plugins').projectDir = new File('../capacitor-cordova-android-plugins/android')
    
  • Open android/app/build.gradle and confirm this dependency is present:
    implementation project(':capacitor-cordova-android-plugins')
    

After making any changes, re-sync the project with Gradle.

5. Clean and rebuild the project

Stale build artifacts can cause module linking issues. Try:

  • In Android Studio: Build > Clean Project followed by Build > Rebuild Project
  • Or from the terminal:
    cd android
    ./gradlew clean
    cd ..
    npx cap sync android
    

6. Recreate the Android platform (last resort)

If none of the above works, completely rebuild the Android platform:

npx cap remove android
npx cap add android
npx cap sync android

This ensures a fresh platform setup without any leftover configuration issues.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.06 10:57:48