Skip to content

path_provider package breaks in release mode, if app also depends on device_info_plus, after b2de4df #154580

Description

@rajveermalviya

Steps to reproduce

  1. Clone https://github.com/rajveermalviya/broken_demo
  2. Checkout Flutter SDK to 1cdff36
  3. Run the app, and verify tapping on the button prints the path in console (Working correctly).
  4. Checkout Flutter SDK to b2de4df
  5. Run the app, and verify tapping on the button results in the following error:
W/FlutterEngineCxnRegstry(14828): Attempted to register plugin (a0.a@29f2957) but it was already registered with this FlutterEngine (d0.c@ca74c44).
E/flutter (14828): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
E/flutter (14828): #0      PathProviderApi.getApplicationSupportPath (package:path_provider_android/messages.g.dart:65)
E/flutter (14828): <asynchronous suspension>
E/flutter (14828): #1      getApplicationSupportDirectory (package:path_provider/path_provider.dart:78)
E/flutter (14828): <asynchronous suspension>
E/flutter (14828): #2      _BorkenDemoHomePageState.build.<anonymous closure> (package:broken_demo/main.dart:44)
E/flutter (14828): <asynchronous suspension>
E/flutter (14828): 

Expected results

There should be no errors, it should print the path.

Actual results

Throws a PlatformException(channel-error, Unable to establish connection on channel., null, null)

Code sample

https://github.com/rajveermalviya/broken_demo

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

No response

Flutter Doctor output

Doctor output
[!] Flutter (Channel [user-branch], 3.25.0-1.0.pre.110, on macOS 14.6.1 23G93 darwin-arm64, locale en-IN)
    ! Flutter version 3.25.0-1.0.pre.110 on channel [user-branch] at /Users/rajveer/sdk/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/setup.
    ! Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
    • Framework revision b2de4dfc2b (11 days ago), 2024-08-23 09:44:08 -0700
    • Engine revision 41f539f086
    • Dart version 3.6.0 (build 3.6.0-172.0.dev)
    • DevTools version 2.39.0-dev.15
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /Users/rajveer/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • ANDROID_HOME = /Users/rajveer/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

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

[✓] Android Studio (version 2024.1)
    • 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 17.0.11+0-17.0.11b1207.24-11852314)

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

[✓] Connected device (4 available)
    • sdk gphone64 arm64 (mobile)     • emulator-5554         • android-arm64  • Android 14 (API 34) (emulator)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 14.6.1 23G93 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 14.6.1 23G93 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 128.0.6613.114

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

! Doctor found issues in 1 category.

Activity

  1. rajveermalviya commented on Sep 3, 2024

    @rajveermalviya
    ContributorAuthor

    Logs

    (Created a gist because Github wouldn't let me post them here because of the character limit.)
    https://gist.github.com/rajveermalviya/718ef0b7f09c5afe897762f21cd93295

  2. rajveermalviya commented on Sep 3, 2024

    @rajveermalviya
    ContributorAuthor

    Also if the app is built with flutter run --release -Pshrink=false there are no exceptions observed, the sample app successfully prints the path.

    cc @gmackall

  3. added
    in triagePresently being triaged by the triage team
    on Sep 4, 2024
  4. huycozy commented on Sep 4, 2024

    @huycozy
    Member

    Thank you for filing a detailed issue, @rajveermalviya

    I see the expected output path on Flutter 3.24.1 whilst the reported error occurs on Flutter master 3.25.0-1.0.pre.248. Also, the issue will not occur without using device_info_plus plugin.

    The current path_provider package versions: path_provider: ^2.1.4 and path_provider_android: ^2.2.10

  5. added
    c: regressionIt was better in the past than it is now
    platform-androidAndroid applications specifically
    toolAffects the "flutter" command-line tool. See also t: labels.
    p: path_providerPlugin that provides resolved paths to some platform directories
    packageflutter/packages repository. See also p: labels.
    a: buildBuilding flutter applications with the tool
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-androidOwned by Android platform team
    fyi-ecosystemFor the attention of Ecosystem team
    and removed
    in triagePresently being triaged by the triage team
    on Sep 4, 2024
  6. 8 remaining items

  7. gmackall commented on Sep 5, 2024

    @gmackall
    Member

    Should be fixed now - thanks for the original report and clean repro @rajveermalviya!

    Let me know if you run in to any new r8 related issues in the wake of #153868

  8. added
    r: fixedIssue is closed as already fixed in a newer version
    on Sep 6, 2024
  9. rajveermalviya commented on Sep 6, 2024

    @rajveermalviya
    ContributorAuthor

    @gmackall Thanks for the prompt response and the PR towards fixing it!

    Unfortunately though that PR doesn't fix the issue for me, running broken_demo with release still generates following warning and error:

    W/FlutterEngineCxnRegstry( 4887): Attempted to register plugin (a0.a@53b33b6) but it was already registered with this FlutterEngine (d0.c@8baa8b7).
    E/flutter ( 4887): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
    E/flutter ( 4887): #0      PathProviderApi.getApplicationSupportPath (package:path_provider_android/messages.g.dart:65)
    E/flutter ( 4887): <asynchronous suspension>
    E/flutter ( 4887): #1      getApplicationSupportDirectory (package:path_provider/path_provider.dart:78)
    E/flutter ( 4887): <asynchronous suspension>
    E/flutter ( 4887): #2      _BorkenDemoHomePageState.build.<anonymous closure> (package:broken_demo/main.dart:44)
    E/flutter ( 4887): <asynchronous suspension>
    E/flutter ( 4887): 

    It seems like the combination of allowoptimization and allowshrinking here is generating this issue, enabling only allowoptimization or only allowshrinking fixes it, but not with both. I changed that to only enable one of the modifier and that seems to fix the issue in both broken_demo (repro sample) and zulip-flutter:

    diff --git a/packages/flutter_tools/gradle/flutter_proguard_rules.pro b/packages/flutter_tools/gradle/flutter_proguard_rules.pro
    index 0a01632662..feb6a3e109 100644
    --- a/packages/flutter_tools/gradle/flutter_proguard_rules.pro
    +++ b/packages/flutter_tools/gradle/flutter_proguard_rules.pro
    @@ -11,4 +11,4 @@
     # why this is the case.
     # See https://github.com/flutter/flutter/issues/154580.
     -if class * implements io.flutter.embedding.engine.plugins.FlutterPlugin
    --keep,allowoptimization,allowshrinking,allowobfuscation class <1>
    +-keep,allowshrinking,allowobfuscation class <1>

    I chose allowshrinking here because that generated the smaller apk for the broken_demo sample compared to allowoptimization. Also just to note, I had to explicitly force snapshot regeneration to test my local changes.

  10. rajveermalviya commented on Sep 6, 2024

    @rajveermalviya
    ContributorAuthor

    Sent PR #154715 making the change mentioned above.

  11. AbdeMohlbi commented on Sep 6, 2024

    @AbdeMohlbi
    Member

    i can confirm that #154677 could not resolve the issue , but i got a new error instead :

    W/FlutterEngineCxnRegstry( 5882): Attempted to register plugin (J.a@3981a52) but it was already registered with this FlutterEngine (Y0.b@d346123).
    W/FlutterEngineCxnRegstry( 5882): Attempted to register plugin (N0.e@3e1ec7f) but it was already registered with this FlutterEngine (Y0.b@d346123).
    W/FlutterEngineCxnRegstry( 5882): Attempted to register plugin (J.a@67a944c) but it was already registered with this FlutterEngine (Y0.b@d346123).
    W/FlutterEngineCxnRegstry( 5882): Attempted to register plugin (N0.e@5e2a938) but it was already registered with this FlutterEngine (Y0.b@d346123).
    W/FlutterEngineCxnRegstry( 5882): Attempted to register plugin (J.a@e156750) but it was already registered with this FlutterEngine (Y0.b@d346123).
    W/FlutterEngineCxnRegstry( 5882): Attempted to register plugin (V0.a@c778d49) but it was already registered with this FlutterEngine (Y0.b@d346123).
    E/flutter ( 5882): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.getAll"., null, null)
    

    and from what i see it's shared_preferences and i've seen some issues lately having simular error messages
    so the issue is not specific to path_provider it also occurs in shared_preferences and possibly other packages

  12. AbdeMohlbi commented on Sep 6, 2024

    @AbdeMohlbi
    Member

    can someone reopen this issue ?

  13. added a commit that references this issue on Sep 6, 2024
    6ad6641
  14. gmackall commented on Sep 6, 2024

    @gmackall
    Member

    can someone reopen this issue ?

    I've just merged @rajveermalviya's pr (#154715) which should (combined with my pr) fix the issue for real this time. Please let me know if you still encounter this (or a similar) issue on the latest master

  15. AbdeMohlbi commented on Sep 6, 2024

    @AbdeMohlbi
    Member

    can someone reopen this issue ?

    I've just merged @rajveermalviya's pr (#154715) which should (combined with my pr) fix the issue for real this time. Please let me know if you still encounter this (or a similar) issue on the latest master

    thnks man i'll let u know once our roll is out

  16. AbdeMohlbi commented on Sep 7, 2024

    @AbdeMohlbi
    Member

    hi @gmackall i can confirm that this pr fix this problem .
    now we got new impeller issues 😑 on Flutter 3.25.0-1.0.pre.299 •
    any way thanks for u and @rajveermalviya efforts

  17. github-actions commented on Sep 21, 2024

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  18. locked as resolved and limited conversation to collaborators on Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work lista: buildBuilding flutter applications with the toolc: regressionIt was better in the past than it is nowfound in release: 3.25Found to occur in 3.25fyi-ecosystemFor the attention of Ecosystem teamhas reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: path_providerPlugin that provides resolved paths to some platform directoriespackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-androidOwned by Android platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-androidTriaged by Android platform team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions