tinker icon indicating copy to clipboard operation
tinker copied to clipboard

热修复后,调用Application类中的public方法会crash

Open wbq888 opened this issue 4 months ago • 0 comments

class Application : TinkerApplication("com.xxx.xxx.ApplicationLike"){
    fun printLog() {
        Log.d("Application", "Application")
    }
}

外部调用Application 方法:

(application as Application).printLog()

全量的两个apk包都不会有问题,但是补丁包加载后,这里会crash FATAL EXCEPTION: main Process: com.xxx.sample.hotfix, PID: 27752 java.lang.ClassCastException: com.xxx.sample.hotfix.app.Application cannot be cast to com.xxx.sample.hotfix.app.Application

按照Tinker 自定义扩展,Application逻辑如果移到代理类是为了避免补丁包是无法对Application和其引用类修改。所以想了解:

  1. 如果我不想热更新Application,怎么可以不crash
  2. 这个为什么会不能将自己类转换为自己(怀疑和classloder有关)

wbq888 avatar Aug 28 '25 13:08 wbq888