cvc-complex-type.2.4.a: Invalid content was found starting with element 'base-extension'. One of '{layoutlib}' is expected
Asked Answered
T

8

120

I am facing this issue many times when i download project from github i am using new Android studio(bumble bee) please help me if any body knows

https://github.com/fjbatresv/arcore_solar_system.git (this is the project which i am downloading in bumble bee)

There are not any gradle issue

actually i have tried many solutions from stack over flow but i am getting solutions for gradle but it is not an gradle related error.

Tawannatawdry answered 29/3, 2022 at 7:57 Comment(1)
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.Triform
M
146

Upgrade your com.android.tools.build:gradle in your build.gradle file to the latest version

e.g.

classpath 'com.android.tools.build:gradle:7.0.4'

And upgrade your gradle-wrapper.properties to the latest version i.e.

#Tue Apr 12 23:39:17 AEST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

Optionally, you can upgrade it using Project-Structure UI

enter image description here

Matrimony answered 12/4, 2022 at 13:59 Comment(4)
It also needs JDK 11 or above to be used. So please update that as well if you apply the above solution.Seasickness
To update the project to compile with Java 11, goto Android Studio ➔ File ➔ Project Structure ➔ SDK Location ➔ click Gradle Settings ➔ Gradle JDK = 11Finbur
What if you can't or don't want to update? It's pretty concerning how "just update to the latest" has become a commonly recommended (and readily accepted) "fix" for things that should have never been broken in the first place. In this case, the root cause was very likely a mistake, as described by @dont-panic below, and can be resolved without changing any versions.Gospodin
Rather than just update to the latest, the com.android.tools.build:gradle version number should match the latest patch version of the plugin that corresponds to the version of Gradle being run... which can be found here: developer.android.com/build/releases/… So if you are using Gradle 7.3.3, for example, you need the plugin version to be 7.2.x You can find all the plugin versions at mvnrepository.com/artifact/com.android.tools.build/… - and so select 7.2.2 Perhaps I should make this a separate answer?Bewick
B
19

Upgrade your Android Gradle plugin version to 4.0.1 or higher in the project build.gradle file

buildscript {
    dependencies {
        classpath("com.android.tools.build:gradle:4.0.1")
        ...
    }
}

Upgrade the Gradle version to 6.5 or higher in the gradle-wrapper.properties file.

distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
Bunch answered 13/9, 2022 at 13:24 Comment(0)
S
16

I was facing same issue and solved it with following changes

In File -> Project Structure, set Android Gradle Plugin Version 7.0.3 And Gradle Version 7.0.2.

Schizogony answered 13/5, 2022 at 18:30 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Triform
B
6

I solved the problem after digging into the source code and some experiments.

Android SDK configuration file ~/Library/Android/sdk/platforms/android-32/package.xml has an extra tag named base-extension compared to the same file of other API levels. Removing this tag solves the problem.

Delete downloaded Android API 32 SDK Platform from SDK Manager (ToolsSDK Manager) also solves the problem (you can redownload after deletion). Maybe the Android studio team noticed the problem, redownloading API 32 platform files, the base-extension tag disappeared from the API 32 package.xml

the extra tag in android-32/package.xml (after format the file)

↑ the extra tag in android-32/package.xml (after formatting the file)

Bullyboy answered 17/8, 2022 at 4:55 Comment(1)
Wow that's a great find. Thanks!Gospodin
L
5

For me I resolved by

Go to File > Project Structure > SDK Location > Gradle Settings.

Check there Gradle JDK, try changing it and then sync again.

solution

Lardner answered 23/5, 2022 at 11:42 Comment(1)
Note: that to find the gradle settings there is a text link "JDK Location was moved to "Gradle Settings" You can see part of this text link in the screen shot just behind the pop-upAlabaster
P
5

I also faced similar issue. cvc-complex-type.2.4.a: Invalid content was found starting with element 'base-extension'. One of '{layoutlib}' is expected. Finally i was able to fix this issue, by Go To File>>Settings>>Build, Execution, Deployment>Build Tools And I am enable "Reload project after changes in the build scripts">Any changes after this Appeared new Error "Add Google maven repository" I add Google maven repository to build.gradle and project worked without any errors enter image description here

Psychodiagnosis answered 14/6, 2022 at 14:33 Comment(0)
A
0

Only classpath 'com.android.tools.build:gradle:7.0.4' is sufficient.

Arvid answered 4/11, 2023 at 21:41 Comment(0)
M
-1

In my case, one of my classpath depencencies had double quotes, once I changed it to single quotes, it worked fine.

Example, change:
classpath "com.android.tools.build:gradle:3.4.1"

To:
classpath 'com.android.tools.build:gradle:3.4.1'

Mckie answered 5/10, 2023 at 17:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.