Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hierarchy is not working for my device

Tags:

android

when I run hierarchy in terminal. it can show the interface of it, but can not connect to my device.And it can connect to virtual emulator. It remind me in terminal like that,

  1. Adb rejected forward command for device 172.18...... unknown host service
  2. missing forward port for 172.18.....
  3. unable to get view server protocal version from device 172.18....

How can it show my view structure of my device in the hierarchy viewer. Can anyone help me ?or anyone who knows where to find the knowledge of the hierarchy. thanks in advance.

like image 787
zyunchen Avatar asked Oct 18 '11 01:10

zyunchen


3 Answers

HierarchyViewer doesn't work on production builds for security reasons. I wrote an API that lets you use HierarchyViewer on any device with your app: https://github.com/romainguy/ViewServer

like image 126
Romain Guy Avatar answered Nov 03 '22 14:11

Romain Guy


For anyone working with Android 4.1 or later: you can get Hierarchy Viewer working by setting the environment variable ANDROID_HVPROTO to ddm.

Mac OSX/Android Studio users, remember to start hierarchy viewer from command line so it will pick up the environment variable. If you installed it with Android Studio, you can find it in /Users/<user>/Library/Android/sdk/tools

https://developer.android.com/tools/performance/hierarchy-viewer/setup.html

like image 23
waternova Avatar answered Nov 03 '22 14:11

waternova


Romain's ViewServer project (see answer #1) works great for this. I downloaded the code, turned the project into a library project, added a dependency in my app to the new library project, and changed my app's base Activity class to subclass from this simple class:

public class SimpleViewServerActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ViewServer.get(this).addWindow(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ViewServer.get(this).removeWindow(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        ViewServer.get(this).setFocusedWindow(this);
    }
}

Now I can connect from the Android Debug Monitor's Hierarchy View and debug my layout.

like image 19
Scott Leslie Avatar answered Nov 03 '22 15:11

Scott Leslie