flutter_local_notifications icon indicating copy to clipboard operation
flutter_local_notifications copied to clipboard

Dependency ':flutter_local_notifications' requires core library desugaring to be enabled for :app

Open esaiamuthan opened this issue 1 year ago • 12 comments
trafficstars

Execution failed for task ':app:checkDevDebugAarMetadata'.

A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction An issue was found when checking AAR metadata:

   1.  Dependency ':flutter_local_notifications' requires core library desugaring to be enabled
       for :app.

       See https://developer.android.com/studio/write/java8-support.html for more
       details.

Hi @here am facing this issue after updating to gradle 8.5.0 version in Android Studio Can anyone help me on this ?

esaiamuthan avatar Aug 16 '24 14:08 esaiamuthan

I have got the same issue. The error asks to use this code below

compileOptions {
        // Flag to enable support for the new language APIs
        coreLibraryDesugaringEnabled true
        // Sets Java compatibility to Java 8
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

but it is deprecated and should not be used.

PollyGlot avatar Aug 19 '24 16:08 PollyGlot

I also have same issue. gradle:8.2.0

hajini avatar Sep 24 '24 10:09 hajini

@PollyGlot do you have a link to a repo hosting a minimal app that shows that what is there is deprecated and shouldn't be used? I updated the example app to AGP 8.6.0, built a release APK and didn't see deprecation warnings

MaikuB avatar Sep 28 '24 08:09 MaikuB

same issue solved by adding in app/build.gradle

compileOptions {
   ......//
    coreLibraryDesugaringEnabled true
}

and 
dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2'
}

ujwal-yadav-aot avatar Oct 04 '24 11:10 ujwal-yadav-aot

dependencies { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2' }

This works !!!

shibakar avatar Oct 08 '24 08:10 shibakar

This works !!!

This works because you're setting the desugaring configurations.

The point is: you are using scheduled notifications? If you're not using it, you should not implement this desugaring configurations. As readme says here, we should configure desugaring only if we will use scheduled notifications: https://pub.dev/packages/flutter_local_notifications#gradle-setup

I've commented this in another similar topic: https://github.com/MaikuB/flutter_local_notifications/issues/2405#issuecomment-2466279883

marcellocamara avatar Nov 09 '24 16:11 marcellocamara

Just to clarify, you should be enabling desugaring whether or not you are using scheduled notifications.

See the next version of the Android setup guide for details, desugaring is right up there

Levi-Lesches avatar Dec 03 '24 10:12 Levi-Lesches

Should I do in my project or modify flutter_local_notifications?

lucasjinreal avatar Jan 27 '25 12:01 lucasjinreal

flutter version >= 3.29

path:android/app/build.gradle.kts

android {
    compileOptions {
        ...
        isCoreLibraryDesugaringEnabled = true
    }
}

and

dependencies {
  coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.4")
}

xiaohu386 avatar Mar 10 '25 08:03 xiaohu386

It is advisable to avoid using high-level APIs on older versions of Android. maybe need someone's pr to remove coreLibraryDesugaring

lwj1994 avatar Mar 18 '25 09:03 lwj1994

I have the same issue

z244370114 avatar Jun 03 '25 01:06 z244370114

I have same issue. Any update ?

burakJs avatar Jun 10 '25 10:06 burakJs

@burakJs this issue happens when desugaring hasn't been enabled and hence why the error says this as well. This is also why there are others in the thread that mentioned the Gradle changes they did the changes to enable it. Those encountering this issue will need to check the readme to follow the instructions as it is called out there as part of the Android setup steps. I'm going to close this as this becoming a longer thread. Should anyone else be posting about this issue, please check the readme first. If you have actually enabled it and then still had an issue then please file a new issue and include a link to a repository hosting a minimal app

MaikuB avatar Jun 10 '25 11:06 MaikuB

flutter version >= 3.29

path:android/app/build.gradle.kts

android {
    compileOptions {
        ...
        isCoreLibraryDesugaringEnabled = true
    }
}

and

dependencies {
  coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.4")
}

yep, worked!

aryanjha256 avatar Aug 13 '25 17:08 aryanjha256

The notion that a notification library should dictate a build feature level for the user is in my opinion insane. This is the only thing that forces us to use corelibrarydesugaring which increases build time and app size.

ezamelczyk avatar Sep 16 '25 09:09 ezamelczyk

agree. It can be divided into two different versions: one with corelibrarydesugaring and one without corelibrarydesugaring. Even learn from Apple: if older versions are no longer supported, then there is no need for corelibrarydesugaring

lwj1994 avatar Sep 18 '25 04:09 lwj1994

@ezamelczyk I couldn't find any sources that show a significant, non-negligible cost with desugaring that would justify not having those APIs available. I'm also not sure since when dependencies weren't allowed to affect the build process -- isn't managing dependencies like the whole point of CMake? Flutter code by itself doesn't use more Android APIs, but using plugins does, and so needing to configure settings to get those features is a pretty natural consequence of... using those features.

As mentioned above, I am working on writing some clearer documentation for setting up on all platforms (#2477). That should help with those who are confused as this is actually in the README at the moment.

Levi-Lesches avatar Sep 18 '25 06:09 Levi-Lesches

flutter version >= 3.29

path:android/app/build.gradle.kts

android {
    compileOptions {
        ...
        isCoreLibraryDesugaringEnabled = true
    }
}

and

dependencies {
  coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.4")
}

after replacing coreLibraryDesugaringEnabled = true to isCoreLibraryDesugaringEnabled = true it work fine

Developerleveler avatar Sep 29 '25 11:09 Developerleveler

@ezamelczyk I couldn't find any sources that show a significant, non-negligible cost with desugaring that would justify not having those APIs available. I'm also not sure since when dependencies weren't allowed to affect the build process -- isn't managing dependencies like the whole point of CMake? Flutter code by itself doesn't use more Android APIs, but using plugins does, and so needing to configure settings to get those features is a pretty natural consequence of... using those features.

As mentioned above, I am working on writing some clearer documentation for setting up on all platforms (#2477). That should help with those who are confused as this is actually in the README at the moment.

We're using gradle not CMake, and if it were up to me there wouldn't even be flutter in our project but unfortunately higher-ups decided it's cheaper to make some screens in flutter and import them into our existing native app. There's a significant performance impact if one small library in a small module enables desugaring for an almost 1m loc project.

ezamelczyk avatar Sep 30 '25 12:09 ezamelczyk