No-one
No-one

Reputation: 21

How to fix flutter_embedding_debug POM markup error when using shared_preferences in Flutter?

I am encountering an issue in my Flutter project where I get the following error message when building the project after adding the shared_preferences dependency:

Warning: SDK processing. This version only understands SDK XML versions up to 3 but an SDK XML file of version 4 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times.
[Fatal Error] flutter_embedding_debug-1.0.0-a18df97ca57a249df5d8d68cd0820600223ce262.pom:2:90: The markup in the document following the root element must be well-formed.
[Fatal Error] flutter_embedding_debug-1.0.0-a18df97ca57a249df5d8d68cd0820600223ce262.pom:2:90: The markup in the document following the root element must be well-formed.
[Fatal Error] flutter_embedding_debug-1.0.0-a18df97ca57a249df5d8d68cd0820600223ce262.pom:2:90: The markup in the document following the root element must be well-formed.
[Fatal Error] flutter_embedding_debug-1.0.0-a18df97ca57a249df5d8d68cd0820600223ce262.pom:2:90: The markup in the document following the root element must be well-formed.
[Fatal Error] flutter_embedding_debug-1.0.0-a18df97ca57a249df5d8d68cd0820600223ce262.pom:2:90: The markup in the document following the root element must be well-formed.
warning: [options] source value 8 is obsolete and will be removed in a future release
warning: [options] target value 8 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
3 warnings

The error occurs when the shared_preferences package is included as a dependency. Removing shared_preferences from the pubspec.yaml file resolves the issue, suggesting the error is related to this specific package. I am using Java 17, but Android Studio is still using Java 21 for the project build, which may also be contributing to the problem.

My Java version:

java -version
java version "17.0.12" 2024-07-16 LTS
Java(TM) SE Runtime Environment (build 17.0.12+8-LTS-286)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.12+8-LTS-286, mixed mode, sharing)

Flutter Doctor:

flutter doctor -v
[√] Flutter (Channel stable, 3.24.5, on Microsoft Windows [Version 10.0.26120.1912], locale en-IN)
    • Flutter version 3.24.5 on channel stable at C:\src\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision dec2ee5c1f (3 weeks ago), 2024-11-13 11:13:06 -0800
    • Engine revision a18df97ca5
    • Dart version 3.5.4
    • DevTools version 2.37.3

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\admin\AppData\Local\Android\Sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.3)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.8.34330.188
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2024.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = C:\Program Files\Android\Android Studio
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)

[√] VS Code (version 1.95.2)
    • VS Code at C:\Users\admin\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (4 available)
    • RMX3471 (mobile)  • 192.168.0.0:00000 • android-arm64  • Android 14 (API 34)
    • Windows (desktop) • windows           • windows-x64    • Microsoft Windows [Version 10.0.26120.1912]
    • Chrome (web)      • chrome            • web-javascript • Google Chrome 131.0.6778.87
    • Edge (web)        • edge              • web-javascript • Microsoft Edge 132.0.2957.26

[√] Network resources
    • All expected network resources are available.

• No issues found!

Android Studio Version: Android Studio Ladybug | 2024.2.1 Patch 3

settings.gradle:

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.3.2" apply false
    id "org.jetbrains.kotlin.android" version "2.0.21" apply false
}

include ":app"

app\build.gradle:

plugins {
    id "com.android.application"
    id "kotlin-android"
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id "dev.flutter.flutter-gradle-plugin"
}

android {
    namespace = "com.example.savory_chef"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = "25.1.8937393"

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.example.savory_chef"
        // You can update the following values to match your application needs.
        // For more information, see: https://flutter.dev/to/review-gradle-config.
        minSdk = flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig = signingConfigs.debug
        }
    }
}

flutter {
    source = "../.."
}

for additional info I am using the latest version of the shared_preferences package: shared_preferences: ^2.3.2

What Did I Tried: if you are gonna suggest to change the jdk version from Build, Execution, Deployment > Build Tools > Gradle or by adding jdk path in gradle.properties this both are not working in this latest version of android studio dont know why the Build Tools > Gradle does not even have a option to change the gradle jdk maybe moved I guess.

What I Need Help With: How to resolve the malformed POM file error (flutter_embedding_debug) caused by the shared_preferences dependency. How to make sure Android Studio uses Java 17 instead of Java 21 during the build process, given that java -version show that Java 17 is installed. Any additional steps I might be missing to fix the dependency conflict or POM file issue.

Upvotes: 2

Views: 587

Answers (0)

Related Questions