I finalized my app and it ran successfully in debug mode without any errors. I also tried to generate signed apk/abb in debug mode, and all went well.
Now, my issue is that whenever I try to generate a signed apk/abb in release mode I get the following errors during the build process:
- Unresolved reference: repeatOnLifecycle
- Unresolved reference: bindingAdapterPosition
- Suspension functions can be called only within coroutine body
An example of how I use bindingAdapterPosition:
class UserFixedIssueViewHolder(
private val binding: ItemIssueFixedBinding,
private val onReopenClicked: (issueIndex: Int) -> Unit
) :
RecyclerView.ViewHolder(binding.root) {
fun bind(issue: UserIssue) {
binding.apply {
reOpenBtn.setOnClickListener {
onReopenClicked(bindingAdapterPosition)
}
}
}
}
An example of how I use repeatOnLifeCycle:
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.CREATED) {
launch {
viewModel.myStateFlow.collect {
//do something
}
}
}
}
The errors Suspension functions can be called only within coroutine body point to the .collect
line above.
I tried the following with no success:
- Deleting the .idea folder
- Invalidate cache and restart
- Cleaning and rebuilding project
- Updating Android Studio to 2021.3.1
Am I missing something here?
To fix these errors when generating a signed bundle in
release modeyou should add this extra dependency:implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.5.1"To fix the
You must manually add the recyclerView dependency to gradle:
It is weird that these errors does not show up when building app in debug mode.