skip to Main Content

After updating my Android Studio to the latest version i.e. Electric Eel | 2022.1.1, I got "Gradle project sync failed" after creating a new project.

Error:

A problem occurred configuring root project 'BIAssignment'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:7.4.0.
     Required by:
         project : > com.android.application:com.android.application.gradle.plugin:7.4.0
         project : > com.android.library:com.android.library.gradle.plugin:7.4.0
      > No matching variant of com.android.tools.build:gradle:7.4.0 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.5' but:
          - Variant 'apiElements' capability com.android.tools.build:gradle:7.4.0 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
          - Variant 'javadocElements' capability com.android.tools.build:gradle:7.4.0 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
          - Variant 'runtimeElements' capability com.android.tools.build:gradle:7.4.0 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
          - Variant 'sourcesElements' capability com.android.tools.build:gradle:7.4.0 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')

I have already tried Invalidating Cache and changing Gradle version from Project Structure but neither of them worked. I also tried disabling Flutter plugin, but none of these methods work please help me solving this problem.

My current project structure:

enter image description here

enter image description here

build.gradle

plugins {
    id 'com.android.application' version '7.4.0' apply false
    id 'com.android.library' version '7.4.0' apply false
}

build.gradle

plugins {
    id 'com.android.application'
}

android {
    namespace 'com.biassignment'
    compileSdk 33

    defaultConfig {
        applicationId "com.biassignment"
        minSdk 24
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildFeatures {
        viewBinding true
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.6.0'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.navigation:navigation-fragment:2.5.3'
    implementation 'androidx.navigation:navigation-ui:2.5.3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

6

Answers


  1. Chosen as BEST ANSWER

    I solved the problem by changing the Android Gradle Plugin Version and Gradle Version.

    File > Project Structure > Project

    I changed this

    enter image description here

    to

    enter image description here


    Adding Fani comment: Changing Gradle JDK to version 11 also worked for me.

    1. File > Settings > Build, Execution, Deployment > Build Tools > Gradle.
    2. Change the Gradle JDK to version 11.

  2. Ok as I see all the thing is right just go to :

    Project structure –> Modules
    and change the Source $ Target compatibility from "$JavaVersion.VERSION_1_8" to "$JavaVersion.VERSION_11"

    Login or Signup to reply.
  3. I had the same problem after upgrading Android Studio. You can reset Android Studio to its default state by following the instructions in the "Known Issues with Android Studio" page at section "Studio doesn’t start after upgrade".

    Reset Android Studio state: https://developer.android.com/studio/known-issues#studio-config-directories

    Caution: All third-party plugins will be removed when you do this

    By the way, changing the gradle version also worked for me (this answer).

    I never answered a question before, please tell me if I’m missing something

    Login or Signup to reply.
  4. I ran into the same problem and applied the following solution :

    I have changed the Gradle JDK to 11 and issue is resolved.

    Login or Signup to reply.
  5. Had the same error and upgraded to these Gradle settings

    enter image description here

    I also changed the Gradle JDK to:

    enter image description here

    Login or Signup to reply.
  6. I found the same problem, I made two changes

    1. Change in Project structure

    enter image description here

    1. Change in Gradle for the following steps are required:
    Settings > Build, Execution, Deployment > Build Tools > Gradle
    

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search