dimanche 20 janvier 2019

Setting "isAccessible" to a reflected delegated property in release crashes the app

I'm trying to access the property of a DelegatedProperty's object instance:

val key: String = preferences.getKey(Preferences::projectName)

the function getKey returns the value I want:

fun getKey(property: KProperty1<Preferences, *>): String {
    property.isAccessible = true // note this line
    val delegate = property.getDelegate(this)

    return when (delegate) {
        is PreferencesProperty<*> -> delegate.key
        is WrapperPreferencesProperty<*, *> -> delegate.key
        else -> throw IllegalStateException("Can't observe the property - ${property.name}")
    }
}

The delegate property in question is written like so:

var projectName: String by PreferencesProperty(context, "project_name", "")

In debug, it's working fine, but when I'm running it in release, the line:

property.isAccessible = true

crashes the application.

the error is:

Property ‘projectName’ (JVM signature: getProjectName()Ljava/lang/String;) not resolved in class com.trax.retailexecution.util.Preferences

and the stack trace is:

“e.i.b.a.R.b(KDeclarationContainerImpl.kt:114)”
“e.i.b.a.Ga.invoke(KPropertyImpl.kt:101)”
“e.i.b.a.Ga.invoke(KPropertyImpl.kt:29)”
“e.i.b.a.Xa$a.a(ReflectProperties.java:92)”
“e.i.b.a.Ba.f(KPropertyImpl.kt:104)”
“e.i.b.a.Ha.invoke(KPropertyImpl.kt:51)”
“e.i.b.a.Ha.invoke(KPropertyImpl.kt:29)”
“e.i.b.a.Xa$a.a(ReflectProperties.java:92)”
“e.i.b.a.Ba.k(KPropertyImpl.kt:78)”
“e.i.b.c.a(ReflectJvmMapping.kt:40)”
“e.i.b.a.a(KCallablesJvm.kt:65)”
“com.trax.retailexecution.util.Preferences.getKey(Preferences.kt:115)”

Naturally since it's configured to release, it's compressed and unintelligible.

Any thoughts?





Aucun commentaire:

Enregistrer un commentaire