Flutter doesnt work properly with firebase on release apk/bundle

1,652

try changing

classpath 'com.google.gms:google-services:4.3.0'

in your project gradle.build to

classpath 'com.google.gms:google-services:3.2.1'

and in gradle.properties add

android.useAndroidX=true
android.enableJetifier=true
Share:
1,652
t0m3r
Author by

t0m3r

Updated on December 21, 2022

Comments

  • t0m3r
    t0m3r over 1 year

    When I execute flutter run my app works fine with Firebase (cloud_firestore) but whenever I do one of these commands: flutter build apk --release or flutter build appbundle --target-platform android-arm,android-arm64,android-x64 my app does not work properly with cloud_firestore. It doesn't do CRUD operations.

    pubspec.yaml (plugins):

      google_sign_in: 4.5.1
      firebase_auth: 0.16.1
      firebase_core: ^0.4.0+8
      firebase_analytics: ^5.0.14
      cloud_firestore: ^0.13.6
    

    app/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 = '15'
    }
    
    def flutterVersionName = localProperties.getProperty('flutter.versionName')
    if (flutterVersionName == null) {
        flutterVersionName = '15.0'
    }
    
    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
    
    def keystoreProperties = new Properties()
    def keystorePropertiesFile = rootProject.file('key.properties')
    if (keystorePropertiesFile.exists()) {
        keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
    }
    
    android {
        compileSdkVersion 28
    
        sourceSets {
            main.java.srcDirs += 'src/main/kotlin'
        }
    
        lintOptions {
            disable 'InvalidPackage'
        }
    
        defaultConfig {
            applicationId "com.tomeruby.iusefully"
            minSdkVersion 21
            targetSdkVersion 28
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
            multiDexEnabled true
            // ndk {
            //     abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a'
            // }
        }
    
        signingConfigs {
           release {
               keyAlias keystoreProperties['keyAlias']
               keyPassword keystoreProperties['keyPassword']
               storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
               storePassword keystoreProperties['storePassword']
           }
        }
    
        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.release
                multiDexEnabled true
            }
        }
    }
    
    flutter {
        source '../..'
    }
    
    dependencies {
        // implementation 'com.google.firebase:firebase-core:16.0.5'
        // implementation 'com.google.firebase:firebase-analytics-impl:16.2.3'
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    }
    
    apply plugin: 'com.google.gms.google-services'
    

    If you need more information, please let me know. Thanks in advance :D

    • EraftYps
      EraftYps almost 4 years
    • t0m3r
      t0m3r almost 4 years
      It's not login related, I'll update if it helps.
    • EraftYps
      EraftYps almost 4 years
      What error do you get?
    • t0m3r
      t0m3r almost 4 years
      I do not get a log tho...
    • EraftYps
      EraftYps almost 4 years
      Have you added the release Keystore SHA1 to your project in the firebase console?
    • t0m3r
      t0m3r almost 4 years
      yes, i haver 3 fingerprints 2 sha1s 1 debug 1 release and another one sha25 (or smth) for release.
  • Maciej Pszczolinski
    Maciej Pszczolinski over 1 year
    Why downgrading google services would help?
  • Rahman Rezaee
    Rahman Rezaee over 1 year
    may last version not compatible for now u can upgrade to v7