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

热修复成功但在7.0系统上会出现ClassCastException异常,如何更好的解决? #433

Closed
casvie opened this issue Apr 1, 2017 · 3 comments

Comments

@casvie
Copy link

casvie commented Apr 1, 2017

异常类型:ClassCastException
手机型号:华为Mate8
手机系统版本:7.0
tinker版本:如:1.7.7
gradle版本:如:2.2.3
是否使用热更新SDK: 否
系统:Windows

堆栈/日志:
java.lang.ClassCastException: tinker.sample.android.app.MyApplication cannot be cast to tinker.sample.android.app.MyApplication
at tinker.sample.android.app.MainActivity$6.onClick(MainActivity.java:114)
at android.view.View.performClick(View.java:5646)
at android.view.View$PerformClick.run(View.java:22450)
at android.os.Handler.handleCallback(Handler.java:755)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6524)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)

报错的代码片段:
((MyApplication) getApplication()).setToken("set data");

MyApplication是自定义的仿官方实体类:
public class MyApplication extends TinkerApplication {

public String token;

public MyApplication() {
      super(ShareConstants.TINKER_ENABLE_ALL, "tinker.sample.android.app.MyApplicationLike",
            "com.tencent.tinker.loader.TinkerLoader", false);
}

public void setToken(String token) {
    this.token = token;
}

public String getToken() {
    return token;
}

}
经多次测试,这个异常暂只出现7.0系统上。
查询wiki,说是不应该再使用这个application实例。但是当前程序已经有很多地方使用了这种通过application实例进行set、get方式的代码,全部调换的话太不方便。
请问有方法解决这个问题么?

@shwenzhang
Copy link
Contributor

  1. 按照文档完成改造
  2. 使用类似 tinkerpatch的一键接入功能

@van416
Copy link

van416 commented May 8, 2017

@lscaiw 你的这个问题解决的怎么样。我也遇到相同的问题。全部改造要改太多代码了

@casvie
Copy link
Author

casvie commented May 9, 2017

@van416 未找到什么好方法,按文档改造了,用到的地方进行了全局替换。

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

3 participants