3

I found several SO posts describing similar issues, but they are outdated and none were found to be helpful in regard to my upgrade to the latest version of Android Studio.

After upgrading my Android Studio from version 2021.3.1 to version 2022.1.1, my attempt to File > Sync Project with Gradle Files results in Sync failed (within less than 200ms).

When I try to Build > Rebuild Project, I get the following error:

Unable to find Gradle tasks to build: [:]. 
Build mode: REBUILD. 
Tests: None.

Unable to find Gradle tasks to build

  1. There is no :app in any of my settings.gradle files.
  2. I did File > Invalidate Caches... (all of them) and restarted AS, but this didn't help.
  3. I also deleted all build folders, but this didn't help.

Any idea how to solve this?

Right-clicking the Sync failed to Reload Gradle Project results in the same failure but it opens now a bar on top of the editor window with the Show Log in Explorer link. When I click it, I indeed find idea.log in C:\Users\WebViewer\AppData\Local\Google\AndroidStudio2022.1\log. I am inspecting it now...

Update:

The first thing I noticed in idea.log is the following exception:

org.gradle.tooling.GradleConnectionException: Could not run phased build action using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-7.4-bin.zip'.
...
Caused by: org.gradle.internal.jvm.JavaHomeException: The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location: C:\Program Files\Android\Android Studio\jre\bin\java.exe

Thanks to this SO tip, I did mklink /D "jre" "jbr" which all of a sudden revived Android Studio and started to download lots of Gradle related packages.

I still have "Gradle Sync issues" but at least Android Studio prompts me now how to solve them:

enter image description here

but... according to https://developer.android.com/reference/tools/gradle-api Gradle's current release is 7.4.0, why is Android Studio asking for a minimum of 7.5?

WebViewer
  • 761
  • 7
  • 21
  • What version of Gradle are you requesting in your build.gradle? `classpath 'com.android.tools.build:gradle` – MESP Jan 24 '23 at 12:34
  • @MennoSpijker See my explanation in the answer that I just posted: I initially tried `7.4.0` and I had Sync issues. So I followed the suggestion to use "minimum 7.5.0". But apparently it doesn't exist on any Maven repository. So, I reverted to 7.4.0 and all of a sudden everything synced and built perfectly. – WebViewer Jan 24 '23 at 12:50

1 Answers1

3

Problem solved.

For the benefit of all, I am posting here a summary of what I did to solve it:

  1. When a laconic "Sync failed" is all Android Studio provides, C:\Users\<yourname>\AppData\Local\Google\AndroidStudio2022.1\log\idea.log is key to finding clues to the mystery.
  2. In my case, it was failure to find and run the embedded Java version. So, I did mklink /D "jre" "jbr" which miraculously revived the build process (see https://github.com/flutter/flutter/issues/106674#issuecomment-1381685888).
  3. Under File > Settings > Build Tools > Gradle, this is the Java version that works for me:

embedded Java version

  1. I then tried to follow Sync's output to use Gradle 7.5.0. It could not be found on any of the repositories in my top level build.gradle and resulted in chasing my tail... According to https://developer.android.com/reference/tools/gradle-api Gradle's current release is 7.4.0, so I reverted to using it (why didn't it work the first time, I don't know) and here is my working top level build.gradle:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    buildscript {
        repositories {
            gradlePluginPortal()  
            mavenCentral()
            google()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:7.4.0'
            classpath("de.mannodermaus.gradle.plugins:android-junit5:1.8.2.1")
            classpath("org.mockito:mockito-inline:4.11.0")
        }
    }
    
    allprojects {
        repositories {
            gradlePluginPortal()
            mavenCentral()
            google()
        }
    

    }

WebViewer
  • 761
  • 7
  • 21