Android Studio构建新项目错误

Android Studio构建gradle 新项目错误

  1. 报错
Build file 'D:\Android\WeatherApp\build.gradle' line: 3

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

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.android.application', version: '7.1.2', 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.1.2')
  Searched in the following repositories:
    Gradle Central Plugin Repository
    Google
    MavenRepo
	
  1. 解决

    1. 路径:Gradle Scripts > build.gradle
    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    buildscript {
        repositories {
            //        google() //注释这行
            //        mavenCentral() //注释这行
            maven { url 'https://plugins.gradle.org/m2/' } //复制这行
            maven { url 'https://maven.aliyun.com/nexus/content/repositories/google' } //复制这行
            maven { url 'https://maven.aliyun.com/nexus/content/groups/public' } //复制这行
            maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'} //复制这行
        }
        dependencies {
            classpath "com.android.tools.build:gradle:7.0.4"
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    plugins {
    //    id 'com.android.application' version '7.1.2' apply false
    //    id 'com.android.library' version '7.1.2' apply false
        id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    
    
    1. 路径:Gradle Scripts > settings.gradle
    dependencyResolutionManagement {
    		    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    		    repositories {
    		//        google() //注释这行
    		//        mavenCentral() //注释这行
    		//        jcenter() // Warning: this repository is going to shut down soon //注释这行
    		
    		        maven { url 'https://plugins.gradle.org/m2/' } //复制这行
    		        maven { url 'https://maven.aliyun.com/nexus/content/repositories/google' } //复制这行
    		        maven { url 'https://maven.aliyun.com/nexus/content/groups/public' } //复制这行
    		        maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'} //复制这行
    		    }
    		    rootProject.name = "My Application" //项目名称
    		    include ':app'
    		}