英文:
Could Not Resolve com.android.tools.build:gradle No Matching Variant
问题
我主要的目标是创建一个新的应用程序,只有一个空白的活动:没有花里胡哨的东西。然而,在试图成为一个好的开发者并升级gradle后,像IDE所说的那样,一切都变得混乱了。
再也无法构建任何东西,无论我把JDK放在哪里,它都找不到,无法编辑gradle依赖锁文件:问题不断。我设法解决了JDK和gradle写入问题,只是将一切都移到了其他地方,但然后我遇到了最后的问题:
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:
现在,这并不是完整的错误。完整的错误是一堆折叠的文本。然而,我可以稍微减少一点,因为这个错误有点递归:
它开始说:
> 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
之后列出了一些在特定情况下使用gradle v.7.4.1的东西,但然后出现了原始问题。
它似乎试图使用7.4.1,但不断找到7.5,但我不理解其余部分。然后记录了一个重复的错误,并集中在一些关键元素(或“变种”)周围,这些元素是:
- 'apiElements'
- 'javadocElements'
- 'runtimeElements',以及
- 'sourcesElements'
对于每一个,它都说了类似这样的话:
- Variant <insert variant here> 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
对我来说毫无意义,因为我应该使用Java...19,但也许19只是构建版本,而不是宣传版本(?)不管怎样...
“其他兼容属性:”子原因包括以下一些,我将使用列表编号来简化:
所有变种都有这个:
- 不提到org.gradle.plugin.api-version(需要'7.5')
变种2和4都有这两个:
- 不提到其目标Java版本(需要与Java 8兼容)
- 不提到其元素(需要打包成jar)
- 不提到org.gradle.plugin.api-version(需要'7.5')
现在,我想告诉你,是的,一开始我确实调整了一些设置,但当我发现没有改进时,我卸载了整个IDE,包括我的用户设置,并下载并安装了最新版本的IDE。我检查了.android文件夹,发现.lib文件夹不见了,所以也许它起作用了(???),但我不确定,因为它打开了一个旧项目。我没有删除它想要看到的任何东西。
我想使用来自另一篇帖子中的这个图片,我还试图强制它使用7.5,将7.4.1更改为7.5并将它们设置为“true”。但没有效果,所以我把它改回来。希望这些信息足以满足原始条件:
- 我告诉了你它应该做什么(只是编译:我不要求太多)
- 我告诉了你错误(gradle完全崩溃了)
- 我提供了最短的代码(几乎没有...因为这是一个gradle问题)
也许需要移动到不同的子SO:我不知道,但我在这里尽了最大努力。如果上面的所有内容都完全令人厌恶,我留下了大部分原始错误,未经修改,但正如我所说,还有一个更加压缩的版本,进一步说明,但...我想你不想看150多行的错误。
...
不过,我可以给你最顶层的错误:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'app'
...它只是说一样的事情。
英文:
My main goal was to create a new app, with just an Empty Activity: no bells nor whistles. However, after trying to be a good developer, and upgrade gradle, like the IDE said, everything went wrong.
Nothing would build anymore, it couldn't find my JDK, no matter where I put it, it couldn't edit the gradle dependency lock file: the whole nine. I managed to fix the JDK and gradle writing issue, by just moving everything, but I was then left with this last problem:
> 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:
Now, this isn't the full error. The full error, is a collapsed wall of text. However, I can reduce it a little bit, since this error is kind of recursive:
It starts out by saying:
A problem occurred configuring root project 'app'.
> 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
After that it lists a couple of things that used gradle v.7.4.1 in a particular capacity, but then the original problem occurred.
It seems like it's trying to use 7.4.1, but keeps finding 7.5, but I don't understand the rest. Then a repetitive error was logged, and centralized around some key elements (or 'variants', as they were), those elements being:
- 'apiElements'
- 'javadocElements'
- 'runtimeElements', and
- 'sourcesElements'
For each one it said something like this:
- Variant <insert variant here> capability com.android.tools.build:gradle:7.4.1 declares
a library, packaged as a jar, and its dependencies declared externally:
Then, for each one, it listed the..."reasons", why the "but:" had to be there, with the following being the parent reason:
component compatible with Java 11 and the consumer needed a runtime of a component
compatible with Java 8
which makes no sense to me, since I should be using Java...19, but maybe 19 is only the build version and not the advertised version (?) anyway...
The "other compatible attribute:" sub-reasons contained some of the following, which I will use the list numbers to simplify:
All variants had this one:
- Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
and variants 2 and 4 had both of these:
- 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)
Now, I want to let you know that, yes, I did muck about with the settings at first, but when I found I wasn't making it any better, I uninstalled the entire IDE, including my user settings, and did a fresh download and installation of the newest version of the IDE. I checked the .android folder to find the .lib folder was gone, so maybe it worked (???), but I'm not sure, since it opened up an old project. I didn't remove any of the stuff that it wanted to see.
I'd like to use this image from another post here, which I also messed with in attempt to force it to use 7.5 by changing 7.4.1 to 7.5 and setting them to "true". It didn't work, so I put it back. Hopefully this was enough information to satisfy the original conditions:
- I gave you what it was supposed to do (just compile: I'm not asking for much)
- I gave you the error (gradle broke all the way)
- I gave the shortest code (which there wasn't any...cuz it's a gradle issue)
Maybe it needs to move to a different sub-SO: I don't know, but I did my best here. Also if all above was completely abhorrent, I left most of the original error, untouched, down below. However, like I said, there is a more compressed version of this that goes even further but...I don't think you want 150+ lines of error to look at.
...
However, I can give you the top-level error:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'app'
...which just says the same thing.
- 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')
答案1
得分: 5
在Android Studio Flamingo 2022.2.1中,我打开了“文件” -> “设置”菜单,然后选择了以下选项:
构建、执行、部署
构建工具
Gradle
我选择了当前项目,在“Gradle JDK”字段中选择了“嵌入式 JDK”(即版本17.0.6)。然后点击“确定”关闭设置,接着在Gradle同步失败通知中点击“重试”。
英文:
In AndroidStudio Flamingo 2022.2.1 I opened the File -> Settings menu, then I selected
Build, Execution, Deployment
Build Tools
Gradle
I selected my current project and in the "Gradle JDK" field I selected "Embedded JDK" (which happens to be v17.0.6). Closed the settings with OK, then clicked on "Try again" in the Gradle sync failure notice.
答案2
得分: 2
我找到的方法可能不是最佳答案,但如果您进入构建设置,将JDK设置回Java 18,一切都会构建。显然,Java 19只与Gradle 7.6兼容,而IDE不会自动找到它。所以只需将它设置回与7.5兼容的版本,至少一切都会编译。如果有更好的答案,请告诉我,但我找不到其他方法。
英文:
Might not be the best answer, but I've found that if you go into the build settings, and just set the JDK back to Java 18, everything builds. Apparently, Java 19 is only compatible with gradle 7.6, which the IDE doesn't automatically find. So just set it back to one compatible with 7.5, at least, and everything compiles. If anyone has a better answer, let me know, but I couldn't find one.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论