I think this bug report and solution will be useful for many developers who may use react-native-firebase
.
i used it in version 5.2.5 with react-native:057.8 so this solution may be more useful for who use this versions
the problem began when is ran the app on Android 4.* the app were crashing with no error and sign like red page or etc.
it took me into a trouble until i found whats the reason. when i ran adb logcat D
and got this:
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.driver-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.driver-1, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:4793)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4385)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4325)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
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.driver-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.driver-1, /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:4778)
... 12 more
Solution: before i test my app on android 4 i had some problem with multidex
which solved by this:
defaultConfig {
applicationId "com.driver"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
vectorDrawables.useSupportLibrary = true
multiDexEnabled true //<<here!!!!!!!!!!!!!!!!!!!!!!!!!!
}
and it fixed the problem but if you think that will be enough you are totally mistake... so keep this steps :
dependencies:{
...
implementation 'com.android.support:multidex:1.0.3'
}
and go to MainApplication.java file and implement this changes:
import android.support.multidex.MultiDexApplication; << in react native > 60 you need this
import androidx.multidex.MultiDex; <<<in react native 60.* you need this
public class MainApplication extends MultiDexApplication implements ReactApplication { //<<extend Multidex like this
//...
//...
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
MultiDex.install(this);
}
}
Enjoy your firebase on android 4 :+1:
Indeed - @Salakar I PRd this here: https://github.com/invertase/react-native-firebase-starter/pull/110
@imansalhi pity us still working with Android 4 :smile: :sob:
This is fixed in the starter and demo'd in https://github.com/mikehardy/rnfbdemo
@imansalhi You saved my day :) I was facing the same problem while running the app on Android 4.4.
I have followed all the steps you mentioned but I was facing the error:
package android.support.multidex does not exist
than I replaced
import android.support.multidex.MultiDexApplication;
with
import androidx.multidex.MultiDexApplication
in MainApplication.java
then it starts working fine.
@shehzadosama @imansalhi
Thanks guys for your solutions. You fixed one of my biggest problems. You are amazing :)
Still there is a little problem. After adding import androidx.multidex.MultiDexApplication
u might face another problem.
So add import androidx.multidex.MultiDex;
to fix that
Most helpful comment
@shehzadosama @imansalhi
Thanks guys for your solutions. You fixed one of my biggest problems. You are amazing :)
Still there is a little problem. After adding
import androidx.multidex.MultiDexApplication
u might face another problem.So add
import androidx.multidex.MultiDex;
to fix that