I tried to use ViewDebug.startHierarchyTracing method but it just do nothing since it checks ViewDebug.TRACE_HIERARCHY and returns immediately if it is false.
Actually this is expected behavior according to JavaDoc:
This method will return immediately if TRACE_HIERARCHY is false.
The problem is that TRACE_HIERARCHY is declared in the source as a boolean constant with a value of false:
/**
* Enables or disables view hierarchy tracing. Any invoker of
* {@link #trace(View, android.view.ViewDebug.HierarchyTraceType)} should first
* check that this value is set to true as not to affect performance.
*/
public static final boolean TRACE_HIERARCHY = false;
There are also startRecyclerTracing, startMotionEventTracing (hidden from public API) methods that depends on TRACE_RECYCLER and TRACE_MOTION_EVENTS constants respectively (which are also set to false).
So I wonder whether it is possible to use ViewDebug class at all or it is intended to be used in custom Android builds only? And if so are there such custom (debug?) builds for Emulator available?
Based on this Dianne Hackborn comment I can assume
ViewDebugis useful only in custom Android builds (with modified values of ViewDebug constants). It seems however that no prebuilt system images with enabled ViewDebug functionality is available for the emulator.