【问题标题】:Flutter app crashes when it use Firestore plugin in Release modeFlutter 应用在​​发布模式下使用 Firestore 插件时崩溃
【发布时间】:2020-02-09 16:38:24
【问题描述】:

在调试模式下一切正常。它首先发生在我将 Flutter 版本更新到 1.10.x 时,我不记得我正确使用了哪个版本。它应该是1.7.8,它是稳定的。为了修复它,我将颤振降级到 1.7.8+4 并降级与 firebase 相关的 pub 包。但错误仍然存​​在。

相关错误的堆栈跟踪,从 gogle 播放控制台捕获

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:790)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:7000)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:441)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1408)
Caused by: java.lang.AbstractMethodError: 
  at com.google.protobuf.GeneratedMessageLite.a (GeneratedMessageLite.java:1319)
  at com.google.firebase.firestore.proto.WriteBatch.s (WriteBatch.java:120)
  at com.google.firebase.firestore.proto.WriteBatch.a (WriteBatch.java:162)
  at com.google.firebase.firestore.proto.WriteBatch.a (WriteBatch.java:15)
  at com.google.firebase.firestore.proto.WriteBatch$Builder.a (WriteBatch.java:835)
  at com.google.firebase.firestore.local.LocalSerializer.a (LocalSerializer.java:172)
  at com.google.firebase.firestore.local.SQLiteMutationQueue.a (SQLiteMutationQueue.java:188)
  at com.google.firebase.firestore.local.LocalStore.a (LocalStore.java:237)
  at com.google.firebase.firestore.local.LocalStore$$Lambda$2.get (LocalStore.java:8)
  at com.google.firebase.firestore.local.SQLitePersistence.a (SQLitePersistence.java:195)
  at com.google.firebase.firestore.local.LocalStore.a (LocalStore.java:201)
  at com.google.firebase.firestore.core.SyncEngine.a (SyncEngine.java:227)
  at com.google.firebase.firestore.core.FirestoreClient.a (FirestoreClient.java:200)
  at com.google.firebase.firestore.core.FirestoreClient$$Lambda$11.run (FirestoreClient.java:6)
  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:457)
  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:1162)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
  at com.google.firebase.firestore.util.AsyncQueue$DelayedStartFactory.run (AsyncQueue.java:205)
  at java.lang.Thread.run (Thread.java:764)

当我在设备上看到错误跟踪时(在 android 崩溃报告对话框中)它提到了 Firebase 19.0.0

颤振医生:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel unknown, v1.7.8+hotfix.4, on Microsoft Windows [Version 10.0.17134.1069], locale en-US)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Enterprise 2017 15.9.7)
[√] Android Studio (version 3.4)
[√] VS Code, 64-bit edition (version 1.38.1)
[√] Connected device (3 available)

• No issues found!

为最终描述重新生成场景时出错:

  • 使用flutter run --release 构建应用程序
  • 应用尝试基本的 Firestore 调用

    Firestore.instance.collection('collection-name').document('docuemnt-id').get()

  • 应用程序崩溃。

使用flutter build appbudle 构建时也会出现相同的错误

【问题讨论】:

    标签: firebase flutter google-cloud-firestore crash


    【解决方案1】:

    这是我噩梦中的solution。

    编辑:

    错误

    FATAL EXCEPTION: main
    Process: com.app.android, PID: 12668
    java.lang.RuntimeException: Internal error in Firestore (19.0.0).
        at com.google.firebase.firestore.g.j.a(:379)
        at com.google.firebase.firestore.g.g.run(Unknown Source:2)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6718)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
    

    要修复此错误,请在 gradle.properties 中更新 android.enableR8=false。您需要添加此行,因为默认值 true。

    【讨论】:

    • 终于!!!太感谢了!我浪费了很多时间试图解决这个问题,如果我没有找到你的解决方案,我会被困一段时间。
    【解决方案2】:

    我遇到了同样的问题,我的build.gradle 的以下更改解决了它。

    android {
        compileSdkVersion 28
    
        ... 
        buildTypes {
            release {
                shrinkResources false
                minifyEnabled false
                signingConfig signingConfigs.release
                
            }
        }
    }
    

    参考:https://github.com/FirebaseExtended/flutterfire/issues/1412#issuecomment-570161645

    注意我知道它不是禁用缩小的完美解决方案。但似乎firebase团队正在努力,并将在未来的更新中解决

    【讨论】:

    【解决方案3】:

    通过升级 gradle 版本,我能够保持 android.enableR8=true。

    android/build.gradle

    来自:

    classpath 'com.android.tools.build:gradle:3.2.1'
    

    到:

    classpath 'com.android.tools.build:gradle:3.5.0'
    

    android/gradle/wrapper/gradle-wrapper.properties

    来自:

    distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
    

    到:

    distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
    

    【讨论】:

      【解决方案4】:

      我有一个类似的案例(同样的错误),所以我会试着告诉你发生了什么,也许和你有同样的问题。

      在我的情况下,我丢失了密钥库,所以我通过了请求新密钥等所有过程,之后我发布了一个新版本,我的应用程序以你的方式崩溃,经过很多次google 和我发现与签名有关的东西(因为在调试中工作但在发布中不起作用),所以我进入 firebase 控制台并再次下载 google-services.json 文件,然后惊喜......该文件有一个以前不存在的块。

      之后,我使用您在此处提供的命令在设备中进行测试(顺便谢谢!),哇!它有效。

      我还在控制台中更新了 SHA-1 签名密钥,所以这也可能有所帮助。 我希望我的回答能帮助您找到一些解决方案。

      【讨论】:

        【解决方案5】:

        https://github.com/flutter/flutter/issues/41576

        更改为 3.4.2 版本,即 build.gradle(project) 中的 com.android.tools.build:gradle:3.4.2,对我有用。

        【讨论】:

          猜你喜欢
          • 2020-01-29
          • 2022-08-09
          • 2021-07-17
          • 2020-04-04
          • 2021-05-10
          • 2020-06-24
          • 2020-06-21
          • 2020-03-01
          • 1970-01-01
          相关资源
          最近更新 更多