Generate signed bundle errors (Unresolved references) only in release mode

405 Views Asked by At

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:

  1. Deleting the .idea folder
  2. Invalidate cache and restart
  3. Cleaning and rebuilding project
  4. Updating Android Studio to 2021.3.1

Am I missing something here?

1

There are 1 best solutions below

0
Mena On
  • Unresolved reference: repeatOnLifecycle
  • Suspension functions can be called only within coroutine body

To fix these errors when generating a signed bundle in release mode you should add this extra dependency: implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.5.1"

To fix the

  • Unresolved reference: bindingAdapterPosition

You must manually add the recyclerView dependency to gradle:

implementation("androidx.recyclerview:recyclerview:1.2.1")
// For control over item selection of both touch and mouse driven selection
implementation("androidx.recyclerview:recyclerview-selection:1.1.0")

It is weird that these errors does not show up when building app in debug mode.