Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get provider com.google.firebase.perf.provider.FirebasePerfProvider on pre-lollipop devices

On all versions before v21 (i.e. 16-19), my app crashes on start because of the following error:

E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to get provider com.google.firebase.perf.provider.FirebasePerfProvider: java.lang.ClassNotFoundException: com.google.firebase.perf.provider.FirebasePerfProvider
    at android.app.ActivityThread.installProvider(ActivityThread.java:4563)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4190)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4132)
    at android.app.ActivityThread.access$1300(ActivityThread.java:130)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.ClassNotFoundException: com.google.firebase.perf.provider.FirebasePerfProvider
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    at android.app.ActivityThread.installProvider(ActivityThread.java:4548)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4190) 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4132) 
    at android.app.ActivityThread.access$1300(ActivityThread.java:130) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255) 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    at android.os.Looper.loop(Looper.java:137) 
    at android.app.ActivityThread.main(ActivityThread.java:4745) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:511) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
    at dalvik.system.NativeStart.main(Native Method) 

On Android 5 and up, my app works without any issues.

I am targeting SDK version 27 and my minimum version is 14. Yes, I have also enabled Multidex support. I have seen some answers about that, but they aren't relevant to my issue as I have this enabled for years already. Currently I am also using Firebase services 11.8.0, the latest.

like image 330
Bjarn Bronsveld Avatar asked Jan 21 '18 19:01

Bjarn Bronsveld


2 Answers

Fixed it!

Although I had multidex imported and enabled in Gradle, I had to change my Application class to extend MultidexApplication instead of Application.

Hope it helps others too!

like image 134
Bjarn Bronsveld Avatar answered Oct 02 '22 23:10

Bjarn Bronsveld


Thanks for the MultiDex tip, which didn't fix this problem for me, but was useful anyway.

What fixed it for me was, in my app build.gradle moving

apply plugin: 'com.google.firebase.firebase-perf'

to be before the following:

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'

In other words, applying firebase-perf as early as possible, but after 'com.android.application'.

Sharing here in case this works for anyone else.

like image 30
Edmund Johnson Avatar answered Oct 03 '22 00:10

Edmund Johnson