kotlin отражает cra sh , установка minifyEnabled в значение true. KotlinReflectionInternalError: свойство 'xxx' не разрешено в классе 'xxx' - PullRequest
0 голосов
/ 29 апреля 2020
  • журнал ошибок

    Процесс: com.sjianjun.test. kotlin .delegate, PID: 23730 kotlin .reflect.jvm.internal.KotlinReflectionInternalError: Свойство DelegateTest ' (Подпись JVM: getDelegateTest () Ljava / lang / Object;) не разрешена в классе com.sjianjun.test. kotlin .delegate.MainActivity в kotlin .reflect.jvm.internal.KDeclarationContainerImpl.findPropertyDescriptor (: 115)

  • MainActivity:

@Keep
class MainActivity : AppCompatActivity() {
    var delegateTest by DelegateTest()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        this::class.java.declaredMethods.forEach {
            Log.e("DelegateTest", it.toString())
        }

        Log.e("DelegateTest ", delegateTest.toString()+DelegateTest::class.java.name)
        delegateTest = 1
        Log.e("DelegateTest ", delegateTest.toString())
    }
}

  • DelegateTest:
@Keep
class DelegateTest {
    var value: Any? = null
    operator fun getValue(thisRef: Any?, property: KProperty<*>): Any {
// crash : property
        return "value:$value $property"
    }

    operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Any) {
        this.value = value
    }

}
  • proguard:
-keep class com.sjianjun.test.kotlin.delegate.DelegateTest{*;}
-keep class com.sjianjun.test.kotlin.delegate.MainActivity{*;}
-keepclassmembers class com.sjianjun.test.kotlin.delegate.MainActivity{*;}
-keep class kotlin.reflect.**{*;}
  • и журнал:
 E/kotlin.delegat: Unable to peek into adb socket due to error. Closing socket.: Connection reset by peer
 E/DelegateTest: public void com.sjianjun.test.kotlin.delegate.MainActivity._$_clearFindViewByIdCache()
 E/DelegateTest: public android.view.View com.sjianjun.test.kotlin.delegate.MainActivity._$_findCachedViewById(int)
 E/DelegateTest: public final java.lang.Object com.sjianjun.test.kotlin.delegate.MainActivity.getDelegateTest()
 E/DelegateTest: protected void com.sjianjun.test.kotlin.delegate.MainActivity.onCreate(android.os.Bundle)
 E/DelegateTest: public final void com.sjianjun.test.kotlin.delegate.MainActivity.setDelegateTest(java.lang.Object)
 E/DelegateTest: value:null var com.sjianjun.test.kotlin.delegate.MainActivity.delegateTest: kotlin.Anycom.sjianjun.test.kotlin.delegate.DelegateTest
 E/DelegateTest: value:1 var com.sjianjun.test.kotlin.delegate.MainActivity.delegateTest: kotlin.Any

Я обнаружил, что Proguard удалит следующие поля:

 E/DelegateTest: value:null var com.sjianjun.test.kotlin.delegate.MainActivity.delegateTest: kotlin.Anycom.sjianjun.test.kotlin.delegate.DelegateTest
 E/DelegateTest: value:1 var com.sjianjun.test.kotlin.delegate.MainActivity.delegateTest: kotlin.Any

I не знаю что делать ...

...