Hi There, I am receiving following exception in so...
# koin
d
Hi There, I am receiving following exception in some devices, can anyone help me to resolve? Fatal Exception: java.lang.RuntimeException Unable to start activity ComponentInfo{com.alivewallpaper.free/com.alivewallpaper.replicantlib.MainActivity}: org.koin.core.error.InstanceCreationException: Could not create instance for [Single:'com.google.firebase.database.FirebaseDatabase'] Precised logs:
Fatal 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
t
Calls to setPersistenceEnabled() must be made before any other usage of FirebaseDatabase instance
d
Yes I am doing it. Here is the code...
interface 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)
And here is the Application class where I initiate Koin:
open class BaseApplication : MultiDexApplication() {
override fun onCreate() {
super.onCreate()
// Start Koin
startKoin {
androidLogger()
androidContext(this@BaseApplication)
modules(allModules)
}
}
override fun onTerminate() {
super.onTerminate()
unloadKoinModules(allModules)
}
}
t
If this is the only case you actually use
FirebaseDatabase.getInstance()
yourself, another library might access and use it before. Does the same occur when you use
createdAtStart
with this declaration?
d
No, didn't try it yet. Will do and let you know. Thanks!
775 Views