demitri kozlov
demitri kozlov

Reputation: 317

Flutter app crashes on start using fire base?

Started a new flutter project and trying to use firestore.

After following all step to add project to fire base.

Adding all plugins to pubspec.yaml and then running the project.

The log cat shows this:

04-04 14:54:56.061 24084-24084/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.firestoreflutterchat, PID: 24084
    java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.example.firestoreflutterchat-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.firestoreflutterchat-2, /vendor/lib, /system/lib]]
        at android.app.ActivityThread.installProvider(ActivityThread.java:4869)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:4461)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4401)
        at android.app.ActivityThread.access$1500(ActivityThread.java:139)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5097)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.example.firestoreflutterchat-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.firestoreflutterchat-2, /vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
        at android.app.ActivityThread.installProvider(ActivityThread.java:4854)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:4461) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4401) 
        at android.app.ActivityThread.access$1500(ActivityThread.java:139) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:136) 
        at android.app.ActivityThread.main(ActivityThread.java:5097) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
        at dalvik.system.NativeStart.main(Native Method

Before adding cloud firestore plugin the newly project was running after adding this i am having issue.

This is the Pubspec.yaml file :

 version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter



  cloud_firestore: ^0.13.4+2
  permission_handler: ^5.0.0+hotfix.3
  firebase_auth: ^0.15.5+3
  google_sign_in: ^4.4.0
  cupertino_icons: ^0.1.3

dev_dependencies:
  flutter_test:
    sdk: flutter




flutter:


  uses-material-design: true

Upvotes: 1

Views: 1297

Answers (2)

demitri kozlov
demitri kozlov

Reputation: 317

the problem did not resolve with multidex , only way was to remove it and follow this link

resolve multidex issue

it worked by removing these in your gradle

multiDexEnabled true

and

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}

and changing from this

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

to this

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

and in your path: /android/app

right click and create a file named proguard-rules.pro

and put these files inside the file

#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.**  { *; }

Upvotes: 1

Sanket Vekariya
Sanket Vekariya

Reputation: 2956

It seems some setups are still remaining for Firebase.
Checkout this link and set up the .json and .plist file accordingly in project.

If you further still facing the issue,
I would recommend some steps.
1) Delete all the build files of the project, invalid cache and restart android studio.
2) Follow the below changes in your project.

build.gradle file

android {
.....
defaultConfig {
......
 multiDexEnabled true//add this line
}
......
dependencies{
 compile 'com.android.support:multidex:1.0.1'//add this line
}

AndroidManifest.xml file

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
....
<application
....
 android:name="android.support.multidex.MultiDexApplication" 
...>
 <activity   />
...

</application>

</manifest>

Upvotes: 0

Related Questions