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:
- create a custom Application class for android-test, call FirebaseApp.initializeApp() once in the application's
onCreate()
(good if you want firebase to be correctly setup and testable in your android tests)
- disable firebase's provider (perfect if you don't need fire, but might cause problems if you use firebase services (such as creashlytics etc) in your tested code)
How to do it?
to create a custom application class:
- in folder
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)
}
}
- 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"
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>