5

I am trying to build a ionic project in Android studio on Ubuntu 20.04 . I am using the command ionic capacitor build then android studio opens up as expected then it shows this error Gradle sync failed: Sync failed: reason unknown. I am unable find a solution for this particular gradle sync error. I have reinstalled Ubuntu and other things but still the problem persists.

Pritam Roy
  • 51
  • 1
  • 2

5 Answers5

3

In my case, a fresh install of Android Studio resulted in Android 31 being the only SDK available but the project was targeting Android 30. I went to Tools > SDK Manager and made sure the appropriate version of Android SDK was installed and available. After restarting, and allowing the gradle sync to complete I was able to build/run the app on a virtual device, etc.

ajcurtis
  • 63
  • 6
0

Here is what I found

This is the screenshot thanks for helping.

Pritam Roy
  • 51
  • 1
  • 2
0

Capacitor lets you manage your own Android project. Like any IDE-backed project, sometimes things get so out of sync that the only solution is to rebuild the project.

To do this, follow these steps:

Copy any source code you created (such as Java files in app/android/src, manifest files, or resource files) into a safe location outside of app/android.

Next, make sure you are running an updated version of the Capacitor CLI:

npm install @capacitor/cli@latest

Remove the android directory:

rm -rf android/

Re-create the Android app from Capacitor:

npx cap add android

Copy your saved source files back into the project.

DoctorWho
  • 1,044
  • 11
  • 34
praveen kumar
  • 51
  • 1
  • 4
0

Check the error log. You should find something like "Module: 'mobile' platform 'android-30' not found" or something similar. Click Tools > SDK Manager and download the appropriate Android SDK Platform package.

Luis
  • 11
  • 3
0

on top right you will see option to view log file upon clicking there you will redirect to file manager and open idea file there example : enter image description here

open idea file and scroll down you will see actual issue. In my case android sdk 31 was not installed. I installed android sdk 31 from File>Settings>Apprearance and behaviour>system settings>android sdk and install required android sdk and rebuild the project.

accord to my observation in most cases you get this error because you have not required sdk installed in your system.

MANISH
  • 2,883
  • 4
  • 11
  • 30