firebase / flutterfire

πŸ”₯ A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.7k stars 3.97k forks source link

πŸ› [firestore] Android fails to connect due to okio method exception #8501

Closed cyberpwnn closed 2 years ago

cyberpwnn commented 2 years ago

Bug report

Describe the bug

This started happening yesterday for me, updating firebase packages did not help.

W/Firestore( 5850): (24.1.1) [WatchStream]: (150415a) Stream closed with status: Status{code=INTERNAL, description=error in frame handler, cause=java.lang.NoSuchMethodError: No interface method getBuffer()Lokio/Buffer; in class Lokio/BufferedSource; or its super classes (declaration of 'okio.BufferedSource' appears in /data/app/~~562CMs3V8mJAW5W-e8eBRQ==/care.mpm.app.myguide-vSZFTwtxrkRSO-SPz3Pd5g==/base.apk!classes5.dex)
W/Firestore( 5850):     at io.grpc.okhttp.OkHttpClientTransport$ClientFrameHandler.data(OkHttpClientTransport.java:1144)
W/Firestore( 5850):     at io.grpc.okhttp.internal.framed.Http2$Reader.readData(Http2.java:234)
W/Firestore( 5850):     at io.grpc.okhttp.internal.framed.Http2$Reader.nextFrame(Http2.java:147)
W/Firestore( 5850):     at io.grpc.okhttp.OkHttpClientTransport$ClientFrameHandler.run(OkHttpClientTransport.java:1103)
W/Firestore( 5850):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/Firestore( 5850):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/Firestore( 5850):     at java.lang.Thread.run(Thread.java:923)

Then later after the above error happens enough times to trigger offline

W/Firestore( 2154): This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
E/flutter ( 2154): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: [cloud_firestore/unavailable] The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff.
E/flutter ( 2154): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter ( 2154): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:177:18)
E/flutter ( 2154): <asynchronous suspension>
E/flutter ( 2154): #2      MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:377:43)
E/flutter ( 2154): <asynchronous suspension>
E/flutter ( 2154): #3      MethodChannelDocumentReference.get (package:cloud_firestore_platform_interface/src/method_channel/method_channel_document_reference.dart:68:42)
E/flutter ( 2154): <asynchronous suspension>
E/flutter ( 2154): #4      _JsonDocumentReference.get (package:cloud_firestore/src/document_reference.dart:146:7)
E/flutter ( 2154): <asynchronous suspension>
E/flutter ( 2154): #5      UserService.bind (package:myguide/service/user_service.dart:39:16)
E/flutter ( 2154): <asynchronous suspension>

Steps to reproduce

Steps to reproduce the behavior:

  1. Run app
  2. See console

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` [βœ“] Flutter (Channel stable, 2.10.4, on macOS 12.3.1 21E258 darwin-arm, locale en-US) β€’ Flutter version 2.10.4 at /Users/danielmills/development/flutter β€’ Upstream repository https://github.com/flutter/flutter.git β€’ Framework revision c860cba910 (4 weeks ago), 2022-03-25 00:23:12 -0500 β€’ Engine revision 57d3bac3dd β€’ Dart version 2.16.2 β€’ DevTools version 2.9.2 [βœ“] Android toolchain - develop for Android devices (Android SDK version 32.0.0) β€’ Android SDK at /Users/danielmills/Library/Android/sdk β€’ Platform android-32, build-tools 32.0.0 β€’ Java binary at: /Users/danielmills/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/211.7628.21.2111.8309675/Android Studio.app/Contents/jre/Contents/Home/bin/java β€’ Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763) β€’ All Android licenses accepted. [βœ“] Xcode - develop for iOS and macOS (Xcode 13.3) β€’ Xcode at /Applications/Xcode.app/Contents/Developer β€’ CocoaPods version 1.11.3 [βœ“] Chrome - develop for the web β€’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [βœ“] Android Studio (version 2020.3) β€’ 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.10+0-b96-7249189) [βœ“] Android Studio (version 2021.1) β€’ Android Studio at /Users/danielmills/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/211.7628.21.2111.8309675/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.11+0-b60-7772763) [βœ“] Android Studio (version 2021.1) β€’ Android Studio at /Users/danielmills/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/211.7628.21.2111.8193401/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.11+0-b60-7772763) [βœ“] IntelliJ IDEA Ultimate Edition (version 2022.1) β€’ IntelliJ at /Users/danielmills/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app β€’ Flutter plugin version 66.0.4 β€’ Dart plugin version 221.5480 [βœ“] IntelliJ IDEA Ultimate Edition (version 2022.1) β€’ IntelliJ at /Users/danielmills/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/221.5080.210/IntelliJ IDEA 2022.1 EAP.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 Ultimate Edition (version 2021.3.3) β€’ IntelliJ at /Users/danielmills/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/213.7172.25/IntelliJ IDEA.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.66.2) β€’ VS Code at /Applications/Visual Studio Code.app/Contents β€’ Flutter extension version 3.38.1 [βœ“] Connected device (3 available) β€’ IN2017 (mobile) β€’ 2e01d742 β€’ android-arm64 β€’ Android 11 (API 30) β€’ Dan’s Phone (mobile) β€’ 00008101-001818940228001E β€’ ios β€’ iOS 15.4.1 19E258 β€’ Chrome (web) β€’ chrome β€’ web-javascript β€’ Google Chrome 100.0.4896.127 ! Error: Dan’s Phone is busy: Fetching debug symbols for Dan’s Phone. Xcode will continue when Dan’s Phone is finished. (code -10) [βœ“] HTTP Host Availability β€’ All required HTTP hosts are available β€’ No issues found! ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` firebase_core: ^1.15.0 firebase_storage: ^10.2.13 firebase_crashlytics: ^2.6.3 firebase_database: ^9.0.12 firebase_messaging: ^11.2.14 firebase_remote_config: ^2.0.5 firebase_performance: ^0.8.0+10 firebase_analytics: ^9.1.6 firebase_auth: ^3.3.15 cloud_functions: ^3.2.13 cloud_firestore: ^3.1.13 ```

cyberpwnn commented 2 years ago

There are a lot of issues with flutterfire im having but this one will prevent me from being able to continue development, It happened all of the sudden without any changes to the project over a span of a few days.

darshankawar commented 2 years ago

@cyberpwnn Looking at the error log you shared: For This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend., Please see this related discussion thread.

For [cloud_firestore/unavailable] The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff., see this discussion thread.

Regarding Stream closed with status: Status{code=INTERNAL, description=error in frame handler, cause=java.lang.NoSuchMethodError: No interface method getBuffer()Lokio/Buffer; in class Lokio/BufferedSource; or its super classes (declaration of 'okio.BufferedSource' appears in /data/app/~~562CMs3V8mJAW5W-e8eBRQ==/care.mpm.app.myguide-vSZFTwtxrkRSO-SPz3Pd5g==/base.apk!classes5.dex) W/Firestore( 5850): at io.grpc.okhttp.OkHttpClientTransport$ClientFrameHandler.data(OkHttpClientTransport.java:1144) these logs, it seems to be coming from okio libraray : https://square.github.io/okio/ and https://github.com/grpc/grpc-java/blob/master/okhttp/src/main/java/io/grpc/okhttp/OkHttpClientTransport.java

So I doubt if this is related to flutterfire's cloud_firestore plugin. I suggest you to reach out to firebase support on this and see what they about this.

cyberpwnn commented 2 years ago

Well given that IOS & Web continue to work as they have on the same network at the same time using the same project & given i can use the android device to download files load web pages etc, It's either a flutterfire package or firebase itself, however given the majority of android-native firebase projects havent posted this im assuming it has to do with the recent flutterfire update.

JustnHaroApps commented 2 years ago

Any help on this, very frustrating: W/Firestore( 7266): (24.1.1) [WatchStream]: (a29ad0c) Stream closed with status: Status{code=INTERNAL, description=error in frame handler, cause=java.lang.NoSuchMethodError: No interface method getBuffer()Lokio/Buffer; at io.grpc.okhttp.OkHttpClientTransport$ClientFrameHandler.data(OkHttpClientTransport.java:1144)

cyberpwnn commented 2 years ago

Yeah @darshankawar this is a sudden change after updating packages, its not a firebase thing, I don't know if it is specifically cloud_functions but it's one of the packages.

cyberpwnn commented 2 years ago

Older packages doesnt seem to fix it anymore, cleaning doesnt fix it. Can we please get an actual fix instead of questioning the internet connection or blaming it on another google project please?

harry-dickson commented 2 years ago

Glad I'm not the only one! A fix/explanation/workaround would be very welcome indeed.

cyberpwnn commented 2 years ago

This prevents me from using firebase, need this fixed, wasnt a problem 5 days ago

cyberpwnn commented 2 years ago

I reached out to firebase support, though i've done this before, there's usually no reply.

harry-dickson commented 2 years ago

See also this insight from from okio: https://github.com/square/okio/discussions/1114 Could be a version/packaging problem...

harry-dickson commented 2 years ago

Info

In android/app/build.gradle I have:

implementation platform('com.google.firebase:firebase-bom:29.3.1')

as per the documentation: https://firebase.google.com/docs/android/setup#add-sdks

As far as I can tell (not very far) from: https://mvnrepository.com/artifact/com.google.firebase/firebase-bom/29.3.1

the dependency chain goes like this:

com.google.firebase/firebase-bom: 29.3.1 => com.google.firebase/firebase-firestore: 24.1.1 => io.grpc/grpc-okhttp: 1.44.1 => com.squareup.okhttp/okhttp: 2.7.4 => com.squareup.okio/okio: 1.6.0

I did notice one dependency inequality (okhttp 2.7.4 <> 2.7.5): com.google.firebase/firebase-bom: 29.3.1 => com.squareup.okhttp/okhttp: 2.7.5 => com.squareup.okio/okio: 1.6.0

harry-dickson commented 2 years ago

No idea. I'm hoping the flutterfire devs - or someone much smarter than me - will be able to help us out...

cyberpwnn commented 2 years ago

I used to do a lot of java dev with gradle, there's a way to basically force all transitive okio deps to be a specific version, but its dirty and im not even sure what eversion its supposed to be using. That and the flutterfire plugins use platform dependencies outside of the build.gradle so whatever solution we come up with will be changing things that shouldnt be changed. If they could just fix the problem that would be great lol.

cyberpwnn commented 2 years ago

Ok i've figured out a temporary solution. But this is a problem with firebase or flutterfire. They really need to fix their dependencies. Basically we're just changing the dependency versions as they get resolved even if the dependencies are in a subproject (say a firebase plugin)

  1. Open your app/build.gradle (the inner one)
  2. Add this block above your dependencies block
    configurations.all {
    resolutionStrategy {
        force 'com.squareup.okhttp:okhttp:2.7.5'
        force 'com.squareup.okio:okio:1.17.5'
    }
    }

Note: Its not a good idea to lock dependencies like this but it should work for a while.

Firebase / Flutterfire devs: Please update your okio version to what GPRC uses (1.17.5)

darshankawar commented 2 years ago

Thanks for the update. Keeping it open and labeling it for further insights from the team.

/cc @russellwheatley

russellwheatley commented 2 years ago

This needs to be resolved upstream at the level of the firebase-android-sdk. We didn't make any changes to Firestore in the last release, except for a dependency change to the latest firebase_core package which contains an update to the latest android firebase BOM.

AbderraoufKhodja commented 2 years ago

I am facing the same problem since last few days.

anushkashelke commented 2 years ago

I was facing the same issue because I was using older versions of firebase packages. Try updating your dependencies it worked for me.

russellwheatley commented 2 years ago

We recently bumped android sdk to BOM version30.0.0 which might explain why this issue is resolved. @AbderraoufKhodja - can you confirm with the latest firebase_core version this problem has been resolved?

AbderraoufKhodja commented 2 years ago

@russellwheatley I have updated firebase_core package to it's latest version. Still facing the same issue. Disabling minifyEnabled and shrinkResources seems to temporarily solve the problem. It's worth noting that the issue started only after I added a video streaming SDK which increased the package size significantly. Before that, it was working fine with minifyEnabled and shrinkResources enabled.

wapoywapa commented 2 years ago

The fix suggested by cyberpwnn does work

chiekkored commented 2 years ago

The temporary fix from @cyberpwnn worked. But flutter devs needs to fix this asap

google-oss-bot commented 2 years ago

Hey @cyberpwnn. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

LiamConan commented 2 years ago

Still facing this issue.

mfagerdal commented 2 years ago

Facing this issue

google-oss-bot commented 2 years ago

Hey @cyberpwnn. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

rtrevivian commented 2 years ago

I was able to resolve this issue by removing another package (google_ml_vision: ^0.0.7) which was causing a dependency conflict and forcing firestore to use outdated networking code.

google-oss-bot commented 2 years ago

Hey @cyberpwnn. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 2 years ago

Since there haven't been any recent updates here, I am going to close this issue.

@cyberpwnn if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

Whaleman0423 commented 2 years ago

Ok i've figured out a temporary solution. But this is a problem with firebase or flutterfire. They really need to fix their dependencies. Basically we're just changing the dependency versions as they get resolved even if the dependencies are in a subproject (say a firebase plugin)

  1. Open your app/build.gradle (the inner one)
  2. Add this block above your dependencies block
configurations.all {
    resolutionStrategy {
        force 'com.squareup.okhttp:okhttp:2.7.5'
        force 'com.squareup.okio:okio:1.17.5'
    }
}

Note: Its not a good idea to lock dependencies like this but it should work for a while.

Firebase / Flutterfire devs: Please update your okio version to what GPRC uses (1.17.5)

it's realy help me, thanks for saving my 3 days debuging time.

MarceloRab commented 2 years ago

Please. Open error persists.