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.

- 51
- 1
- 2
-
1There should be a tool window showing the Gradle output of the build Android Studio triggers for syncing. Try to find that, maybe it contains more useful information. – Joachim Sauer May 17 '21 at 08:02
-
@JoachimSauer Here is what I found in the image below. – Pritam Roy May 17 '21 at 13:18
-
1I am experiencing this issue too on a Mac. I wonder if it is a consequence of an update to Android Studio. – Mattias Martens May 21 '21 at 18:19
-
@MattiasMartens Let me know if you find a solution – Pritam Roy May 24 '21 at 14:54
-
I solved mine after accepting licenses, look here -> https://stackoverflow.com/a/43003932/6210398 – don_jon Aug 31 '21 at 10:20
5 Answers
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.

- 63
- 6
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.

- 1,044
- 11
- 34

- 51
- 1
- 4
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.

- 11
- 3
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 :
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.

- 2,883
- 4
- 11
- 30