skydoves / Bindables

🧬 Android DataBinding kit that enables notifying UI layers of data changes without requiring backing properties or relying on reactive programming models like LiveData and StateFlow.
Apache License 2.0
321 stars 19 forks source link

App crashes on 2nd time debug app launch on andoroid 11 phone #19

Closed keyur9779 closed 2 years ago

keyur9779 commented 2 years ago

Please complete the following information:

Describe the Bug: App keeps crashing when launching 2nd time while development.

You can try running current sample version in any android 11 to check the below issue.

kotlin.jvm.KotlinReflectionNotSupportedError: Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath

Below is class and line number where it crases,

Class : BindingManager, LineNumber : 73( it.getter.hasAnnotation()). - It crases due to getter method of reflection jar.

skydoves commented 2 years ago

Hey @keyur9779,

I just checked the demo project works fine for my environment. It seems your Gradle system couldn't download the dependency of the kotlin-refleciton. Could you check out your version of Kotlin in your Android Studio? You must use 1.5.10 or higher in the demo project.

Screen Shot 2021-12-29 at 4 37 45 PM

keyur9779 commented 2 years ago

Hi Sir,

Yes, I'm using latest kotlin version(1.6.10), and I have also tried with version 1.5.10 but it didn't worked. Please follow below steps in android -11

  1. launch debug app from studio - App will not crash
  2. launch debug app from studio 2nd time - App will carsh with reflection error. I faced this issue with samsung s10.

Log :

kotlin.jvm.KotlinReflectionNotSupportedError: Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath at kotlin.jvm.internal.CallableReference.getReflected(CallableReference.java:98) at kotlin.jvm.internal.PropertyReference.getReflected(PropertyReference.java:31) at kotlin.jvm.internal.PropertyReference1.getGetter(PropertyReference1.java:40) at kotlin.jvm.internal.PropertyReference1.getGetter(PropertyReference1.java:12) at com.skydoves.bindables.BindingManager.getBindingIdByProperty$bindables_debug(BindingManager.kt:73) at com.skydoves.bindables.StateFlowBindingPropertyId.provideDelegate(FlowBindingProperty.kt:234) at com.skydoves.bindablesdemo.MainViewModel.(MainViewModel.kt:37) at com.skydoves.bindablesdemo.DaggerBindableApp_HiltComponents_SingletonC$ViewModelCImpl$SwitchingProvider.get(DaggerBindableApp_HiltComponents_SingletonC.java:427) at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory$1.create(HiltViewModelFactory.java:100) at androidx.lifecycle.AbstractSavedStateViewModelFactory.create(AbstractSavedStateViewModelFactory.java:69) at androidx.lifecycle.AbstractSavedStateViewModelFactory.create(AbstractSavedStateViewModelFactory.java:84) at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory.create(HiltViewModelFactory.java:109) at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187) at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) at androidx.lifecycle.ViewModelLazy.getValue(ViewModelProvider.kt:54) at androidx.lifecycle.ViewModelLazy.getValue(ViewModelProvider.kt:41) at com.skydoves.bindablesdemo.MainActivity.getViewModel(MainActivity.kt:30) at com.skydoves.bindablesdemo.MainActivity.onCreate(MainActivity.kt:35) at android.app.Activity.performCreate(Activity.java:8207) at android.app.Activity.performCreate(Activity.java:8191) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3808) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4011) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2325) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:246) at android.app.ActivityThread.main(ActivityThread.java:8633) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

skydoves commented 2 years ago

Hmm, I have the same device and I followed your processes and it works as well. Then could you build by adding the below dependency on the app's build.gradle file? Or by changing the compile options to Java 11.

compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = '11'
    }

implementation "org.jetbrains.kotlin:kotlin-reflect:$versions.kotlin"
skydoves commented 2 years ago

And I can see the error that you attached is related to Hilt. Also, you can try the new version of the Hilt (2.40.5)

keyur9779 commented 2 years ago

Hi Sir,

No Luck,

I have updated gradle files based on your 2 inputs, and same issue.

Thank you

keyur9779 commented 2 years ago

Hi Sir,

I have tried your last commit which work very fine with android studio version(arctic fox).

Thank you.