Getting error says - “Entry name 'res/layout/test_toolbar.xml' collided” while creating signed apk

后端 未结 20 1964
深忆病人
深忆病人 2020-12-29 17:27

I have updated my android studio from 3.5.x to 3.6 today and getting error while generating signed apk for build variant showing the follow

20条回答
  •  失恋的感觉
    2020-12-29 18:07

    It happen when you used auto viewBinding, Binding using Kotlin or viewBinding feature of 3.6.

    In case, you are adding files whose element share same id's, ViewBinding confuse and create such error.

    Let me help you by example Adapter class which have two layout file separating by view Type :

    import kotlinx.android.synthetic.main.frag_subscription_recommend.view.*
    
    
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
       return ViewHolder(
            LayoutInflater.from(parent.context).inflate(
                if (viewType == 1) {
                    R.layout.frag_subscription_recommend
                } else
                    R.layout.frag_subscription_common,
                parent,
                false
            )
        )
    }
    
    onBinding(){
      holder.itemView.id_button_submit.setOnClickListener {}
    }
    

    // which in case confusing which resource or layout full fill the requirement bcoz both have same ids of button. in case you have to use :

     onBinding(){
      holder.itemView.findViewById

    which enable the old implementation.

    Let me know if this working on your side?

提交回复
热议问题