Deepti M
06/24/2020, 9:16 PMFatal Exception: java.lang.RuntimeException
Unable to start activity ComponentInfo{MainActivity}: org.koin.core.error.InstanceCreationException: Could not create instance for [Single:'com.google.firebase.database.FirebaseDatabase']
android.app.ActivityThread.performLaunchActivity
keyboard_arrow_down
Caused by org.koin.core.error.InstanceCreationException
Could not create instance for [Single:'com.google.firebase.database.FirebaseDatabase']
org.koin.core.instance.InstanceFactory.a
keyboard_arrow_down
Caused by com.google.firebase.database.DatabaseException
Calls to setPersistenceEnabled() must be made before any other usage of FirebaseDatabase instance
tynn
06/25/2020, 5:51 AMCalls to setPersistenceEnabled() must be made before any other usage of FirebaseDatabase instance
Deepti M
06/25/2020, 5:44 PMinterface RuntimeConfig {
var videoRepository: VideoRepository
}
class SingletonRuntimeConfig : RuntimeConfig {
companion object {
val instance = SingletonRuntimeConfig()
}
override var videoRepository: VideoRepository = videoRepositoryInstance
}
private val videoPlayer by lazy { VideoPlayer() }
private val staticTexts by lazy { StaticTexts() }
private val videoRepositoryInstance by lazy { VideoRepository() }
private val glideRequestOptions by lazy {
RequestOptions
.placeholderOf(R.drawable.white_background)
.error(R.drawable.white_background)
}
private val remoteConfig by lazy {
val remote = Firebase.remoteConfig
remote.setDefaultsAsync(R.xml.remote_config_defaults)
remote
}
val appModule = module {
single { videoPlayer }
single { staticTexts }
single { SingletonRuntimeConfig.instance as RuntimeConfig }
factory { get<RuntimeConfig>().videoRepository }
single {
Glide.with(androidContext())
.setDefaultRequestOptions(glideRequestOptions)
}
single { StorageUtils(androidContext()) }
single {
PreferenceHelper(
androidContext().getSharedPreferences(
"pref${androidContext().resources.getString(R.string.app_collection_id)}",
Context.MODE_PRIVATE
)
)
}
single { MultiProcessPreferencesHelper(androidContext()) }
}
val firebaseModule = module {
single {
val instance = FirebaseDatabase.getInstance()
instance.setPersistenceEnabled(true)
instance
}
single { FirebaseAuth.getInstance() }
single { Firebase.storage.reference }
single { remoteConfig }
}
val allModules = listOf(firebaseModule, appModule)
Deepti M
06/25/2020, 5:46 PMopen class BaseApplication : MultiDexApplication() {
override fun onCreate() {
super.onCreate()
// Start Koin
startKoin {
androidLogger()
androidContext(this@BaseApplication)
modules(allModules)
}
}
override fun onTerminate() {
super.onTerminate()
unloadKoinModules(allModules)
}
}
tynn
06/25/2020, 7:10 PMFirebaseDatabase.getInstance()
yourself, another library might access and use it before. Does the same occur when you use createdAtStart
with this declaration?Deepti M
06/27/2020, 6:18 PM