2

When I create a new project (with the default settings, wasn't modified) in the newest Android Studio version (no more updates available) I get this message:

Build file 'C:\Users\user\AndroidStudioProjects\MyApplication\build.gradle' line: 3

Plugin [id: 'com.android.application', version: '7.2.1', apply: false] was not found in any of the following sources:

...

Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.android.application', version: '7.2.1', apply: false] was not found in any of the following sources:

Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
Plugin Repositories (could not resolve plugin artifact 'com.android.application:com.android.application.gradle.plugin:7.2.1')

Searched in the following repositories:
Gradle Central Plugin Repository
Google
MavenRepo at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:116) at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:42)

While I can open projects that were created with an older version just fine.

This is the default project structure:


build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.2.1' apply false
    id 'com.android.library' version '7.2.1' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app/build.gradle:

plugins {
    id 'com.android.application'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdk 23
        targetSdk 32
        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
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.4.2'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

settings.gradle:

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}
rootProject.name = "My Application"
include ':app'

enter image description here


I tried to lower the APG and Gradle versions, reinstall Android Studio, reset to default settings, but it still fails.
How can I resolve this error?

ATP
  • 2,939
  • 4
  • 13
  • 34
  • Check your settings.gradle. Now repository downloads are moved to there – Gobu CSG Jun 25 '22 at 18:16
  • @GobuCSG see update – ATP Jun 26 '22 at 03:53
  • Gradle 7 and above Java 11 required. If not download and install it then restart your studio. – Gobu CSG Jun 26 '22 at 05:09
  • @GobuCSG I'm using java 11 and the gradle is 7.3.3 as you can see – ATP Jun 26 '22 at 05:25
  • I think it's known issue https://issuetracker.google.com/228336564 Try this id 'com.android.application' version '7.1.2' apply false distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip – Gobu CSG Jun 26 '22 at 05:46
  • @ATP let's try this `File`>`Sync Project with Gradle Files`. Make sure that your grade toggle is online mode see this image https://img-bc.icode.best/f584bfba8109455d9f583e01ed15ba62.png – M DEV Jun 26 '22 at 17:47

3 Answers3

1

The message means that you are defining a dependency that can not be found in any of the repositories that are defined in settings.gradle. This file can be found in your project root folder.

Maybe your gradle cache is having problems. Try to invalidate all caches in Android Studio and restart it: File -> Invalidate Caches -> Invalidate and Restart

muetzenflo
  • 5,653
  • 4
  • 41
  • 82
  • Doesn't work, As I said, I also reinstalled android studio and it doesn't work. – ATP Jun 26 '22 at 03:52
  • could you list the "sources" that is listed below the message please? – muetzenflo Jun 26 '22 at 15:58
  • Here are some ideas to the same problem: https://stackoverflow.com/questions/70947176/bumblebee-android-studio-plugin-id-com-android-application-version-7-1-0 – muetzenflo Jun 27 '22 at 09:40
  • Tried them all, still doesn't work. It seems to be a bug. I opened an issue on issuetracker waiting for their response. – ATP Jun 27 '22 at 09:55
1

Turned out to be a problem with the internet supply which blocked the access to the google() repository.
Using hotspot solved the problem.

ATP
  • 2,939
  • 4
  • 13
  • 34
0

Check following things: in gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

In android studio preferences Build,Execut....>Build Tools>Gradle Set Use Gradle from gradle-wrapper.properties file and Gradle JDK to 11

mohit48
  • 712
  • 7
  • 9