liangjingkanji/Net

lifecycle版本升级后报错

qwer2y opened this issue · 4 comments

问题描述

lifecycle版本升级到2.8.0之后运行报错,2.7.0没问题
错误信息如下:

java.lang.NoSuchMethodError: No virtual method setTagIfAbsent(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; in class Landroidx/lifecycle/ViewModel; or its super classes (declaration of 'androidx.lifecycle.ViewModel' appears in /data/app/~~7JuOQ-oMpwQg7WmqajuK3A==/com.demo.test-dfkSlRfuBzB5vTH99OiBMg==/base.apk!classes32.dex)
                 	at androidx.lifecycle.ScopeKt.scopeNetLife(Scope.kt:54)
                 	at androidx.lifecycle.ScopeKt.scopeNetLife$default(Scope.kt:49)
                 	at com.haller.traveler.ui.fragment.HomeFragment$createObserver$2.invoke(HomeFragment.kt:190)
                 	at com.haller.traveler.ui.fragment.HomeFragment$createObserver$2.invoke(HomeFragment.kt:77)
                 	at com.drake.brv.PageRefreshLayout.onRefresh(PageRefreshLayout.kt:650)
                 	at com.scwang.smart.refresh.layout.SmartRefreshLayout$2.onAnimationEnd(SmartRefreshLayout.java:1298)
                 	at android.animation.Animator$AnimatorListener.onAnimationEnd(Animator.java:719)
                 	at android.animation.Animator$AnimatorCaller$$ExternalSyntheticLambda1.call(Unknown Source:4)
                 	at android.animation.Animator.callOnList(Animator.java:677)
                 	at android.animation.Animator.notifyListeners(Animator.java:616)
                 	at android.animation.Animator.notifyEndListeners(Animator.java:641)
                 	at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1306)
                 	at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1585)
                 	at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:328)
                 	at android.animation.AnimationHandler.-$$Nest$mdoAnimationFrame(Unknown Source:0)
                 	at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:86)
                 	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1550)
                 	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1561)
                 	at android.view.Choreographer.doCallbacks(Choreographer.java:1117)
                 	at android.view.Choreographer.doFrame(Choreographer.java:992)
                 	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1535)
                 	at android.os.Handler.handleCallback(Handler.java:958)
                 	at android.os.Handler.dispatchMessage(Handler.java:99)
                 	at android.os.Looper.loopOnce(Looper.java:257)
                 	at android.os.Looper.loop(Looper.java:368)
                 	at android.app.ActivityThread.main(ActivityThread.java:8826)
                 	at java.lang.reflect.Method.invoke(Native Method)
                 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:572)
                 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)

期望行为

如何复现

fork仓库并复现问题可以快速解决, 猜测只会让问题晦涩难懂, 耽误所有人时间

截图

异常堆栈信息或者手机截图/视频(拖拽到输入框即可上传)

版本

  • Net: 3.6.4
  • OkHttp: 4.12.0
  • Android: 14
  • Gradle: 8.3.2
  • Android Studio: Jellyfish 2023.3.1

你fork仓库复现问题吧, demo里面并没有单独引入此库

看问题是为了适配ViewModel, Net使用了内部函数(非反射), 但是新版本好像删除了该方法

确实我发现是我单独引入了lifecycle一系列库的原因,demo中只使用了androidx.appcompat:appcompat库。现在demo中的appcompat库版本是1.3.1,对应的lifecycle版本是2.3.1,将appcompat升级到最新的1.6.1后对应的版本是2.5.1。

lifecycle库在2.8.0使用kotlin重写了并且删除了setTagIfAbsent()方法,报错在Scope文件里的三个扩展方法,估计以后应该还是得适配

https://developer.android.com/jetpack/androidx/releases/lifecycle?hl=zh-cn#2.8.0
https://issuetracker.google.com/issues/322407038

别关闭啊,lifecycle总要升级的,升级后就报错了,以后还是得适配呢。。。。