Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType #1088

Open
PKReejesh opened this issue Jul 7, 2023 · 1 comment

Comments

@PKReejesh
Copy link

I am getting two errors

  1. java.lang.IllegalArgumentException: Unable to create call adapter for class androidx.lifecycle.LiveData from the caller.

  2. Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType , which is pointed at the line

if (getRawType(returnType) != LiveData::class.java) { return null }

File :
https://github.com/android/architecture-components-samples/blob/master/GithubBrowserSample/app/src/main/java/com/android/example/github/util/LiveDataCallAdapterFactory.kt

This happens in the release apk.
Recent changes : Added co routine components.

Requesting to explain the issue please.

@PKReejesh
Copy link
Author

PKReejesh commented Jul 10, 2023

When debugging with this line, inside LiveDataCallAdapterFactory get method,

String name = returnType.getClass().getName(); //to get full.package.name.of.Cat
Log.i(TAG,"Check#in between:"+name);

Found differences in release and debug apk.

Debug apk printed the log as : Check#in between:libcore.reflect.ParameterizedTypeImpl
Release apk printed the log as : Check#in between:java.lang.Class

Also with breakpoints, I was able to see that, the Type variable was wrapped with a LiveData

So,

Adding
-keep class androidx.lifecycle.LiveData { *; }

to proguard solved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant