'Gradle sync failed with reason unknown - Android studio 4.2.1 [closed]
Did something to trigger a gradle sync (e.g. added a module that has its own compileSdkVersion different from my project's, as seen in its own build.gradle file), but after seeing Gradle sync started in the Event Log, I quickly run into:
Gradle sync failed: Sync failed: reason unknown
Tried solutions
- Invalidate cache and restart
- reinstalled android studio and recloned project
- changed the gradle version
- removed .gradle and .idea folder
- run gradle build from cli
- toggling offline mode
- Manually pointed gradle files
[using Android studio 4.2.1 and gradle 6.5, but can encounter this problem with other IDE/gradle combinations, as the problem most likely stems from the dependencies I've changed.]
Solution 1:[1]
In your screenshot, there is a infomation bar on top of the editor area "Gradle project sync failed. Basic funtionality will not work." Click the "Show log in finder", you can check the real reason in the log file.
In my case, I found “ Module: 'xxxxx' platform 'android-26' not found” which mean the platform 26 is missing. After download the platform api level 26, problem solved.
Solution 2:[2]
I got a similar issue in the new Arctic Fox version. After looking at the idea.log (it should be at /Users/username/Library/Logs/Google/AndroidStudioXX.XX/idea.log), it looked like I was missing some Android SDKs that are needed for the external libraries (I'm working on react native).
- Just look for the lines that say
Module: xx platform 'android-yy' not found. - Use the SDK Manager and install the SDK version yy
- Invalidate cache and restart
In my case, I had multiple missing SDKs, so it didn't work after restarting; I had to repeat steps 1 to 3 another time.
Solution 3:[3]
When install new environment, go to SDK Manager and install necessary API (ex: from 28 to 31)
Finally go to Gradle of App level and Sync Now again.
Solution 4:[4]
Did you install all the SDK packages required on Android Studio?
'Cause I solved installing some SDK packages I didn't install previously. Check if you have missed them.
For understand when you have done, the Event Log tab reports these messages (look at the img) https://i.stack.imgur.com/ids61.png
Solution 5:[5]
I had this same issue and i fixed it in the following steps after trying lots of stuff all in vain.
Check the
compileSdkVersion 30andtargetSdkVersion 30values in your app gradle file.If the values are say
30, you must make sure that when you click theSDK Managerat the top left corner of your Android studio, you will have thisSDKlevel installed.Otherwise you can
install it. from the dialog box that will have popped up. In my case, my appgradlefile from apull requestof my company's code was30but since i had just updated android studio i had level31only installed.So instead of going through the hassle of installing
SDK level 30of which i was in a rush to do other stuff, I just switched my values from 30 to 31 in the gradle app files.
And everything worked after gradle sync. Then when i had the time, i would later go back to install level 30 and revert the values.
Hope this helps someone as I had spent some good minutes trying to figure out the error
Solution 6:[6]
- Just go to "Run/edit configurations" and scroll down to bottom of the window and here you can see option "Before launch"
- Remove whatever already inside the little window.
- Then click on (+) icon and select "Gradle-aware Make" and then type "assembleDebug" and select the first option or that you need. This will solve your problem.
Solution 7:[7]
I also have exact errors and tried all solutions, but I solved this by adding Android Virtual Device.
In my case, I added two virtual devices with minimum API level and Maximum API level of my project. Then Restarting the Android Studio Sync Gradle and solved the problem.
Try this with Stable Network Connection.
Solution 8:[8]
I had a fresh installation of Android Studio and started facing this problem. After trying all the various solutions, I found that the SDK Platform was not installed for API Level 30, but was installed for API Level 31, and my project was using API Level 30.
So I installed API level 30 SDK Platform and the issue got resolved.
Solution 9:[9]
Tried all the options mentioned above and finally deleted the .gradle folder within the project structure and invalidate caches to restart the intellij, this resolved the issue
Solution 10:[10]
If you have a fresh installation of android studio , you should
- Install java if not already installed (If you re-installed windows) skip this step otherwise
- Menu -> Invalidate caches/restart and try to sync Gradle afterwards (If issue still persists go to step 3)
- go to tools->SDK Manager-> and install any missing SDK version (Sync Gradle afterwards) if all the android versions are installed prior to your targeted version and subsequent to your compiled SDK version go search another thread on Stack Overflow! else go to step 4
- Accept debugging dialog/keys at your android device if you keep the device connected and are waiting to show up in run configuration (Wait few seconds to let the dialog show up. Go to step 5 if dialog not presented in step 4)
- Disconnect the USB cable and reconnect again.
make sure to accept the SDK license in step 4.
Solution 11:[11]
You cannot do that. Whole paging is based on flow, this is just the official api. Is there any particular reason why you don't want to use flow?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
