Flutter crash in Android 12l with "No interface method addWindowLayoutInfoListener"

In flutter app development, Sometimes you may have seen  "Android 12| No interface method addWindowLayoutInfoListener" this type of error. This error might occur when you are using flutter_local_notifications. So in this article, I will share with you how to solve this type of error.

Error:

E/AndroidRuntime(13862): FATAL EXCEPTION: main
E/AndroidRuntime(13862): Process: de.roegmbh.checkit, PID: 13862
E/AndroidRuntime(13862): java.lang.NoSuchMethodError: No interface method addWindowLayoutInfoListener(Landroid/app/Activity;Lj$/util/function/Consumer;)V in class Landroidx/window/extensions/layout/WindowLayoutComponent; or its super classes (declaration of 'androidx.window.extensions.layout.WindowLayoutComponent' appears in /system_ext/framework/androidx.window.extensions.jar)
E/AndroidRuntime(13862):    at androidx.window.layout.ExtensionWindowLayoutInfoBackend.registerLayoutChangeCallback(ExtensionWindowLayoutInfoBackend.kt:68)
E/AndroidRuntime(13862):    at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invokeSuspend(WindowInfoTrackerImpl.kt:52)
E/AndroidRuntime(13862):    at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invoke(Unknown Source:8)
E/AndroidRuntime(13862):    at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invoke(Unknown Source:4)
E/AndroidRuntime(13862):    at kotlinx.coroutines.flow.SafeFlow.collectSafely(Builders.kt:61)
E/AndroidRuntime(13862):    at kotlinx.coroutines.flow.AbstractFlow.collect(Flow.kt:212)
E/AndroidRuntime(13862):    at androidx.window.java.layout.WindowInfoTrackerCallbackAdapter$addListener$1$1.invokeSuspend(WindowInfoTrackerCallbackAdapter.kt:96)
E/AndroidRuntime(13862):    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
E/AndroidRuntime(13862):    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
E/AndroidRuntime(13862):    at android.os.Handler.handleCallback(Handler.java:942)
E/AndroidRuntime(13862):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(13862):    at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime(13862):    at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime(13862):    at android.app.ActivityThread.main(ActivityThread.java:7898)
E/AndroidRuntime(13862):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(13862):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime(13862):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

 

Cause of Error:

When you are using flutter_local_notifications for schedule notifications with backward compatibility on older versions of Android. 

Solution:

We can easily solve Android 12 | No interface method addWindowLayoutInfoListener following steps.

The first step is to go into android/build.gradle file and add the below piece of code

compileOptions {
        coreLibraryDesugaringEnabled true
       }

 

The second step is to enable multiDexEnabled true.

defaultConfig {
        multiDexEnabled true
       }

 

The third step is to add the dependency desugar_jdk_libs like below.

 coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'

 

Conclusion : 

Now finally solved "Android 12l with "No interface method addWindowLayoutInfoListener" error, I hope this article may help you.

Tags: