简体   繁体   English

Flutter:使用 minifyEnabled 在发布模式下 Firestore 不可用错误

[英]Flutter: Firestore unavailable error on release mode with minifyEnabled

I have been experiencing a very strange error.我遇到了一个非常奇怪的错误。 I have been developing an app for some time now (3 years ago) with flutter.我已经有一段时间(3 年前)使用 Flutter 开发应用程序了。 I migrated the application to Null safety and from that moment the app started to crash in release mode causing the error我将应用程序迁移到 Null 安全,从那一刻起应用程序开始在发布模式下崩溃,导致错误

[cloud_firestore/unavailable] The service is currently unavailable. [cloud_firestore/unavailable] 该服务当前不可用。 This is a most likely a transient condition and may be corrected by retrying with a backoff.这很可能是一种瞬态情况,可以通过回退重试来纠正。

Everything works fine on debug mode.在调试模式下一切正常。

I have the following configuration in the related files in the apk compilation in release mode.我在release模式下编译apk的相关文件中有如下配置。

android/build.gradle android/build.gradle

buildscript {
    ext.kotlin_version = '1.4.21'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath 'com.google.gms:google-services:4.3.8'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}
...

android/app/build.gradle android/app/build.gradle

...
android {

    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
        }
    }
}
...

proguard-rules.pro proguard-rules.pro

## Flutter wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.**  { *; }
-keep class io.flutter.util.**  { *; }
-keep class io.flutter.view.**  { *; }
-keep class io.flutter.**  { *; }
-keep class io.flutter.plugins.**  { *; }
-keep class com.google.firebase.** { *; }
-keep class com.revenuecat.purchases.** { *; }
-keep class androidx.lifecycle.DefaultLifecycleObserver
-dontwarn android.**

If I change minifyEnabled false shrinkResources false to Everything works fine on release mod too, but my app size increase by 27%.如果我将minifyEnabled false shrinkResources false更改为 Everything 在发布 mod 上也可以正常工作,但我的应用程序大小增加了 27%。

One thing that may work for you is go back to using proguard instead of R8, it may be a step back but could help you.可能对您有用的一件事是重新使用 proguard 而不是 R8,这可能是退后一步,但可以帮助您。 For that to happen the configuration of the release should look like:为此,发行版的配置应如下所示:

buildTypes {
    release {
        signingConfig signingConfigs.release
        minifyEnabled true
        shrinkResources true
        useProguard true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    }
}

And maybe you should add to the build gradle that you don't want to use R8:也许您应该将不想使用 R8 的构建 gradle 添加到:

android.enableR8=true

Another option would be to look at this file and check for the imports to see if there is maybe a secondary library that you should add to your proguard configuration file: /android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant另一种选择是查看此文件并检查导入以查看是否存在应该添加到 proguard 配置文件中的辅助库:/android/app/src/main/java/io/flutter/plugins/生成的插件注册者

You can also check the compilation log to see any errors related to some library (link: https://github.com/flutter/flutter/issues/15100#issuecomment-474687849 )您还可以检查编译日志以查看与某些库相关的任何错误(链接: https : //github.com/flutter/flutter/issues/15100#issuecomment-474687849

Have you tried updating to a relatively new version of https://pub.dev/packages/cloud_firestore , eg 2.5.2 currently?您是否尝试更新到相对较新的https://pub.dev/packages/cloud_firestore版本,例如当前的 2.5.2?

What version are you currently using?您目前使用的是什么版本?

Share your pubspec.yaml, sometimes plugins can conflict too.分享您的 pubspec.yaml,有时插件也会发生冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM