Flutterfire: [cloud_firestore] Flutter crash in android release version only with firestore

Created on 12 Nov 2019  Β·  20Comments  Β·  Source: FirebaseExtended/flutterfire

Describe the bug
This only seems to reproduce on a physical android device, with a release build. Seems like it crashes on first call to firestore. I do not have a small repro because I don't have a physical device for quick iteration. Stack traces from Google Play. I'm currently on flutter channel master, but I have tried from beta + dev channels as well.

Target Platform: Any android
Target OS version/browser: NA
Devices: Physical only, doesn't reproduce in emulator

To Reproduce
I don't have a local run, as I don't have a physical android device, which is making this hard to debug :(

Expected behavior
Not a crash :)

Additional context
Stack trace from google play:

java.lang.RuntimeException: 
  at com.google.firebase.firestore.util.AsyncQueue.a (AsyncQueue.java:379)
  at com.google.firebase.firestore.util.AsyncQueue$$Lambda$5.run (AsyncQueue.java:2)
  at android.os.Handler.handleCallback (Handler.java:883)
  at android.os.Handler.dispatchMessage (Handler.java:100)
  at android.os.Looper.loop (Looper.java:214)
  at android.app.ActivityThread.main (ActivityThread.java:7356)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:492)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:930)

Caused by: java.lang.AbstractMethodError: 
  at com.google.protobuf.GeneratedMessageLite.a (GeneratedMessageLite.java:1319)
  at com.google.firestore.v1.StructuredQuery.a (StructuredQuery.java:7346)
  at com.google.protobuf.GeneratedMessageLite.a (GeneratedMessageLite.java:1355)
  at com.google.protobuf.GeneratedMessageLite$DefaultInstanceBasedParser.d (GeneratedMessageLite.java:1340)
  at com.google.protobuf.GeneratedMessageLite$DefaultInstanceBasedParser.b (GeneratedMessageLite.java:1328)
  at com.google.protobuf.CodedInputStream.a (CodedInputStream.java:497)
  at com.google.firestore.v1.Target$QueryTarget.a (Target.java:1186)
  at com.google.protobuf.GeneratedMessageLite.a (GeneratedMessageLite.java:1355)
  at com.google.protobuf.GeneratedMessageLite$DefaultInstanceBasedParser.d (GeneratedMessageLite.java:1340)
  at com.google.protobuf.GeneratedMessageLite$DefaultInstanceBasedParser.b (GeneratedMessageLite.java:1328)
  at com.google.protobuf.CodedInputStream.a (CodedInputStream.java:497)
  at com.google.firebase.firestore.proto.Target.a (Target.java:1101)
  at com.google.protobuf.GeneratedMessageLite.a (GeneratedMessageLite.java:1355)
  at com.google.protobuf.GeneratedMessageLite.a (GeneratedMessageLite.java:1432)
  at com.google.protobuf.GeneratedMessageLite.a (GeneratedMessageLite.java:1449)
  at com.google.firebase.firestore.proto.Target.a (Target.java:538)
  at com.google.firebase.firestore.local.SQLiteQueryCache.a (SQLiteQueryCache.java:238)
  at com.google.firebase.firestore.local.SQLiteQueryCache.a (SQLiteQueryCache.java:221)
  at com.google.firebase.firestore.local.SQLiteQueryCache$$Lambda$4.accept (SQLiteQueryCache.java:8)
  at com.google.firebase.firestore.local.SQLitePersistence$Query.a (SQLitePersistence.java:431)
  at com.google.firebase.firestore.local.SQLiteQueryCache.a (SQLiteQueryCache.java:218)
  at com.google.firebase.firestore.local.LocalStore.a (LocalStore.java:513)
  at com.google.firebase.firestore.core.SyncEngine.a (SyncEngine.java:178)
  at com.google.firebase.firestore.core.EventManager.a (EventManager.java:91)
  at com.google.firebase.firestore.core.FirestoreClient.b (FirestoreClient.java:152)
  at com.google.firebase.firestore.core.FirestoreClient$$Lambda$6.run (FirestoreClient.java:4)
  at com.google.firebase.firestore.util.AsyncQueue.a (AsyncQueue.java:311)
  at com.google.firebase.firestore.util.AsyncQueue$$Lambda$4.call (AsyncQueue.java:2)
  at com.google.firebase.firestore.util.AsyncQueue.a (AsyncQueue.java:287)
  at com.google.firebase.firestore.util.AsyncQueue$$Lambda$3.run (AsyncQueue.java:4)
  at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:462)
  at java.util.concurrent.FutureTask.run (FutureTask.java:266)
  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run (ScheduledThreadPoolExecutor.java:301)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
  at com.google.firebase.firestore.util.AsyncQueue$DelayedStartFactory.run (AsyncQueue.java:205)
  at java.lang.Thread.run (Thread.java:919)

Flutter doctor:

[βœ“] Flutter (Channel master, v1.10.17-pre.49, on Mac OS X 10.14.6 18G1012, locale en-US)
    β€’ Flutter version 1.10.17-pre.49 at /Applications/flutter
    β€’ Framework revision e7073f9a1f (3 days ago), 2019-11-09 17:08:53 -0800
    β€’ Engine revision 31cd2dfca2
    β€’ Dart version 2.7.0


[βœ“] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
    β€’ Android SDK at /Users/braxton/Library/Android/sdk
    β€’ Android NDK location not configured (optional; useful for native profiling support)
    β€’ Platform android-29, build-tools 29.0.0
    β€’ Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    β€’ Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    β€’ All Android licenses accepted.

[βœ“] Xcode - develop for iOS and macOS (Xcode 11.1)
    β€’ Xcode at /Applications/Xcode.app/Contents/Developer
    β€’ Xcode 11.1, Build version 11A1027
    β€’ CocoaPods version 1.7.1

[βœ“] Android Studio (version 3.5)
    β€’ Android Studio at /Applications/Android Studio.app/Contents
    β€’ Flutter plugin version 41.0.2
    β€’ Dart plugin version 191.8593
    β€’ Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[βœ“] IntelliJ IDEA Community Edition (version 2019.1.4)
    β€’ IntelliJ at /Applications/IntelliJ IDEA CE.app
    β€’ Flutter plugin version 38.2.3
    β€’ Dart plugin version 191.8423

[βœ“] Connected device (1 available)
    β€’ iPhone 11 Pro Max β€’ 048D2EB0-7B10-4BA5-B908-4B581EF1696A β€’ ios β€’ com.apple.CoreSimulator.SimRuntime.iOS-13-1 (simulator)

β€’ No issues found!
crowd android cloud_firestore regression bug

Most helpful comment

any updates? it seems flutter releases are getting more and more unstable.

production apps, should not have minifyenabled false.

All 20 comments

Hi @braxtont
could you please post a minimal code sample to reproduce the problem
Thank you

Hi @iapicca - I'm having a really hard time giving a minimal code sample. The stack trace doesn't trace back to any of my code. But it seems like it's happening immediately after google sign in, on the first access to firestore, with this line:

FirebaseAuth _auth = FirebaseAuth.fromApp(app);

I'm also not the only one who is seeing this recently, I've found a few other reports around, including this stack overflow question:

https://stackoverflow.com/questions/58353313/flutter-app-crashes-when-it-use-firestore-plugin-in-release-mode

I will try to produce a standalone minimal app that hits this error in the next day or so. But it doesn't seem like it's really that specific to what I am doing.

I started fiddling with this a bit more, and this crash actually only occurs when building appbundle.

1) Build + Run on emulator. Works.
2) Build + Run on physical device using Android Studio. Works.
3) flutter run --release -> works
4)

flutter build appbundle
bundletool build-apks --bundle=build/app/outputs/bundle/release/app.aab --output=~/test.apks
bundletool install-apks --apks=~/test.apks

-> fails.

Fiddling more, got a different physical device. When running on this one in debug mode, attached via usb, I get:

D/SQLiteConnection(29370): config according to google default.
W/art     (29370): Before Android 4.1, method double java.util.concurrent.ThreadLocalRandom.internalNextDouble(double, double) would have incorrectly overridden the package-private method in java.util.Random
W/art     (29370): Before Android 4.1, method int java.util.concurrent.ThreadLocalRandom.internalNextInt(int, int) would have incorrectly overridden the package-private method in java.util.Random
W/art     (29370): Before Android 4.1, method long java.util.concurrent.ThreadLocalRandom.internalNextLong(long, long) would have incorrectly overridden the package-private method in java.util.Random
E/ConnectivityManager(29370): java.lang.Throwable
E/ConnectivityManager(29370):   at android.net.ConnectivityManager.sendRequestForNetwork(ConnectivityManager.java:2908)
E/ConnectivityManager(29370):   at android.net.ConnectivityManager.registerDefaultNetworkCallback(ConnectivityManager.java:3215)
E/ConnectivityManager(29370):   at io.grpc.android.AndroidChannelBuilder$AndroidChannel.configureNetworkMonitoring(AndroidChannelBuilder.java:224)
E/ConnectivityManager(29370):   at io.grpc.android.AndroidChannelBuilder$AndroidChannel.<init>(AndroidChannelBuilder.java:205)
E/ConnectivityManager(29370):   at io.grpc.android.AndroidChannelBuilder.build(AndroidChannelBuilder.java:176)
E/ConnectivityManager(29370):   at com.google.firebase.firestore.remote.Datastore.<init>(com.google.firebase:firebase-firestore@@19.0.0:131)
E/ConnectivityManager(29370):   at com.google.firebase.firestore.core.FirestoreClient.initialize(com.google.firebase:firebase-firestore@@19.0.0:245)
E/ConnectivityManager(29370):   at com.google.firebase.firestore.core.FirestoreClient.lambda$new$2(com.google.firebase:firebase-firestore@@19.0.0:116)
E/ConnectivityManager(29370):   at com.google.firebase.firestore.core.FirestoreClient$$Lambda$2.run(com.google.firebase:firebase-firestore@@19.0.0)
E/ConnectivityManager(29370):   at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$4(com.google.firebase:firebase-firestore@@19.0.0:311)
E/ConnectivityManager(29370):   at com.google.firebase.firestore.util.AsyncQueue$$Lambda$4.call(com.google.firebase:firebase-firestore@@19.0.0)
E/ConnectivityManager(29370):   at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$3(com.google.firebase:firebase-firestore@@19.0.0:287)
E/ConnectivityManager(29370):   at com.google.firebase.firestore.util.AsyncQueue$$Lambda$3.run(com.google.firebase:firebase-firestore@@19.0.0)
E/ConnectivityManager(29370):   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
E/ConnectivityManager(29370):   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
E/ConnectivityManager(29370):   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
E/ConnectivityManager(29370):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
E/ConnectivityManager(29370):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
E/ConnectivityManager(29370):   at com.google.firebase.firestore.util.AsyncQueue$DelayedStartFactory.run(com.google.firebase:firebase-firestore@@19.0.0:205)
E/ConnectivityManager(29370):   at java.lang.Thread.run(Thread.java:761)
E/ConnectivityManager(29370): DEBUG1

I don't know if that is relevant to the original problem. But, the app seems to still work in this configuration.

@iapicca - after some very painful binary search test&check, I can get the error with the first call to .getDocuments:

    CollectionReference cr = StateModel.firestore.collection('config');
    QuerySnapshot qs = await cr.getDocuments(); // If this line is commented out, no crash

but

    CollectionReference cr = StateModel.firestore.collection('config');
    DocumentSnapshot ds = cr.document(''); // no crash

I don't think it's a database permissions issue either, as permissions have not changed, and, again, works on iOS.

I found that flutter version v1.9.1+hotfix.4 works, while anything later than that, I get this problem.

Hi @braxtont
thank you for the update

Happy new year everyone πŸŽ† 🍾 πŸ˜„
I think I'm been affected by this issue and I added more information here

I was wondering if you guys have some progress on this issue?

Thanks

I expended some hours to change my code to flutter version v1.9.1+hotfix.4 and still getting the same error when building for release.

flutter doctor -v                                                                                                           22:59:56
[βœ“] Flutter (Channel unknown, v1.9.1+hotfix.4, on Mac OS X 10.15.2 19C57, locale en-ES)
    β€’ Flutter version 1.9.1+hotfix.4 at <dir>
    β€’ Framework revision cc949a8e8b (3 months ago), 2019-09-27 15:04:59 -0700
    β€’ Engine revision b863200c37
    β€’ Dart version 2.5.0


[βœ“] Android toolchain - develop for Android devices (Android SDK version 29.0.0-rc1)
    β€’ Android SDK at /Users/josef/Library/Android/sdk
    β€’ Android NDK location not configured (optional; useful for native profiling support)
    β€’ Platform android-29, build-tools 29.0.0-rc1
    β€’ Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    β€’ Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    β€’ All Android licenses accepted.

[βœ“] Xcode - develop for iOS and macOS (Xcode 11.3)
    β€’ Xcode at /Applications/Xcode.app/Contents/Developer
    β€’ Xcode 11.3, Build version 11C29
    β€’ CocoaPods version 1.8.4

[βœ“] Android Studio (version 3.5)
    β€’ Android Studio at /Applications/Android Studio.app/Contents
    β€’ Flutter plugin version 41.1.2
    β€’ Dart plugin version 191.8593
    β€’ Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[!] Android Studio
    β€’ Android Studio at /Applications/Android Studio 4.0 Preview.app/Contents
    βœ— Flutter plugin not installed; this adds Flutter specific functionality.
    βœ— Dart plugin not installed; this adds Dart specific functionality.
    β€’ Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[βœ“] IntelliJ IDEA Ultimate Edition (version 2019.3.1)
    β€’ IntelliJ at /Applications/IntelliJ IDEA.app
    β€’ Flutter plugin version 42.1.4
    β€’ Dart plugin version 193.5731

[βœ“] VS Code (version 1.40.1)
    β€’ VS Code at /Applications/Visual Studio Code.app/Contents
    β€’ Flutter extension version 3.6.0

[βœ“] Connected device (1 available)
    β€’ Pixel 3 XL β€’ <numbers> β€’ android-arm64 β€’ Android 10 (API 29)

! Doctor found issues in 1 category.
pubspec.yaml

environment:
  sdk: ">=2.5.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  provider: ^3.1.0
  #  dart_countries_states: ^0.0.7
  dart_countries_states: #^0.0.8
      path: <dir>
  streets:
    path: <dir>
  jaguar_serializer: ^2.2.12
  firebase_core: ^0.4.0+9
  firebase_analytics: ^5.0.6
  firebase_auth: ^0.15.0
#  firebase_dynamic_links: ^0.5.0+9
  cloud_firestore: ^0.12.11
  firebase_storage: ^3.0.8
  cache_image: ^0.0.3
  enum_to_string: ^1.0.8
#  google_sign_in: ^4.1.1
  flutter_i18n: ^0.8.2
  flutter_typeahead: ^1.7.0
  #  flutter_flipperkit: ^0.0.20
  flutter_cache_manager: 1.1.3
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  image: ^2.1.4
  transparent_image: 1.0.0

dev_dependencies:
  flutter_launcher_icons: ^0.7.3
  build_runner: ^1.0.0
  jaguar_serializer_cli: ^2.2.8
  flutter_test:
    sdk: flutter

The issue is related to the minifyEnabled option. When setting minifyEnabled to false the crash disappeared using flutter version v1.9.1+hotfix.4 and 1.12.13+hotfix.5

android {
    compileSdkVersion 28

    ... 
    buildTypes {
        release {
            shrinkResources false
            minifyEnabled false
            signingConfig signingConfigs.release
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
flutter doctor -v                                                                                                                                                                                                   10:52:31
[βœ“] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.2 19C57, locale en-ES)
    β€’ Flutter version 1.12.13+hotfix.5 at <dir>
    β€’ Framework revision 27321ebbad (3 weeks ago), 2019-12-10 18:15:01 -0800
    β€’ Engine revision 2994f7e1e6
    β€’ Dart version 2.7.0


[βœ“] Android toolchain - develop for Android devices (Android SDK version 29.0.0-rc1)
    β€’ Android SDK at <dir>
    β€’ Android NDK location not configured (optional; useful for native profiling support)
    β€’ Platform android-29, build-tools 29.0.0-rc1
    β€’ Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    β€’ Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    β€’ All Android licenses accepted.

[βœ“] Xcode - develop for iOS and macOS (Xcode 11.3)
    β€’ Xcode at /Applications/Xcode.app/Contents/Developer
    β€’ Xcode 11.3, Build version 11C29
    β€’ CocoaPods version 1.8.4

[βœ“] Android Studio (version 3.5)
    β€’ Android Studio at /Applications/Android Studio.app/Contents
    β€’ Flutter plugin version 41.1.2
    β€’ Dart plugin version 191.8593
    β€’ Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[!] Android Studio
    β€’ Android Studio at /Applications/Android Studio 4.0 Preview.app/Contents
    βœ— Flutter plugin not installed; this adds Flutter specific functionality.
    βœ— Dart plugin not installed; this adds Dart specific functionality.
    β€’ Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[βœ“] IntelliJ IDEA Ultimate Edition (version 2019.3.1)
    β€’ IntelliJ at /Applications/IntelliJ IDEA.app
    β€’ Flutter plugin version 42.1.4
    β€’ Dart plugin version 193.5731

[βœ“] VS Code (version 1.40.1)
    β€’ VS Code at /Applications/Visual Studio Code.app/Contents
    β€’ Flutter extension version 3.6.0

[βœ“] Connected device (1 available)
    β€’ Android SDK built for x86 64 β€’ emulator-5554 β€’ android-x64 β€’ Android 9 (API 28) (emulator)

! Doctor found issues in 1 category.

I can confirm as @jffiorillo says, adding minifyEnabled and shrinkResources to the release buildtype and set it them to false make the crash disappear, however my app which is a very basic one got +4MB, no issue at all, but it feels like a cheap trick to fix the issue, will be looking forward for the fix.

Doctor summary (to see all details, run flutter doctor -v):
[βœ“] Flutter (Channel stable, v1.12.13+hotfix.5, on Linux, locale en_US.UTF-8)

[βœ“] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[βœ“] Android Studio (version 3.5)
[βœ“] VS Code (version 1.41.0)
[βœ“] Connected device (1 available)

β€’ No issues found!

True. This solves the problem, but the increment in file size is just too much!

any updates? it seems flutter releases are getting more and more unstable.

production apps, should not have minifyenabled false.

Hi there, mates... facing same issue over here ...

Internar Server Error in Cloud Firestore .... caused by AbstractMethodError ....

Yesterday I made 2 main changes in my code that solved the problem (don't know with one made it happen)

  1. Bumped versiΓ³n of gms in build.gradle to: classpath 'com.google.gms:google-services:4.3.3' (latest)
  2. Setting minifyEnabled false & shrinkResources false (a shame)

I am in Channel stable, v1.12.13+hotfix.5

Thanks for all the info and hard work ....

any updates on this issue? Facing the same issue here (only in --release mode). And it works when I set minifyEnabled false

flutter version: Flutter 1.13.6-pre.25

Hi There,

Is there any update on this. I started facing the same issue recently.
Here's the output from Flutter Doctor:
[√] Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.18363.657], locale en-US)
β€’ Flutter version 1.12.13+hotfix.8
β€’ Framework revision 0b8abb4724 (4 weeks ago), 2020-02-11 11:44:36 -0800
β€’ Engine revision e1e6ced81d
β€’ Dart version 2.7.0

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
β€’ Android NDK location not configured (optional; useful for native profiling support)
β€’ Platform android-29, build-tools 29.0.2
β€’ Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
β€’ All Android licenses accepted.

[√] Android Studio (version 3.5)
β€’ Flutter plugin version 44.0.1
β€’ Dart plugin version 191.8593
β€’ Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] VS Code (version 1.40.2)
β€’ Flutter extension version 3.6.0

***********ITS VERY EASY TO SOLVE************

  1. FIRST RUN YOUR APP ON APP-RELEASE
    RUN COMMAND
    flutter run --release
    2.AND DONE YOU HAVE YOUR APP-REALESE APK FILE ON BUILD/../APK FOLDER.
    THANK YOU

Same issue.
Disable shrinking is not good solution.

i found this solution - keep classes like this :

-keep class com.google.** { *; }

in proguard-rules.pro

R8 is enabled

Hey, as part of our on-going work for #2582, this issue should have been resolved in our Firebase Firestore rework (#2913) - which has now been merged into master. We'll look at publishing some prereleases in the next few days. Thank you

Was this page helpful?
0 / 5 - 0 ratings