51

After I update the target Android SDK from 30.0.3 to 31.0.0 I started to have these 2 warnings :

This version only understands SDK XML versions up to 2 but an SDK XML file of version 3 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times.

Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>

I tried to update all the libraries but it didn't help. Anyone had this warning ?

Edhar Khimich
  • 1,468
  • 1
  • 17
  • 20
  • 2
    I also have the exact same issue since changing to 31.0.0 – DanMossa Dec 05 '21 at 22:18
  • You might get that if mixing up or upgrading components. I could remove the 'SDK XML' message by doing a 'Clean Project' after messing with Studio versions. The 'unexpected element' issue is bothering me for a while. Seems it has to do with the inner 'repository' XML files. The 'sdk-repository' element shows on line 304 an example. I assume the warning can be ignored. See https://github.com/eagletmt/android-repository-history/blob/master/repository/repository2-1.xml#L304 – Michael Jan 17 '22 at 16:28

8 Answers8

15

This is caused by using a newer version of commandline-tools to download the packages of Android SDK, while your project is probably using an older version of Gradle.

Enter your Android SDK directory and delete everything but the licenses folder. Try to rebuild your project and Gradle will redownload all the tools needed. This time the warning won't be logged.

Petrakeas
  • 1,521
  • 15
  • 28
4

Answer from an "official" source:

As mentioned in the message, this is happening because you have some packages that were installed that are using the v3 format for package.xml, but then reading it with a tool that only knows about v2. Probably you installed some components using the canary studio. If you want to you could uninstall the problem components and reinstall using sdkmanager or the stable studio. Or you could just ignore the message for now, until the new cmdline-tools is out, which should happen alongside the next studio stable release. -- https://issuetracker.google.com/issues/207386175#comment3

TWiStErRob
  • 44,762
  • 26
  • 170
  • 254
2

It come from an update of Gradle after installation of Android SDK PLateforms & an application's build.

This require reinstallation of SDK Plateforms & delete/rebuild of application.

To remove the warning :

  • Uninstall SDK Plateforms>Android SDK Platform XX
  • Delete all files built by the application (build folder, gradle files, …)
  • re-Install SDK Plateforms>Android SDK Platform XX
  • Build application

Source : https://titanium.dzzd.net/t/gradle-warning-message-during-building/36/8?u=dzzd

DzzD
  • 31
  • 3
1

thanks for the answers,

for my case I had to "Sync Project With Gradle files" instead of deleting them

in addition to

  • delete and resinstall the SDK (no impact done alone)
  • In the SDK Manager I also install the new command-line tool
Delcroip
  • 101
  • 1
  • 3
1

As mentioned in other answers this is caused by the project using a different gradle version after an Android Studio update or using in a newer installation, I installed a fresh copy of flutter and android studio in a new pc to compare projects, extracted the differences in the configuration and made the following changes to the project:

  1. in the android/gradle/wrapper/gradle-wrapper.properties update the gradle files; from(example):

    distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip

to:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip

(inverting the numbers was just a coincidence)

  1. in the android/gradle/build.gradle file update the buildscript.dependencies to gradle version 7.2.0; from(example):

    dependencies { classpath 'com.android.tools.build:gradle:4.1.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" }

to:

dependencies {
        classpath 'com.android.tools.build:gradle:7.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

(the wrapper and properties version don't match identically)

3)in the android/local.properties make sure you have the correct minSdkVersion and compileSdkVersion;from(example):

flutter.minSdkVersion=26
flutter.targetSdkVersion=31

to:

flutter.minSdkVersion=26
flutter.targetSdkVersion=33
flutter.compileSdkVersion=33
  1. run:

    flutter pub outdated

    flutter pub upgrade

    flutter clean

    flutter pub get

Note: you may have to replace packages due to compatibility, in my case I had to drop package_info for package_info_plus and upgraded other packages.

Eliezer Garza
  • 327
  • 2
  • 7
0

I have been working on my project for two months but when I export into flutter build appbundle brings the same error.

Solution it's to delete the Android sdk latest and search on Google for later version of 2 and install the sdk commandtool line and it will work, errors all gone.

Flutter build appbundle success.

0

For me, it was caused due to using an outdated dependency when I upgraded the app's targetSdkVersion. It was happening because Espresso was using an Android Manifest file that was compatible with an older version of Android. When the manifest merged while building, it showed me that error. So I just upgraded the espresso version to the latest version available. In the upgraded version it was using an Android Manifest file that was compatible with the latest Android version (or the one to which I have upgraded the app).

Prem Thakur
  • 72
  • 1
  • 8
-1

Try to uninstall the current Android studio and download the later like Android studio 4.1.3 and and Android api 30.

Ryan M
  • 18,333
  • 31
  • 67
  • 74