今天新建了一个工程,报了如下错误
A problem occurred configuring root project 'My Application'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:7.4.1.
Required by:
project : > com.android.application:com.android.application.gradle.plugin:7.4.1
project : > com.android.library:com.android.library.gradle.plugin:7.4.1
> No matching variant of com.android.tools.build:gradle:7.4.1 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.1 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.1 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.1 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.1 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')
这个原因是最新的AndroidStudio 所用的gradle需要使用jdk11才能构建 ,因此要更改AndroidStudio的jdk版本
我的AndoirdStudio版本是
gradle版本用的是
解决方案如下,
打开如下页面。
File -> ProjectStructure -> Gradle Setting . -> Gradle JDK
关于Could not
resolve
com
.
android
.
tools
.
build
:
gradle
:x.x.x的问题,可以在项目的
build
.
gradle
文件加入google()
这里有个小提醒,尽量将google()放在jcenter()上面
这个问题基本是墙的问题,所以如果上面方法无效,可以试下下面的方法,一样是在项目的
build
.
gradle
文件加入一段代码
maven{url'http://maven.aliyun.
com
/nexus/content/repositories/...
使用Flutter引入pub的时候经常遇到
gradle
版本下载失败的问题,这里原因是因为国外资源被墙的原因,因此我们需要更换成国内资源即可(以上
gradle
:xx.xx.xx代表任意版本)。
首先附上异常图示例:
分解异常问题:
(上图)异常发生位置:flutter_absolute_path,这里我在pubspec.yaml添加了flutter_absolute_path第三方库,然后这个第三方库的
gradle
的版本是3.4.1,在flutter pub get同步的时候并没有找到这个对应版本的gra
Could not find
com
.
android
.
tools
.
build
:
gradle
:4.2.2.
Could not find
com
.
android
.
tools
.
build
:
gradle
:4.2.2.
Searched in the following locations:
- https://jcenter.bintray.
com
/
com
/
android
/
tools
/
build
/
gradle
/4.2.2/
gradle
-4.2.2.pom
- https://jcenter
在使用
Android
Studio
这个IDE时,出现
com
.
android
.
tools
.
build
:
gradle
:X.XX.XX:
gradle
.jar插件无法下载问题
可能的原因就是网速不好或者依赖仓库的下载网址被墙了,可以配置代理试试。比如,
android
studio
定义的默人依赖仓库为jcenter()仓库.如下
打开项目下的
build
.
gradle
文件,不是Module下