问题描述
使用 Android Studio 新建项目时,无法同步。根据报错信息翻译,没有找到对应的插件,但是仍未找到有效的解决办法。
问题出现的平台版本
Android Studio 版本信息
Android Studio Bumblebee | 2021.1.1 Patch 3
Build #AI-211.7628.21.2111.8309675, built on March 17, 2022
Runtime version: 11.0.11+9-b60-7590822 amd64
VM: OpenJDK 64-Bit Server VM by Oracle Corporation
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 1280M
Cores: 4
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: org.jetbrains.kotlin (211-1.6.21-release-334-AS7442.40)JDK & Gradle 版本
Java 使用 8/11/15 版本、Gradle 版本使用 7.1/7.2 版本,均出现类似问题
其他版本
Windows 10 家庭中文版 21H1 内部版本 19043.1466
相关代码
./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.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}- Android Studio 报错信息
Build file 'E:\...\AndroidEnglishProjectNameTest\build.gradle' line: 4
Plugin [id: 'com.android.library', 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.library', 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.library:com.android.library.gradle.plugin:7.1.2')
Searched in the following repositories:
Gradle Central Plugin Repository
Google
MavenRepo已经尝试过的方法
- 更换 JDK 版本(复现)
- 更换 Gradle 版本
- 项目名称更换英文
- 路径全部更换为英文
- 使用 HTTP 代理、排除
dl.google.com并且禁用 HTTPS 启用代理 - 复制其他项目中的
./build.gradle用于替换新建项目中对应文件 - 在
./build.gradle文件中创建并不存在的buildscript等节点 - 仓库中添加阿里的
maven仓库
尝试在
./settings.gradle文件中的pluginManagement.repositories节点添加如下代码(添加阿里云的仓库),如果已经添加的调整为第一个节点如果再次出现此问题,需要尝试更换 JDK 版本,至少是 JDK 11。