Constraint layout Layout Crashing : All Children of constraint layout should have ids to use constraint set

Saikrishna Rajaraman picture Saikrishna Rajaraman · May 25, 2018 · Viewed 11k times · Source

After updating to com.android.support.constraint:constraint-layout:1.1.0

The constraint layout crashes saying:

All children of constraint layout should have ids to use constraint set

I have set ids to all views even then it's crashing.

java.lang.RuntimeException: All children of ConstraintLayout must have ids to use ConstraintSet at android.support.constraint.ConstraintSet.clone(ConstraintSet.java:687) at com.zoho.notebook.views.SettingsViewNavBar.showNoteSettingsView(SettingsViewNavBar.java:594) at com.zoho.notebook.views.SettingsViewNavBar.onClick(SettingsViewNavBar.java:303)

This problem is only happening with tablet devices.

Answer

hushed_voice picture hushed_voice · Jun 15, 2018

I had the same bug in my code. I had ids for all the views in xml, but I was manually adding a view to the constraint layout(a Tooltip view) with

constraintParent.addView(childView)

and while the dynamically added view is still on the parent if the constraint layout is redrawn (app goes to bg and resumed) this exception was getting triggered.

I fixed it by generating a view id for the dynamic view like this

CustomViewChildView childView = new CustomViewChildView()
childView.setId(View.generateViewId()); 

and then adding it to the constraint layout.