解决Build failed:Could not resolve com.android.tools.build:gradle:7.4.0-alpha10.

Posted 言并肃

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决Build failed:Could not resolve com.android.tools.build:gradle:7.4.0-alpha10.相关的知识,希望对你有一定的参考价值。

异常分析

androidStudio的项目在build时出现下面的报错:

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring root project ‘TestApp’.
    Could not resolve all files for configuration ‘:classpath’.
    Could not resolve com.android.tools.build:gradle:7.4.0-alpha10.
    Required by:
    project : > com.android.application:com.android.application.gradle.plugin:7.4.0-alpha10
    project : > com.android.library:com.android.library.gradle.plugin:7.4.0-alpha10
    No matching variant of com.android.tools.build:gradle:7.4.0-alpha10 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.0-alpha10 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.0-alpha10 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.0-alpha10 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.0-alpha10 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’)

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


新版本的AndroidStudio出现下面的错误通知:

此为Android Studio默认的JDK版本与项目配置的Gradle所需的JDK不一致导致冲突所致。要求选择同一版本的JDK。

解决方案

在弹出的错误通知中,选择 Select the Gradle JDK location

弹出Gradle设置,将默认的JDK改为和项目一样的版本。

或者进入Preferences->Build,Execution,Deployment->Build Tools->Gradle中,将Gradle user home和项目的Gradle JDK改为一样的版本目录。

Mac上无法选择 /Applications/Android Studio Preview.app 下的目录,可以直接输入 /Applications/Android Studio Preview.app/Contents/jbr/Contents/Home 在应用程序中的具体地址。
修改的JDK版本按项目要求来设置,有些需要JDK8以上(required compatibility with Java 8)则选择JDK8以上版本。

AS中加载gradle时出现Gradle sync failed: Could not find com.android.tools.build:gradle.的错误

 

时间:2019/12/7

 

这次接着整理加载gradle时出现的错误

 

出现的错误:

1 Gradle sync failed: Could not find com.android.tools.build:gradle:3.5.0.  
2          Searched in the following locations:  
3          file:/F:/studio/studio2.0/gradle/m2repository/com/android/tools/build/gradle/2.8/gradle-2.8.pom  
4          file:/F:/studio/studio2.0/gradle/m2repository/com/android/tools/build/gradle/2.8/gradle-2.8.jar  
5          https://jcenter.bintray.com/com/android/tools/build/gradle/2.8/gradle-2.8.pom  
6          https://jcenter.bintray.com/com/android/tools/build/gradle/2.8/gradle-2.8.jar  
7          Required by:  
8          :TestApk:unspecified  
9          Consult IDE log for more details (Help | Show Log)

 

解决方法:

1.在bulid.gradle(project)文件的相应地方中添加google(),如下图(一共要在两个地方加):

 1 buildscript {
 2     repositories {
 3         //添加
 4         google()
 5         jcenter()
 6     }
 7     dependencies {
 8         classpath \'com.android.tools.build:gradle:3.1.1\'
 9 
10         // NOTE: Do not place your application dependencies here; they belong
11         // in the individual module build.gradle files
12     }
13 }
14 
15 allprojects {
16     repositories {
17      //添加
18         google()
19         jcenter()
20     }
21 }
22 
23 task clean(type: Delete) {
24     delete rootProject.buildDir
25 }

2.重新编译

 

参考博文:https://www.cnblogs.com/xiaoxiaoyibu/p/8830826.html

 

以上是关于解决Build failed:Could not resolve com.android.tools.build:gradle:7.4.0-alpha10.的主要内容,如果未能解决你的问题,请参考以下文章

AS中加载gradle时出现Gradle sync failed: Could not find com.android.tools.build:gradle.的错误

Push failed: Failed with error: fatal: Could not read from remote repository

pytthon问题 pytcharm Automatic upload failed: could not resolve file “sftp://10.xx.xx.xx 已解决

git clone failed. Could not read from remote repository

fatal: Authentication failed could not read from remote repository

fatal: Authentication failed could not read from remote repository