Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [cloud_firestore] Firestore crashes in release build of Flutter Android app. #7406

Closed
deZak opened this issue Nov 22, 2021 · 13 comments
Closed
Labels
resolution: solution-provided A solution has been provided in the issue. type: bug Something isn't working

Comments

@deZak
Copy link

deZak commented Nov 22, 2021

Firestore crashes release build of Flutter app in Android. After going through this post in Stackoverflow (https://stackoverflow.com/questions/69094856/flutter-firestore-unavailable-error-on-release-mode-with-minifyenabled), tried three different configurations in buildTypes.release in android/app/build.gradle file.

Case 1:
In builTypes.release:

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

In proguard-rules.pro file:
-keep class com.example.appname.** { *; }

Created appbundle by running:

flutter clean 
flutter build appbundle

After releasing for Internal Testing in Google Play, app crashes on accessing Firestore. Crash report:

java.lang.A
ssertionError: impossible
at java.lang.Enum$1.create(Enum.java:272)
at java.lang.Enum$1.create(Enum.java:263)
at libcore.util.BasicLruCache.get(BasicLruCache.java:58)
at java.lang.Enum.getSharedConstants(Enum.java:289)
at java.lang.Class.getEnumConstantsShared(Class.java:2416)
at java.util.EnumSet.getUniverse(EnumSet.java:407)
at java.util.EnumSet.noneOf(EnumSet.java:109)
at java.util.EnumSet.of(EnumSet.java:235)
at d.b.M1.o.<clinit>(Unknown Source:102)
at d.b.M1.o.forTarget(Unknown Source:0)
at d.b.M1.p.a(:1)
at d.b.J0.b(:2)
at com.google.firebase.firestore.r0.V.e(:2)
at com.google.firebase.firestore.r0.r.call(Unknown Source:2)
at c.c.a.b.i.N.run(Unknown Source:4)
at com.google.firebase.firestore.s0.H.a(:1)
at com.google.firebase.firestore.s0.l.run(Unknown Source:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.NoSuchMethodException: values []
at java.lang.Class.getMethod(Class.java:2068)
at java.lang.Class.getDeclaredMethod(Class.java:2047)
at java.lang.Enum$1.create(Enum.java:268)
... 19 more

Case 2:
Tried to build appbundle again changing buildType.release to (proguard rules same as above):

signingConfig signingConfigs.release
 minifyEnabled false

This time, Gradle failed to build appbundle. Log from terminal is:

Running Gradle task 'bundleRelease'...
Running Gradle task 'bundleRelease'...FAILURE: Build failed with an exception.
Running Gradle task 'bundleRelease'...
Running Gradle task 'bundleRelease'...* Where:
Running Gradle task 'bundleRelease'...Build file 'D:\FlutterApps\android\appname\android\build.gradle' line: 25 
Running Gradle task 'bundleRelease'...
Running Gradle task 'bundleRelease'...* What went wrong:
Running Gradle task 'bundleRelease'...A problem occurred evaluating root project 'android'.
Running Gradle task 'bundleRelease'...> A problem occurred configuring project ':app'.
Running Gradle task 'bundleRelease'...   > Removing unused resources requires unused code shrinking to be turned on. See http://d.android.com/r/tools/shrink-resources.html for more information.
Running Gradle task 'bundleRelease'...
Running Gradle task 'bundleRelease'...* Try:
Running Gradle task 'bundleRelease'...Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Running Gradle task 'bundleRelease'...
Running Gradle task 'bundleRelease'...* Get more help at https://help.gradle.org
Running Gradle task 'bundleRelease'...
Running Gradle task 'bundleRelease'...BUILD FAILED in 4s
Running Gradle task 'bundleRelease'...                              5.8s
Gradle task bundleRelease failed with
exit code 1

Case 3:
buildTypes.release configuration is (no change in proguard rules):

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

However, in this case built appbundle by running:

flutter clean
flutter build appbundle --no-shrink

After releasing for Internal Testing in Google Play, app crashes on accessing Firestore. Crash report:

java.lang.AssertionError: impossible
at java.lang.Enum$1.create(Enum.java:272)
at java.lang.Enum$1.create(Enum.java:263)
at libcore.util.BasicLruCache.get(BasicLruCache.java:58)
at java.lang.Enum.getSharedConstants(Enum.java:289)
at java.lang.Class.getEnumConstantsShared(Class.java:2416)
at java.util.EnumSet.getUniverse(EnumSet.java:407)
at java.util.EnumSet.noneOf(EnumSet.java:109)
at java.util.EnumSet.of(EnumSet.java:235)
at d.b.M1.o.<clinit>(Unknown Source:102)
at d.b.M1.o.forTarget(Unknown Source:0)
at d.b.M1.p.a(:1)
at d.b.J0.b(:2)
at com.google.firebase.firestore.r0.V.e(:2)
at com.google.firebase.firestore.r0.r.call(Unknown Source:2)
at c.c.a.b.i.N.run(Unknown Source:4)
at com.google.firebase.firestore.s0.H.a(:1)
at com.google.firebase.firestore.s0.l.run(Unknown Source:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.NoSuchMethodException: values []
at java.lang.Class.getMethod(Class.java:2068)
at java.lang.Class.getDeclaredMethod(Class.java:2047)
at java.lang.Enum$1.create(Enum.java:268)
... 19 more

Run flutter doctor and paste the output below:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.5.3, on Microsoft Windows [Version 10.0.19042.1348], locale en-IN)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Chrome - develop for the web
[√] Android Studio (version 2020.3)
[√] VS Code (version 1.62.3)
[√] Connected device (2 available)

• No issues found!

@deZak deZak added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Nov 22, 2021
@deZak deZak changed the title 🐛 Firestore: Firestore crashes in release build of Flutter Android app. 🐛 [cloud_firestore] Firestore crashes in release build of Flutter Android app. Nov 22, 2021
@maheshmnj maheshmnj added the triage Issue is currently being triaged. label Nov 23, 2021
@maheshmnj
Copy link
Member

maheshmnj commented Nov 23, 2021

Hi @deZak, Thanks for filing the issue. Can you please share what version of the cloud_firestore are you using?

Build file 'D:\FlutterApps\android\appname\android\build.gradle' line: 25

Please share your android/build.gradle file.

On a side note

  • I created a new flutter project on stable 2.5.3
  • added plugins to yaml
  cloud_firestore: ^3.1.0
  firebase_core: ^1.10.0     

and I was able to generate a release apk.

@maheshmnj maheshmnj added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Nov 23, 2021
@deZak
Copy link
Author

deZak commented Nov 24, 2021

Hi @maheshmnj , thanks for responding.
Using version 3.1.0 of cloud_firestore.

android/build.gradle file:

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        mavenCentral()
    }

    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"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Additional info, dependencies in pubspec.yaml file is :

dependencies :
  agora_rtc_engine: ^4.0.7
  cached_network_image: ^3.1.0
  cloud_firestore: '^3.1.0'
  file_picker: ^4.1.1
  firebase_core: '^1.10.0'
  firebase_messaging: '^11.1.0'
  firebase_storage: '^10.1.0'
  flutter:
    sdk: flutter
  hive: ^2.0.4
  hive_flutter: ^1.1.0
  http: ^0.13.4
  image_picker: ^0.8.4+2
  json_annotation: ^4.3.0
  lottie: ^1.2.1
  open_file: ^3.2.1
  pdf: ^3.6.0
  permission_handler: ^8.2.5
  provider: ^6.0.1
  razorpay_flutter: ^1.2.7

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Nov 24, 2021
@maheshmnj
Copy link
Member

@deZak can you please share the complete output of flutter run -v (preferably in a textfile as the output will be long)?

Thanks

@maheshmnj maheshmnj added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Nov 24, 2021
@google-oss-bot google-oss-bot added the Stale Issue with no recent activity label Dec 3, 2021
@google-oss-bot
Copy link

Hey @deZak. 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!

@Sagarsappic
Copy link

Hello i also have the same issue.......in release mode firestore not working

@google-oss-bot google-oss-bot removed the Stale Issue with no recent activity label Dec 4, 2021
@Sagarsappic
Copy link

Sagarsappic commented Dec 4, 2021

project level build.gradle/

buildscript {
    ext.kotlin_version = '1.5.10'
    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"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app level build.gradle/

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
android {
    compileSdkVersion 31
    buildToolsVersion "30.0.2"
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }


    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.roccabox.roccabox"
        minSdkVersion 23
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation platform('com.google.firebase:firebase-bom:28.4.0')
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.google.firebase:firebase-messaging:21.1.0'
}

pubsec.yaml file/

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

 
  cupertino_icons: ^1.0.2
  flutter_svg: ^0.22.0
  carousel_slider: ^4.0.0
  http: ^0.13.3
  shared_preferences: ^2.0.5
  email_validator: ^2.0.1
  image_picker: ^0.8.0+3
  country_code_picker: ^2.0.2
  cached_network_image: ^3.1.0
  flutter_launcher_icons: ^0.9.0
  readmore: ^2.1.0
  photo_view: ^0.12.0
  cloud_firestore: ^3.1.1
  firebase_messaging:
  firebase_core: ^1.10.2
  flutter_local_notifications: ^9.1.4
  firebase_storage:
  cloud_functions: ^3.2.0
  firebase_auth: ^3.3.0
  video_player: ^2.2.5
  url_launcher: ^6.0.12
  file_picker: ^4.1.3
  flutter_pdfview: ^1.2.1
  path_provider:
  permission_handler:
  provider: ^6.0.1
  agora_rtc_engine: ^4.0.7
  flutter_ringtone_player: ^3.0.0
  rxdart: ^0.26.0
  audioplayers: ^0.20.1
  uuid: ^3.0.5
  multi_image_picker: ^4.7.14
dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_native_splash: ^1.1.8+4


flutter_icons:
  android: "launcher_icon"
  ios: true
  image_path: assets/logo.png
  image_path_ios: assets/app_icon_ios.jpg

flutter_native_splash:
  color: "#FFFFFF"
  image: assets/logo.png
  color_dark: "#1a1a1a"
  android: true
  ios: true

flutter:

 
  uses-material-design: true

  assets:
    - assets/

  fonts:
    - family: Poppins
      fonts:
        - asset: font/Poppins-Regular.ttf
        - asset: font/Poppins-SemiBold.ttf
          weight: 500
        - asset: font/Poppins-Light.ttf
          weight: 300

@maheshmnj
Copy link
Member

@Sagarsappic, please share flutter run -v

@deZak can you please share the complete output of flutter run -v (preferably in a textfile as the output will be long)?

Thanks

@JAICHANGPARK
Copy link

I had a same Issue
How to fix this issue??

@google-oss-bot
Copy link

Hey @deZak. 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 google-oss-bot added the Stale Issue with no recent activity label Dec 16, 2021
@LearningLeopard
Copy link

Is this issue resolved?
I am having the same issue and completely lost as to what to do next

@google-oss-bot google-oss-bot removed the Stale Issue with no recent activity label Dec 24, 2021
@Sagarsappic
Copy link

Is this issue resolved? I am having the same issue and completely lost as to what to do next

Yes it resolved. you have to go to this link
https://docs.flutter.dev/deployment/android
and then follow this section
Configure signing in gradle
also add these two line to buildtypes in release
minifyEnabled false
shrinkResources false

@LearningLeopard
Copy link

LearningLeopard commented Dec 25, 2021

Thank you! It worked!

@russellwheatley
Copy link
Member

Thanks for letting us know, @Sagarsappic 👍

@maheshmnj maheshmnj added resolution: solution-provided A solution has been provided in the issue. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Dec 30, 2021
@firebase firebase locked and limited conversation to collaborators Jan 30, 2022
@darshankawar darshankawar removed the triage Issue is currently being triaged. label Aug 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
resolution: solution-provided A solution has been provided in the issue. type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants