I have a multi module project. I want to be able to run the instrumentation tests i'm writing for these modules separately. I am continually running into the below error when I run the tests and initialize the activity.
Default FirebaseApp is not initialized in this process. Make sure to call FirebaseApp.initializeApp(Context) first.
I have tried explicitly calling this in my test code with the test app's context, but to no avail. I know firebase is set up through the config files and I don't explicitly call it to set it up. It automatically is initialized through a content provider (read a blog) before the actual app starts.
Because it would be a static call and we don't explicitly call it, I don't see a way to mock it either. Is there a way to completely disable firebase for my UITest runs in my modules?
Firebase are using a content-provider to hook the library up before the application's onCreate() method.
This content provider is registered in the library com.google.firebase.firebase-perf (which is imported by the line platform("com.google.firebase:firebase-bom:... from your build.gradle file)
To stop firebase hook-up process problems, you can either:
onCreate() (good if you want firebase to be correctly setup and testable in your android tests)to create a custom application class:
src/androidTest/ create file MyCustomTestApp.kt (or any other class name), with content:package <...> // use the default package that was set when you created the file
import android.app.Application
import com.google.firebase.FirebaseApp
class MyCustomTestApp: Application() {
override fun onCreate() {
super.onCreate()
FirebaseApp.initializeApp(this)
}
}
src/androidTest/AndroidManifest.xml file (create new file if it doesn't exist yet) add the following:<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:versionCode="1"
android:versionName="1.0" >
<application
android:name="here setup the path to your custom application class, e.g. com.yourApp.package.name.MyCustomTestApp"
tools:replace="android:name">
<--! if you have test activities etc, you register them here ... -->
</application>
</manifest>
to disable firebase's content-provider altogether:
in file src/androidTest/AndroidManifest.xml file (create new file if it doesn't exist yet) add the following:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application>
<!-- disable firebase provider to get rid of "Default FirebaseApp is not initialized in this process" exceptions -->
<provider
android:authorities="${applicationId}.firebaseperfprovider"
android:name="com.google.firebase.perf.provider.FirebasePerfProvider"
tools:node="remove" />
</application>
</manifest>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With