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

[Bug]:java.lang.ClassCastException: java.lang.Void cannot be cast to com.easy.demo.net.bean.HttpData #221

Closed
ljiezhou opened this issue Jan 4, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@ljiezhou
Copy link

ljiezhou commented Jan 4, 2024

框架版本【必填】

EasyHttp-12.8 or EasyHttp:12.6

问题描述【必填】

请求的结果已经有了,但是会报错
java.lang.ClassCastException: java.lang.Void cannot be cast to com.easy.demo.net.bean.HttpData

复现步骤【必填】

调用测试接口即可复现

是否必现【必填】

项目 targetSdkVersion【必填】

34

出现问题的手机信息【必填】

HUAWEI TEL-AN00a

出现问题的安卓版本【必填】

Android 10

问题信息的来源渠道【必填】

自己遇到的

是部分机型还是所有机型都会出现【必答】

目前测试的情况是不分机型,都会出现

框架最新的版本是否存在这个问题【必答】

框架文档是否提及了该问题【必答】

是否已经查阅框架文档但还未能解决的【必答】

issue 列表中是否有人曾提过类似的问题【必答】

是否已经搜索过了 issue 列表但还未能解决的【必答】

是否可以通过 Demo 来复现该问题【必答】

提供报错堆栈

java.lang.ClassCastException: java.lang.Void cannot be cast to com.easy.demo.net.bean.HttpData
	at com.easy.demo.main.FanMainViewModel$test$1.onHttpSuccess(FanMainViewModel.kt:43)
	at com.hjq.http.listener.HttpCallbackProxy.onHttpSuccess(HttpCallbackProxy.java:38)
	at com.hjq.http.callback.NormalCallback.dispatchHttpSuccessCallback(NormalCallback.java:163)
	at com.hjq.http.callback.NormalCallback.lambda$onHttpResponse$2(NormalCallback.java:123)
	at com.hjq.http.callback.NormalCallback.$r8$lambda$ruKNKwI9yEHO75k7rzJHem_j4ys(NormalCallback.java:0)
	at com.hjq.http.callback.NormalCallback$$ExternalSyntheticLambda0.run(R8$$SyntheticClass:0)
	at android.os.Handler.handleCallback(Handler.java:900)
	at android.os.Handler.dispatchMessage(Handler.java:103)
	at android.os.Looper.loop(Looper.java:219)
	at android.app.ActivityThread.main(ActivityThread.java:8673)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)

提供截图或视频

No response

提供解决方案

No response

@ljiezhou ljiezhou added the bug Something isn't working label Jan 4, 2024
@getActivity
Copy link
Owner

小伙子,劳烦提供一个可供复现的 Demo 工程给我。

@ljiezhou
Copy link
Author

ljiezhou commented Jan 4, 2024

小伙子,劳烦提供一个可供复现的 Demo 工程给我。

demo我已经准备好了,怎么发给你呢

@getActivity
Copy link
Owner

@ljiezhou 直接上传到 Github issue 评论区

@ljiezhou
Copy link
Author

ljiezhou commented Jan 4, 2024

Uploading com.easy.demo.zip…
// api Easy.INSTANCE.easy_http_
// api(name: Easy.easy_http, ext: 'aar')
//直接依赖源码
api project(':library')

源码和远程依赖都试过

@getActivity
Copy link
Owner

@ljiezhou 小伙子,你的 demo 没有上传成功,重新上传一下。

@ljiezhou
Copy link
Author

ljiezhou commented Jan 4, 2024

com.easy.demo.zip

@getActivity
Copy link
Owner

小伙子,在经过了大量的测试和验证后发现,这个问题其实就是混淆导致的问题,你发的 Demo 工程里面,debug 模式也开启了代码混淆模式,间接导致 HttpCallbackProxy 携带的泛型在编译过程中被擦除,解决的方案是在混淆规则中加入以下规则:

# 必须要加上此规则,否则会导致泛型解析失败
-keep public class * implements com.hjq.http.listener.OnHttpListener {
    *;
}

@ljiezhou
Copy link
Author

ljiezhou commented Jan 8, 2024

感谢轮子哥。
因为项目需要开启混淆,所以我将 com.hjq.http.listener 里面的接口都添加了混淆规则后,所有场景都正常了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants