错误日志
进程: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)
主要活动:
@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())
}
}
- 委托测试:
@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
}
}
- 前卫:
-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
我不知道该怎么办 ...