Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coreLibraryDesugaringEnabled option in android/app/build.gradle causes immediate flutter crash (java.lang.NoSuchMethod) on Android 12L/13 #110658

Open
dickverweij opened this issue Aug 31, 2022 · 18 comments
Labels
c: crash Stack traces logged to the console c: fatal crash Crashes that terminate the process dependency: android Android team may need to help us e: OS-version specific Affects only some versions of the relevant operating system engine flutter/engine repository. See also e: labels. P2 Important issues not at the top of the work list platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team

Comments

@dickverweij
Copy link

dickverweij commented Aug 31, 2022

Steps to Reproduce

this already reported in issues 110000 and 104279 but was not reproducable, now I have a reproducable crash with the plain vanilla counter app.

  1. flutter create z4tester
  2. adjust android/app/build.gradle
  3. enable option
    compileOptions {
        coreLibraryDesugaringEnabled true

        sourceCompatibility JavaVersion.VERSION_1_8

        targetCompatibility JavaVersion.VERSION_1_8
    }

add dependency

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

set min sdk to 21
minSdkVersion 21
5. hook up 12L phone (Galaxy Z4 Fold)
6. Flutter run

Expected results:
normal counter app

Actual results:
app crashed at startup

Code sample
flutter create z4tester (no change to code whatsoever)
Logs
[   +1 ms] Forwarded host port 58322 to device port 34629 for Observatory
[   +5 ms] Caching compiled dill
[  +44 ms] Connecting to service protocol: http://127.0.0.1:58322/ieBP2dHgJdI=/
[  +15 ms] E/AndroidRuntime(26454): FATAL EXCEPTION: main
[        ] E/AndroidRuntime(26454): Process: com.example.z4tester, PID: 26454
[   +2 ms] E/AndroidRuntime(26454): 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)       
[   +1 ms] E/AndroidRuntime(26454):     at androidx.window.layout.ExtensionWindowLayoutInfoBackend.registerLayoutChangeCallback(ExtensionWindowLayoutInfoBackend.kt:68)
[        ] E/AndroidRuntime(26454):     at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invokeSuspend(WindowInfoTrackerImpl.kt:52)
[        ] E/AndroidRuntime(26454):     at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invoke(Unknown Source:8)
[        ] E/AndroidRuntime(26454):     at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invoke(Unknown Source:4)
[        ] E/AndroidRuntime(26454):     at kotlinx.coroutines.flow.SafeFlow.collectSafely(Builders.kt:61)
[        ] E/AndroidRuntime(26454):     at kotlinx.coroutines.flow.AbstractFlow.collect(Flow.kt:212)
[        ] E/AndroidRuntime(26454):     at androidx.window.java.layout.WindowInfoTrackerCallbackAdapter$addListener$1$1.invokeSuspend(WindowInfoTrackerCallbackAdapter.kt:96)
[        ] E/AndroidRuntime(26454):     at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
[        ] E/AndroidRuntime(26454):     at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
[        ] E/AndroidRuntime(26454):     at android.os.Handler.handleCallback(Handler.java:938)
[        ] E/AndroidRuntime(26454):     at android.os.Handler.dispatchMessage(Handler.java:99)
[        ] E/AndroidRuntime(26454):     at android.os.Looper.loopOnce(Looper.java:226)
[        ] E/AndroidRuntime(26454):     at android.os.Looper.loop(Looper.java:313)
           #7      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:229:5)
           <asynchronous suspension>
           #8      run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:62:9)
           <asynchronous suspension>
           #9      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #10     main (package:flutter_tools/executable.dart:94:3)
           <asynchronous suspension>
No issues found! (ran in 5.4s)
    • Flutter version 3.0.5 at C:\Development\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f1875d570e (7 weeks ago), 2022-07-13 11:24:16 -0700
    • Engine revision e85ea0e79c
    • Dart version 2.17.6
    • DevTools version 2.12.2

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0-rc5)
    • Android SDK at C:\Users\*****\AppData\Local\Android\sdk
    • Platform android-32, build-tools 31.0.0-rc5
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
    • All Android licenses accepted.

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

[√] Visual Studio - develop for Windows (Visual Studio Professional 2019 16.10.2)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional
    • Visual Studio Professional 2019 version 16.10.31410.357
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2021.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
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)

[√] VS Code, 64-bit edition (version 1.70.2)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.46.0

[√] Connected device (5 available)
    • SM F936B (mobile)                     • RFCT716Y5HD   • android-arm64  • Android 12 (API 32)
    • Android SDK built for x86 64 (mobile) • emulator-5554 • android-x64    • Android 6.0 (API 23) (emulator)
    • Windows (desktop)                     • windows       • windows-x64    • Microsoft Windows [Version 10.0.22000.856]
    • Chrome (web)                          • chrome        • web-javascript • Google Chrome 104.0.5112.102
    • Edge (web)                            • edge          • web-javascript • Microsoft Edge 104.0.1293.70

[√] HTTP Host Availability
    • All required HTTP hosts are available
@huycozy huycozy added the in triage Presently being triaged by the triage team label Aug 31, 2022
@huycozy
Copy link
Member

huycozy commented Aug 31, 2022

Hi @dickverweij, thanks for filing the issue.
This issue is reproducible on the latest stable and master channels.
Device info: Pixel C API 32 (guideline to get 12L virtual device: https://developer.android.com/about/versions/12/12L/get#set-up-avd)

The issue is only happening when adding coreLibraryDesugaringEnabled true. Without this flag, the app runs normally.

Demo
Screen.Recording.2022-08-31.at.22.04.16.mp4
Sample code

Default Flutter counter app:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        DefaultCupertinoLocalizations.delegate,
      ],
      supportedLocales: const [
        Locale('en'),
      ],
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: GestureDetector(
        onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              const Text(
                'You have pushed the button this many times: ',
              ),
              Text(
                '$_counter',
                style: Theme.of(context).textTheme.headlineMedium,
              ),
              TextFormField(
                keyboardType: TextInputType.number,
              ),
            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        child: const Icon(Icons.add),
      ),
    );
  }
}
Crash logs
09-01 04:57:04.132  9527  9527 E AndroidRuntime: FATAL EXCEPTION: main
09-01 04:57:04.132  9527  9527 E AndroidRuntime: Process: com.example.reproduce_issues, PID: 9527
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 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)
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 	at androidx.window.layout.ExtensionWindowLayoutInfoBackend.registerLayoutChangeCallback(ExtensionWindowLayoutInfoBackend.kt:68)
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 	at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invokeSuspend(WindowInfoTrackerImpl.kt:52)
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 	at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invoke(Unknown Source:8)
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 	at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invoke(Unknown Source:4)
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 	at kotlinx.coroutines.flow.SafeFlow.collectSafely(Builders.kt:61)
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 	at kotlinx.coroutines.flow.AbstractFlow.collect(Flow.kt:212)
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 	at androidx.window.java.layout.WindowInfoTrackerCallbackAdapter$addListener$1$1.invokeSuspend(WindowInfoTrackerCallbackAdapter.kt:96)
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:938)
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:99)
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 	at android.os.Looper.loopOnce(Looper.java:201)
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:288)
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:7842)
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
09-01 04:57:04.132  9527  9527 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
09-01 04:57:04.137   587   854 W ActivityTaskManager:   Force finishing activity com.example.reproduce_issues/.MainActivity
09-01 04:57:04.137   587  9566 I DropBoxManagerService: add tag=data_app_crash isTagEnabled=true flags=0x2
09-01 04:57:04.139   391   456 D goldfish-address-space: claimShared: Ask to claim region [0x3f5194000 0x3f5cd4000]
09-01 04:57:04.160   587  4275 D HostConnection: createUnique: call
flutter doctor -v
[✓] Flutter (Channel stable, 3.3.0, on macOS 12.5 21G72 darwin-x64, locale en-EE)
    • Flutter version 3.3.0 on channel stable at /Users/huynq/Documents/GitHub/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ffccd96b62 (28 hours ago), 2022-08-29 17:28:57 -0700
    • Engine revision 5e9e0e0aa8
    • Dart version 2.18.0
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 13E113
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] IntelliJ IDEA Community Edition (version 2020.3.3)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • 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

[✓] IntelliJ IDEA Community Edition (version 2022.1.1)
    • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
    • 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

[✓] VS Code (version 1.70.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.46.0

[✓] Connected device (3 available)
    • iPhone 13 (mobile) • 2526BC1A-435D-4B08-B99C-44B928F2517B • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-4 (simulator)
    • macOS (desktop)    • macos                                • darwin-x64     • macOS 12.5 21G72 darwin-x64
    • Chrome (web)       • chrome                               • web-javascript • Google Chrome 104.0.5112.101

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
[✓] Flutter (Channel master, 3.1.0-0.0.pre.2592, on macOS 12.5 21G72 darwin-x64, locale en-EE)
    • Flutter version 3.1.0-0.0.pre.2592 on channel master at /Users/huynq/Documents/GitHub/flutter_master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 069f504297 (3 hours ago), 2022-08-30 18:20:09 -0700
    • Engine revision 0ef08a8525
    • Dart version 2.19.0 (build 2.19.0-152.0.dev)
    • DevTools version 2.16.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 13E113
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] IntelliJ IDEA Community Edition (version 2020.3.3)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • 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

[✓] IntelliJ IDEA Community Edition (version 2022.1.1)
    • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
    • 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

[✓] VS Code (version 1.70.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.46.0

[✓] Connected device (3 available)
    • iPhone 13 (mobile) • 2526BC1A-435D-4B08-B99C-44B928F2517B • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-4 (simulator)
    • macOS (desktop)    • macos                                • darwin-x64     • macOS 12.5 21G72 darwin-x64
    • Chrome (web)       • chrome                               • web-javascript • Google Chrome 104.0.5112.101

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

@huycozy huycozy added c: crash Stack traces logged to the console dependency: android Android team may need to help us e: OS-version specific Affects only some versions of the relevant operating system c: fatal crash Crashes that terminate the process platform-android Android applications specifically and removed in triage Presently being triaged by the triage team labels Aug 31, 2022
@Robin-Sociosoftware
Copy link

Our team has been experiencing exactly this issue for a few weeks now. We've had reports from production users who are using Fold devices who can't open our apps. Samsung has also reached out to us in an effort to resolve this as they probably want a stable environment for their new devices.

Our Flutter apps crash on API 32+ running on fold devices (12L) where we use the desugaring library. Our apps use features from desugaring in its core functionality (java.time), so we can't simply disable it.

Interestingly, we've found that if we run the Android project directly instead of through Flutter, the crash does not occur. So if you right-click your project > Flutter > Open Android, and you just run it as a normal Android app, there's no crash. Anything where you run it through Flutter (flutter run, flutter build appbundle, etc) will still crash.

We updated the native Android project's Gradle version and Gradle Plugin version. I'm unsure if Flutter uses a different Gradle version when executing the build.

gradle-wrapper.properties
#Thu Sep 01 10:21:48 ULAT 2022 distributionBase=GRADLE_USER_HOME distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME

In android/build.gradle:
classpath 'com.android.tools.build:gradle:7.2.2'

Crash logs 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) at androidx.window.layout.ExtensionWindowLayoutInfoBackend.registerLayoutChangeCallback(ExtensionWindowLayoutInfoBackend.kt:68) at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invokeSuspend(WindowInfoTrackerImpl.kt:52) at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invoke(Unknown Source:8) at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invoke(Unknown Source:4) at kotlinx.coroutines.flow.SafeFlow.collectSafely(Builders.kt:61) at kotlinx.coroutines.flow.AbstractFlow.collect(Flow.kt:212) at androidx.window.java.layout.WindowInfoTrackerCallbackAdapter$addListener$1$1.invokeSuspend(WindowInfoTrackerCallbackAdapter.kt:96) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7842) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
flutter doctor -v [√] Flutter (Channel stable, 3.3.0, on Microsoft Windows [Version 10.0.19044.1889], locale en-US) • Flutter version 3.3.0 on channel stable at C:\Development\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision ffccd96 (2 days ago), 2022-08-29 17:28:57 -0700 • Engine revision 5e9e0e0aa8 • Dart version 2.18.0 • DevTools version 2.15.0

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at C:\Users\Robin\AppData\Local\Android\sdk
• Platform android-33, build-tools 33.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
• All Android licenses accepted.

@arlakay
Copy link

arlakay commented Sep 2, 2022

try adding this into your build.gradle.

implementation "androidx.window:window:1.0.0-rc01"
implementation "androidx.window:window-java:1.0.0-rc01"

@Robin-Sociosoftware
Copy link

Thank you @arlakay. This worked for us and resolves the crash issue.

@dickverweij
Copy link
Author

Thanks @arlakay!. What was causing the issue btw?

@GaryQian GaryQian added the P2 Important issues not at the top of the work list label Sep 6, 2022
@vlasentiy
Copy link

vlasentiy commented Sep 13, 2022

Try to add these lines of code to your's build.gradle:

dependencies {
    implementation "androidx.window:window:1.0.0"

    // For Java-friendly APIs to register and unregister callbacks
    implementation "androidx.window:window-java:1.0.0"

    // For RxJava2 integration
    implementation "androidx.window:window-rxjava2:1.0.0"

    // For RxJava3 integration
    implementation "androidx.window:window-rxjava3:1.0.0"

    // For testing
    implementation "androidx.window:window-testing:1.0.0"
}

https://developer.android.com/jetpack/androidx/releases/window

and optionally:

implementation "androidx.window:window-extensions:1.0.0-alpha01"

https://androidx.tech/artifacts/window/window-extensions/

@arlakay
Copy link

arlakay commented Sep 13, 2022

Thanks @arlakay!. What was causing the issue btw?

It's about make your app fold aware.

@noinskit
Copy link

I believe that this bug affects also non-foldable devices. I had a similar crash on Samsung s22 ultra (not foldable without considerable force) and explicitly adding these androidx.window* dependencies "fixed" it (worked it around).

@EArminjon
Copy link
Contributor

EArminjon commented Oct 18, 2022

The following line fixed my crash on my Android emulator API 33.

implementation "androidx.window:window:1.0.0"

@AlexV525
Copy link
Member

AlexV525 commented Nov 19, 2022

https://stackoverflow.com/a/74410353/17742614 describes the root cause of the issue.

Adding androidx.window:window and androidx.window:window-java to android/app/build.gradle will solve the issue temporarily.

dependencies {
    implementation 'androidx.window:window:1.0.0'
    implementation 'androidx.window:window-java:1.0.0'
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2'
}

@gnprice
Copy link
Member

gnprice commented May 17, 2023

It sounds like the fix is that Flutter should update the version of androidx.window that it pulls in as a dependency, because this issue was fixed there and we just need to take that update.

It looks like we're currently pulling in 1.0.0-beta04, after it was updated from 1.0.0-beta03 in flutter/engine#29897 . So that should be bumped to at least 1.0.0, and perhaps even to 1.1.0-rc01, the latest.

I'm actually still a bit puzzled at how a version bump to 1.0.0 fixes the issue — I'd have expected it to require bumping to at least 1.1.0-alpha01, because that's the first release that has the commit that looks to be the fix. But based on several reports above, it seems like a version bump to 1.0.0 does fix it.


Details on the apparent upstream fix and where it was released:

I don't entirely understand what's going on in the issue as diagnosed in that StackOverflow answer, but it looks like probably an accurate diagnosis. In particular, here's the stack trace @huycozy found above:

E AndroidRuntime: 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: 	at androidx.window.layout.ExtensionWindowLayoutInfoBackend.registerLayoutChangeCallback(ExtensionWindowLayoutInfoBackend.kt:68)
[…]

and that answer points to an upstream AndroidX commit d9a44f767 that fixed a bug in androidx.window which matches that stack trace.

From the androidx.window release notes, that commit was included in release 1.1.0-alpha01:
https://developer.android.com/jetpack/androidx/releases/window#1.1.0-alpha01
(linking to this list of commits, which includes the fix in question.)

The thing that leaves me still puzzled, though, is that the workaround reported above is to force the androidx.window:window dependency to version 1.0.0 — older than that fix. I don't know what to make of that.

@gnprice gnprice added the engine flutter/engine repository. See also e: labels. label May 17, 2023
dreautall added a commit to dreautall/waterfly-iii that referenced this issue May 29, 2023
@flutter-triage-bot flutter-triage-bot bot added multiteam-retriage-candidate team-android Owned by Android platform team triaged-android Triaged by Android platform team labels Jul 8, 2023
@ShivamPundir12

This comment was marked as off-topic.

@SirBarksALot
Copy link

Shouldn't this be closed as it's been merged into flutter?

@udoy-touhid
Copy link

Try to add these lines of code to your's build.gradle:

dependencies {
    implementation "androidx.window:window:1.0.0"

    // For Java-friendly APIs to register and unregister callbacks
    implementation "androidx.window:window-java:1.0.0"

    // For RxJava2 integration
    implementation "androidx.window:window-rxjava2:1.0.0"

    // For RxJava3 integration
    implementation "androidx.window:window-rxjava3:1.0.0"

    // For testing
    implementation "androidx.window:window-testing:1.0.0"
}

https://developer.android.com/jetpack/androidx/releases/window

and optionally:

implementation "androidx.window:window-extensions:1.0.0-alpha01"

https://androidx.tech/artifacts/window/window-extensions/

After following this, I still got the crash many times and lost many hours.
It turned out that I mistakenly updated the desugar version to 1.2.2 to 1.2.3

So, this doesn't work
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.3'
But this works!
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2'

@johanlantz
Copy link

@huycozy This just happened to me when submitting to Google Play. I have recently added desugaring due to a requirement from flutter_local_notifications but since I thought this was fixed in Flutter, I had not added the extra dependencies in my gradle file.

So, at least for me, this issue persists in Flutter 3.16.1 and happened on a Pixel 2 on Google Play. Now I will try to add the gradle dependences as suggested above but if this is expected to not happen on recent flutter versions, then there might still be something wrong.

Flutter 3.16.1
com.android.tools.build:gradle:7.4.2
Kotlin 1.8
com.android.tools:desugar_jdk_libs:1.2.2
compileSdkVersion: 33
targetSdkVersion: 33
minSdkVersion: 21

Stack trace at l9.z0.run(Unknown Source:88)
Exception 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)
  at androidx.window.layout.ExtensionWindowLayoutInfoBackend.registerLayoutChangeCallback
  at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invokeSuspend (WindowInfoTrackerImpl.java)
  at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invoke (WindowInfoTrackerImpl.java)
  at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invoke (WindowInfoTrackerImpl.java)
  at kotlinx.coroutines.flow.SafeFlow.collectSafely (SafeFlow.java)
  at kotlinx.coroutines.flow.AbstractFlow.collect (AbstractFlow.java)
  at androidx.window.java.layout.WindowInfoTrackerCallbackAdapter$addListener$1$1.invokeSuspend
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (BaseContinuationImpl.java)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.java)
  at android.os.Handler.handleCallback (Handler.java:942)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:201)
  at android.os.Looper.loop (Looper.java:288)
  at android.app.ActivityThread.main (ActivityThread.java:7872)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:548)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:936)

@ajaygautam

This comment was marked as off-topic.

@gnprice
Copy link
Member

gnprice commented Feb 19, 2024

Shouldn't this be closed as it's been merged into flutter?

No, there's been no change merged into Flutter to fix this. The androidx.window version that Flutter pulls in is still 1.0.0-beta04, the same as it was before (#110658 (comment)):
https://github.com/flutter/engine/blob/e96c18b6c5ee022867c73a30fd445b8fbfb2365e/tools/androidx/files.json#L70-L72

@bhumkong
Copy link

Seems strange that it hasn't been fixed yet...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: crash Stack traces logged to the console c: fatal crash Crashes that terminate the process dependency: android Android team may need to help us e: OS-version specific Affects only some versions of the relevant operating system engine flutter/engine repository. See also e: labels. P2 Important issues not at the top of the work list platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team
Projects
None yet
Development

No branches or pull requests