小编Abh*_* AN的帖子

R8 完整模式抛出类转换异常 AGP 8.0

我最近升级到 Android Studio Flamingo 和 AGP 8.0

我的生产版本启用了 minfiy 和 ShrinkResources,不允许改造进行调用。这是抛出的错误。

java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
at retrofit2.HttpServiceMethod.parseAnnotations(HttpServiceMethod.java:46)
at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:39)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:202)
at retrofit2.Retrofit$1.invoke(Retrofit.java:160)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy11.checkIfEmailExists(Unknown Source)
at com.iku.data.network.service.IkuApiService$DefaultImpls.checkIfEmailExists$default(IkuApiService.kt:123)
at com.iku.auth.data.network.repository.AuthRepositoryImpl$checkEmail$2.invokeSuspend(AuthRepositoryImpl.kt:24)
at com.iku.auth.data.network.repository.AuthRepositoryImpl$checkEmail$2.invoke(AuthRepositoryImpl.kt:0)
at com.iku.auth.data.network.repository.AuthRepositoryImpl$checkEmail$2.invoke(AuthRepositoryImpl.kt:0)
at com.iku.data.network.helper.NetworkHelperKt$safeApiCall$2.invokeSuspend(NetworkHelper.kt:27)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Run Code Online (Sandbox Code Playgroud)

我在 retorfit 的 github 上发现了这个问题 - https://github.com/square/retrofit/issues/3751。并添加了新规则已在这里评论 - https://github.com/square/retrofit/issues/3751#issuecomment-1192043644

# Keep generic signature of Call, Response (R8 full mode strips signatures from …
Run Code Online (Sandbox Code Playgroud)

android android-studio android-gradle-plugin retrofit moshi

15
推荐指数
1
解决办法
6217
查看次数

快速片段切换视图绑定 null

我在选项卡布局中有 2 个片段,使用 ViewBinding 在它们之间快速切换会导致视图返回为 null。这是因为构建 FragmentXBinding 类的延迟吗?

使用示例:

chatadapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
            @Override
            public void onItemRangeInserted(int positionStart, int itemCount) {
                binding.chatRecyclerView.smoothScrollToPosition(0);
            }
        });
Run Code Online (Sandbox Code Playgroud)

错误:

java.lang.NullPointerException: Attempt to read from field 'androidx.recyclerview.widget.RecyclerView com.iku.databinding.FragmentChatBinding.chatRecyclerView' on a null object reference
Run Code Online (Sandbox Code Playgroud)

data-binding android android-fragments android-viewbinding

11
推荐指数
1
解决办法
4451
查看次数

如何结合 livedata 和 kotlin flow

把最新的collect放在observe里面好不好?

viewModel.fetchUserProfileLocal(PreferencesManager(requireContext()).userName!!)
            .observe(viewLifecycleOwner) {
                if (it != null) {
                    viewLifecycleOwner.lifecycleScope.launch {
                        viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
                            launch {
                                viewModel.referralDetailsResponse.collect { referralResponseState ->
                                    when (referralResponseState) {
                                        State.Empty -> {
                                        }
                                        is State.Failed -> {
                                            Timber.e("${referralResponseState.message}")
                                        }
                                        State.Loading -> {
                                            Timber.i("LOADING")
                                        }
                                        is State.Success<*> -> {
                                            // ACCESS LIVEDATA RESULT HERE??
}}}}
Run Code Online (Sandbox Code Playgroud)

我确信不是,当本地数据库发生变化时,我的 API 也会被调用三次,正确的方法是什么?

我的 ViewModel 看起来像这样,我从本地 Room DB 获取用户信息,推荐详细信息响应是 API 响应

private val _referralDetailsResponse = Channel<State>(Channel.BUFFERED)
val referralDetailsResponse = _referralDetailsResponse.receiveAsFlow()

init {
        val inviteSlug: String? = savedStateHandle["inviteSlug"]
        // Fire invite link
        if (inviteSlug …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-livedata kotlin-coroutines kotlin-flow

3
推荐指数
1
解决办法
2550
查看次数

Kotlin:如何检查对象列表中的字段是否等于另一个对象列表的字段

基本上就是标题。

如果我必须找到我所知道的单一领域

a.any {
    it.name == "user"
}
Run Code Online (Sandbox Code Playgroud)

现在我有一个 listOf(Groups) 其中包含唯一的 ID

我想检查一下

如果 user.groups.anyItemInThisList.UNIQUEID == otheruser.groups.anyItemInThisList.UNIQUEID

我的数据看起来像这样

{
   "groups":[
      {
         "id":4
         "group":"Test Group",
         "role":"creator",
         "member_count":1,
         "userType":"local"
      }
   ]
}
Run Code Online (Sandbox Code Playgroud)

arrays list kotlin

1
推荐指数
1
解决办法
2561
查看次数