A problem occurred configuring root project 'MyApplication2'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:7.4.2.
Required by:
project : > com.android.application:com.android.application.gradle.plugin:7.4.2
project : > com.android.library:com.android.library.gradle.plugin:7.4.2
> No matching variant of com.android.tools.build:gradle:7.4.2 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.2 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.2 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.2 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.2 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')
昨天用老版本的Android Studio 新建了一个Kotlin项目,. 之类的提示没有,应该是环境问题,就升级了Android Studio到最新的电鳗版本,新建kotlin项目就报上述错误。
搜索了一圈,原来是gradle插件7.4.2版本比较新,需要Java11,以前配置的是Java8,修改下配置就可以了,以mac电脑为例,操作如下:
1、左上角
File
-------
Project Structure
, 如图:
2、
SDK Location
-----------
Gradle Settings
,如图:
3、
Gradle JDK
, 选择11的,点击OK , 如图:
4、Settings.gradle文件里,配置一些仓库地址,如图:
代码如下:
pluginManagement {
repositories {
maven { url 'https://maven.aliyun.com/repository/releases' }
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url "https://www.jitpack.io" }
google()
mavenCentral()
gradlePluginPortal()
jcenter()
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
maven { url 'https://maven.aliyun.com/repository/releases' }
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url "https://www.jitpack.io" }
google()
mavenCentral()
jcenter()
rootProject.name = "MyApplication2"
include ':app'
5、点击同步按钮,下载相应的库,如图:
6、 等待下载完毕,可能需要几分钟到几十分钟,只要下载进度是对的,就OK,如图:
7、. 已经可以正常提示语法了
好了,又可以愉快的玩耍了。
昨天用老版本的Android Studio 新建了一个Kotlin项目,. 之类的提示没有,应该是环境问题,就升级了Android Studio到最新的电鳗版本,新建kotlin项目就报上述错误。好了,又可以愉快的玩耍了。
升级完AndroidStudio3.6.1编译项目报错:
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all artifacts for configuration ‘:classpath’.
提示错误:Read Time out
即使开了梯子依然下载超时,我们更换为阿里云的maven库,下载速度会更快一点。
将原来配置:
repositories {
google()
A problem occurred configuring root project 'DataBinding'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:7.4.2.
关于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/...
按官方配置好了 developer.huawei.com/repo/ 点击同步 Sync Now 会报以下错误
Could not resolve com.huawei.agconnect
解决方法:把相应的插件用本地化安装
agconnect-crash-symbol-lib-1.6.1.300.jar
agconnect-apms-plugin-1.6.1.300.jar
agcp-1.6.1.300.jar。
解决java.lang.NullPointerException Attempt to read from field 'int android.view.View.mViewFlags' on a
30638