liangjingkanji / Net

Android 基于协程/OkHttp网络请求工具
http://liangjingkanji.github.io/Net/
MIT License
1.91k stars 214 forks source link

viewModel中使用出现错误 #241

Closed AdminQQZ closed 3 months ago

AdminQQZ commented 3 months ago

问题描述

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/~~0D3zDOgCAlrM3kfTdg3qpw==/com.app.gw.debug-Cy-fyEVYzI7k-6MlWUnl5g==/base.apk!classes24.dex) at androidx.lifecycle.ScopeKt.scopeNetLife(Scope.kt:54) at androidx.lifecycle.ScopeKt.scopeNetLife$default(Scope.kt:49) at com.app.gw.feature.main.pages.discovery.DiscoveryViewModel.fetchUserInfo(DiscoveryViewModel.kt:30) at com.app.gw.feature.main.pages.discovery.DiscoveryViewModel.getIndexData(DiscoveryViewModel.kt:77) at com.app.gw.feature.main.pages.discovery.DiscoveryViewModel.(DiscoveryViewModel.kt:42) at com.app.gw.DaggerGWApplication_HiltComponents_SingletonC$ViewModelCImpl$SwitchingProvider.get(DaggerGWApplication_HiltComponents_SingletonC.java:550) at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory$2.createViewModel(HiltViewModelFactory.java:133) at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory$2.create(HiltViewModelFactory.java:104) at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory.create(HiltViewModelFactory.java:171) at androidx.lifecycle.ViewModelProvider$Factory.create(ViewModelProvider.android.kt:158) at androidx.lifecycle.viewmodel.ViewModelProviderImpl_androidKt.createViewModel(ViewModelProviderImpl.android.kt:34) at androidx.lifecycle.viewmodel.ViewModelProviderImpl.getViewModel$lifecycle_viewmodel_release(ViewModelProviderImpl.kt:65) at androidx.lifecycle.viewmodel.ViewModelProviderImpl.getViewModel$lifecycle_viewmodel_release$default(ViewModelProviderImpl.kt:47) at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.android.kt:91) at androidx.lifecycle.viewmodel.compose.ViewModelKtViewModelKt.get(ViewModel.kt:162) at androidx.lifecycle.viewmodel.compose.ViewModelKt.get(Unknown Source:1) at androidx.lifecycle.viewmodel.compose.ViewModelKtViewModel_androidKt.viewModel(ViewModel.android.kt:124) at androidx.lifecycle.viewmodel.compose.ViewModelKt.viewModel(Unknown Source:1) at com.app.gw.feature.main.pages.discovery.DiscoveryRouterKt.DiscoveryRouter(DiscoveryRouter.kt:547) at com.app.gw.feature.main.MainRouterKt$MainScreen$4$1.invoke(MainRouter.kt:85) at com.app.gw.feature.main.MainRouterKt$MainScreen$4$1.invoke(MainRouter.kt:82) at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:139) at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35) at androidx.compose.foundation.pager.PagerLazyLayoutItemProvider$Item$1.invoke(LazyLayoutPager.kt:199) at androidx.compose.foundation.pager.PagerLazyLayoutItemProvider$Item$1.invoke(LazyLayoutPager.kt:197) at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109) at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35) at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:248) at androidx.compose.foundation.lazy.layout.LazyLayoutPinnableItemKt.LazyLayoutPinnableItem(LazyLayoutPinnableItem.kt:58) at androidx.compose.foundation.pager.PagerLazyLayoutItemProvider.Item(LazyLayoutPager.kt:197) at androidx.compose.foundation.lazy.layout.LazyLayoutItemContentFactoryKt$SkippableItem$1.invoke(LazyLayoutItemContentFactory.kt:135) at androidx.compose.foundation.lazy.layout.LazyLayoutItemContentFactoryKt$SkippableItem$1.invoke(LazyLayoutItemContentFactory.kt:134) at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109) at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)

期望行为

如何复现

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

截图

image

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

版本

liangjingkanji commented 3 months ago

v3.7.0已经支持appcompat-v1.7, 但是一旦升级就不支持appcompat-v1.6了

由于无法实现兼容新旧版本, 只能发布v3.7.0了

感谢 @gangoogle 的代码分享