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 新建了一個(gè)Kotlin項(xiàng)目,. 之類的提示沒有,應(yīng)該是環(huán)境問題,就升級(jí)了Android Studio到最新的電鰻版本,新建kotlin項(xiàng)目就報(bào)上述錯(cuò)誤。
? ? ? 搜索了一圈,原來是gradle插件7.4.2版本比較新,需要Java11,以前配置的是Java8,修改下配置就可以了,以mac電腦為例,操作如下:
1、左上角 File ------- Project Structure, 如圖:
?2、SDK Location -----------? Gradle Settings ,如圖:
?3、Gradle JDK, 選擇11的,點(diǎn)擊OK , 如圖:
?4、Settings.gradle文件里,配置一些倉(cāng)庫(kù)地址,如圖:
?代碼如下:
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、點(diǎn)擊同步按鈕,下載相應(yīng)的庫(kù),如圖:
6、 等待下載完畢,可能需要幾分鐘到幾十分鐘,只要下載進(jìn)度是對(duì)的,就OK,如圖:
7、. 已經(jīng)可以正常提示語(yǔ)法了
文章來源:http://www.zghlxwxcb.cn/news/detail-428989.html
好了,又可以愉快的玩耍了。文章來源地址http://www.zghlxwxcb.cn/news/detail-428989.html
到了這里,關(guān)于Android Studio 解決Could not resolve com.android.tools.build:gradle:7.4.2問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!