Android 为什么hierarchyviewer 不适用于Samsung Galaxy TAB 7.0?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10647300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:29:10  来源:igfitidea点击:

Why is hierarchyviewer not working for Samsung Galaxy TAB 7.0?

androidgalaxy-tab

提问by Harshal Kshatriya

I've used hierarachyviewer earlier, but on android emulator. It works absolutely fine when I use it on the emulator. However it does not work with Samsung Galaxy TAB 7.0, with Android 2.3.4.

我之前使用过 hierarachyviewer,但在 android 模拟器上。当我在模拟器上使用它时,它工作得很好。但是,它不适用于使用 Android 2.3.4 的三星 Galaxy TAB 7.0。

This is the log, that I get

这是我得到的日志

11:04:22 E/hierarchyviewer: Unable to get view server version from device 303599
64881B00EC
11:04:22 E/hierarchyviewer: Unable to get view server protocol version from devi
ce 30359964881B00EC
11:04:24 E/hierarchyviewer: Unable to debug device 30359964881B00EC
11:05:05 E/hierarchyviewer: Unable to get view server version from device 303599
64881B00EC
11:05:05 E/hierarchyviewer: Unable to get view server protocol version from devi
ce 30359964881B00EC
11:05:07 E/hierarchyviewer: Unable to debug device 30359964881B00EC
11:09:38 E/hierarchyviewer: Unable to get view server version from device 303599
64881B00EC
11:09:38 E/hierarchyviewer: Unable to get view server protocol version from devi
ce 30359964881B00EC
11:09:40 E/hierarchyviewer: Unable to debug device 30359964881B00EC

I'm also not using hierarchyviewer in the debug mode, just running the application. Thanks.

我也没有在调试模式下使用hierarchyviewer,只是运行应用程序。谢谢。

采纳答案by neworld

I found a workaround: https://github.com/romainguy/ViewServer

我找到了一个解决方法:https: //github.com/romainguy/ViewServer

ViewServer is a simple class you can use in your Android application to use the HierarchyViewer inspection tool...

If you do need this library then follow these directions:

  • Include the ViewServer library(easy directions found here)
  • Your application must require the INTERNET permission
  • The recommended way to use this API is to register activities when they are created, and to unregister them when they get destroyed:

    public class MyActivity extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // Set content view, etc.
            ViewServer.get(this).addWindow(this);
        }
    
        public void onDestroy() {
            super.onDestroy();
            ViewServer.get(this).removeWindow(this);
        }
    
        public void onResume() {
            super.onResume();
            ViewServer.get(this).setFocusedWindow(this);
        }
    }
    

Please refer to the documentation in ViewServer.java for more info...

ViewServer 是一个简单的类,您可以在 Android 应用程序中使用它来使用 HierarchyViewer 检查工具...

如果您确实需要此库,请按照以下说明操作:

  • 包括 ViewServer 库(在此处找到简单说明)
  • 您的应用程序必须需要 INTERNET 权限
  • 使用此 API 的推荐方法是在创建活动时注册活动,并在活动被销毁时取消注册:

    public class MyActivity extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // Set content view, etc.
            ViewServer.get(this).addWindow(this);
        }
    
        public void onDestroy() {
            super.onDestroy();
            ViewServer.get(this).removeWindow(this);
        }
    
        public void onResume() {
            super.onResume();
            ViewServer.get(this).setFocusedWindow(this);
        }
    }
    

有关更多信息,请参阅 ViewServer.java 中的文档...

回答by RhodanV5500

Use the monitor-tool instead (android-sdk/tools/monitor).

请改用监视器工具 ( android-sdk/tools/monitor)。

Connect to your device. Close Eclipse first if you can't connect.

连接到您的设备。如果无法连接,请先关闭 Eclipse。

Press the "Dump view hierarchy for UI automator" button in the devices-tab. Its the one next to the screen-capture button.

按设备选项卡中的“UI automator 的转储视图层次结构”按钮。它是屏幕捕获按钮旁边的那个。

Works since API Level 16 (Android 4.1).

从 API 级别 16 (Android 4.1) 开始工作。

回答by user1378730

You can only use HierarachyViewer on the emulator and special developer phones bought from google.

您只能在模拟器和从谷歌购买的特殊开发者手机上使用 HierarachyViewer。

http://groups.google.com/group/android-developers/browse_thread/thread/b0b0af7a316ca768

http://groups.google.com/group/android-developers/browse_thread/thread/b0b0af7a316ca768

Quote from above link

从上面的链接引用

HierarchyViewer does not work on user builds (i.e. with devices available in stores.) This is for security reasons. If HiearchyViewer was able to work on user builds, any application on your desktop (or even on the phone in some cases) could potentially get access to private information (like logins and passwords.)

HierarchyViewer 不适用于用户构建(即商店中可用的设备)。这是出于安全原因。如果 HiearchyViewer 能够处理用户构建,那么您桌面上(甚至在某些情况下甚至是手机上)上的任何应用程序都有可能访问私人信息(例如登录名和密码)。

回答by smallsilver

I'm solved question in max os

我在 max os 中解决了问题

this ANDROID_HVPROTO solution is documented here:

此 ANDROID_HVPROTO 解决方案记录在此处:

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

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

then try to close Android Studio

然后尝试关闭 Android Studio

run adb kill-server, adb start-server

运行 adb kill-server, adb start-server

and launch monitor work to me!

并向我启动监控工作!

the answer is :

答案是 :

https://github.com/romainguy/ViewServer/issues/14#issuecomment-75354479

https://github.com/romainguy/ViewServer/issues/14#issuecomment-75354479

@ozodrukh's answer is usefull.

@ozodrukh 的回答很有用。

回答by Srdjan Grubor

Almost no general-production phones will allow the HierarchyViewer to access them. Usually developer phones and emulators are the only ones with those features.

几乎没有一般生产手机会允许 HierarchyViewer 访问它们。通常,开发者手机和模拟器是唯一具有这些功能的手机。

回答by Ronak Poriya

Similar issue i was having on 4.1 Android phone.Use ViewServerin your code.

我在 4.1 Android 手机上遇到了类似的问题。在您的代码中使用ViewServer

Before checking in Hierarchy viewer,Just restart adb server once by doing.

在签入层次结构查看器之前,只需重新启动 adb 服务器一次。

回答by baiiu

the official documentation:Optimizing Your UIsaid so:

官方文档:优化你的用户界面是这么说的:

To preserve security, Hierarchy Viewer can only connect to devices running a developer version of the Android system.

为了保证安全,Hierarchy Viewer 只能连接到运行 Android 系统开发者版本的设备。

回答by mortalis

Profile your layout with Hierarchy Viewer:

使用 Hierarchy Viewer 分析您的布局

Set the environment variable

设置环境变量

ANDROID_HVPROTO=ddm

So from [andrid-sdk]/toolsfolder run this in Command Line:

所以从[andrid-sdk]/tools文件夹在命令行中运行:

set ANDROID_HVPROTO=ddm
hierarchyviewer

Or put set ANDROID_HVPROTO=ddmin the hierarchyviewer.bat.

或放set ANDROID_HVPROTO=ddmhierarchyviewer.bat