join 如何处理 android 中的属性?
How's koin works with properties in android?
我在官方 koin 文档中发现属性默认位置是 src/main/resources/koin.properties,但是当我尝试使用它时,我得到了这个漂亮的异常。
有人可以向我解释 koin 如何与 Android 上的属性一起使用吗?
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.access00(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 与 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)
}
}
问题是我应该使用不带参数的 fileProperties()
,而不是 fileProperties("filename")
。
然后只需使用 getProperty("property_name")
.
那是因为 /src/main/resources/koin.properties
是默认位置 包括 一个文件名...
我在官方 koin 文档中发现属性默认位置是 src/main/resources/koin.properties,但是当我尝试使用它时,我得到了这个漂亮的异常。 有人可以向我解释 koin 如何与 Android 上的属性一起使用吗?
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.access00(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 与 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)
}
}
问题是我应该使用不带参数的 fileProperties()
,而不是 fileProperties("filename")
。
然后只需使用 getProperty("property_name")
.
那是因为 /src/main/resources/koin.properties
是默认位置 包括 一个文件名...