简体   繁体   中英

How's koin works with properties in android?

I found in official koin docs that properties default location is the src/main/resources/koin.properties , but when I trying to use it, I getting this beautiful exception. Can someone explain me how's koin works with properties on Android please?

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.app.AppApplication, PID: 12387
    java.lang.RuntimeException: Unable to create application com.example.app.AppApplication: org.koin.core.error.NoPropertyFileFoundException: No properties found for file 'koin.properties'
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6608)
        at android.app.ActivityThread.access$1500(ActivityThread.java:235)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1916)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:225)
        at android.app.ActivityThread.main(ActivityThread.java:7563)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:994)
     Caused by: org.koin.core.error.NoPropertyFileFoundException: No properties found for file 'koin.properties'
        at org.koin.core.registry.PropertyRegistry.loadPropertiesFromFile(PropertyRegistry.kt:100)
        at org.koin.core.KoinApplication.fileProperties(KoinApplication.kt:92)

Class with onCreate():

override fun onCreate() {
        super.onCreate()
        startKoin {
            androidLogger(Level.NONE)
            androidContext(this@AppApplication)
                
            //copied from docs
            // Load properties from the default location 
            // (i.e. `/src/main/resources/koin.properties`)
            fileProperties("koin.properties") //CRASH

            modules(appModule)
        }
    }

Thing is that i should use use fileProperties() , without parameters, instead fileProperties("filename") . And then just use getProperty("property_name") .

That's because /src/main/resources/koin.properties is default location INCLUDING a filename...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM