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:
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
I solved the problem by changing the
Android Gradle Plugin Version
andGradle Version
.File > Project Structure > Project
I changed this
to
Adding Fani comment: Changing Gradle JDK to version 11 also worked for me.
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"
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
I ran into the same problem and applied the following solution :
I have changed the Gradle JDK to 11 and issue is resolved.
Had the same error and upgraded to these Gradle settings
I also changed the Gradle JDK to:
I found the same problem, I made two changes