Skip to content

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

Closed
@casvie

Description

@casvie

异常类型: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方式的代码,全部调换的话太不方便。
请问有方法解决这个问题么?

Activity

shwenzhang

shwenzhang commented on Apr 9, 2017

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

van416 commented on May 8, 2017

@van416

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

casvie

casvie commented on May 9, 2017

@casvie
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @van416@shwenzhang@casvie

        Issue actions

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