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

Abnormal analysis

The AndroidStudio project has the following error when building:

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.

insert image description here
The following error notification appears in the new version of AndroidStudio:
insert image description here
This is caused by the conflict between the default JDK version of Android Studio and the JDK required by Gradle configured in the project. It is required to select the same version of JDK.

solution

In the pop-up error notification, select Select the Gradle JDK location
insert image description here
to pop up the Gradle settings, and change the default JDK to the same version as the project.
insert image description here
Or go to Preferences->Build, Execution, Deployment->Build Tools->Gradle, and change the Gradle user home and the Gradle JDK of the project to the same version directory.
insert image description here

The directory under /Applications/Android Studio Preview.app cannot be selected on the Mac . You can directly enter the specific address of /Applications/Android Studio Preview.app/Contents/jbr/Contents/Home in the application.
The modified JDK version is set according to the requirements of the project. If some require JDK8 or above ( required compatibility with Java 8 ), choose JDK8 or above.

Guess you like

Origin blog.csdn.net/CJohn1994/article/details/126882187