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 tha
I am using Android Studio 2.3.3. The conclusion is at the end of this post.
Notation: Monitor = Android Device Monitor Studio = Android Studio
In the Android Studio’s preference -> (Build, Execution, Deployment) -> Instant Run -> uncheck Instant Run. Otherwise, it will prompt error message “Application Installation Failed”, and I tried several ways without unchecking Instant Run, but none of them works. So just Uncheck Instant Run for now.
(i) If it’s production build(Run ‘app’):
(1) If I put a check mark on “Enable ADB Integration” option from the drop down menu from “Tools”:
(a) Opening Monitor directly from Studio would work and the view Hierarchy would show in the Monitor, but it will prompt a message “Disable ADB Integration Following debug sessions will be closed:app”(it says “debug session”, though I am using production build). Notice After I close the Monitor, the “Enable ADB Integration” option will be automatically checked again by Studio.
(b) Opening Monitor from Bash will prompt error message saying “ddms, could not open selected VM debug port(870)”, but simply manually unchecking the “Enable ADB Integration” option will fix the problem and the View Hierarchy will show.
(2) If I didn’t put a check mark on “Enable ADB Integration” option: Opening Monitor directly from Studio and from Bash both work, no additional operations needed.
(ii) If it’s debug build: I have to enable ADB Integration in order to launching debugging, so “Enable ADB Integration” option will be checked. After Studio installed the app in my phone: Then the behavior is exactly the same in the section (i)-(1). In other words, for View Hierarchy purpose, launching debug build is the same as launching production build with “Enable ADB Integration” option checked.
In conclusion: To install the app, “Instant Run” need to be unchecked(see instruction in the top of the report). To show View Hierarchy in Monitor, “Enable ADB Integration” need to be unchecked. Opening Monitor from bash and from Studio both work. Debug Build and production build both work.
I had the same problem and finally found an answer at http://developer.android.com/tools/performance/hierarchy-viewer/setup.html. There is an environmental variable that needs to be set in your development environment before the ViewServer will connect.
Hierarchy viewer worked for me once I selected Tools-->Android-->Enable ADB Integration within Android Studio.
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
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
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.