Android Debug Monitor层次结构视图未显示 [英] Android Debug Monitor hierarchy view not showing

查看:165
本文介绍了Android Debug Monitor层次结构视图未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在ADM中连接我的应用程序,但不幸的是,没有显示层次结构"视图.我应该如何将我的应用程序连接到ADM工具?

I am trying to connect my App in ADM but unfortunately Hierarchy view is not showing. How should I connect my app to ADM tool?

设备:Nexus 4

Device: Nexus 4

Os:4.3.3

错误:

    [2014-02-06 13:00:14 - hierarchyviewer]Missing forwarded port for 021df5e049116bac
    [2014-02-06 13:00:14 - hierarchyviewer]Unable to get view server version from device     021df5e049116bac
    [2014-02-06 13:00:14 - hierarchyviewer]Missing forwarded port for 021df5e049116bac
    [2014-02-06 13:00:14 - hierarchyviewer]Unable to get view server protocol version from device 021df5e049116bac
    [2014-02-06 13:00:14 - ViewServerDevice]Unable to debug device: lge-nexus_4-021df5e049116bac

推荐答案

请参阅使用层次结构查看器配置布局,以供层次结构查看器使用.

Refer to Profile Your Layout with Hierarchy Viewer for hierarchy viewer usage.

今天,我在应用程序中使用了层次结构查看器,并且在层次化查看器树状视图"窗口为黑色的情况下,在隔离器和真实设备上都遇到了非常相似的问题.

Today I use hierarchy viewer with my app, and I get the very similar issue on both silulator and real device, with hierarch viewer Tree View window black.

注意:对于较新版本的android studio,您可以使用Tools > Android > Android Device Monitor > Window > Open Perspective... > Hierarchy View

Note: For the newer version of android studio, you can open hierarchy viewer with Tools > Android > Android Device Monitor > Window > Open Perspective... > Hierarchy View

下面,我将向您展示如何解决隔离器和真实设备上的问题.

Below I'll show you how to solve the problem on silulator and real device.

信息:设备调试模式已启用,我不测试它是否对以下结果产生影响.

Info: device debug mode is on, I don't test if it has influence on the below result.

a).检查设备是否已打开视图服务器

bogon:~ roofe$ adb shell service call window 3
Result: Parcel(00000000 00000000   '........')

注意:(如果获得)

找不到命令adb

cannot find command adb

adb通常位于sdk的路径中,我的位于/Users/roofe/Library/Android/sdk/platform-tools/adb处.然后,您可以将其添加到路径或为其创建别名.

adb is usually in the path of sdk, mine is at /Users/roofe/Library/Android/sdk/platform-tools/adb. Then you can add it to path or make a alias for it.

我将alias adb='/Users/roofe/Library/Android/sdk/platform-tools/adb'放在用户路径下的.bash_profile中,然后是source ./.bash_profile.这里的adb命令应该可以使用.

I put alias adb='/Users/roofe/Library/Android/sdk/platform-tools/adb' in the .bash_profile under the user path, then source ./.bash_profile. Here adb command should works.

输出信息:

关闭View Server:Result: Parcel(00000000 00000000 '........')

View Server off: Result: Parcel(00000000 00000000 '........')

在以下服务器上查看服务器:Result: Parcel(00000000 00000001 '........')

View Server on: Result: Parcel(00000000 00000001 '........')

如果打开了视图服务器,则层次结构查看器应该运行良好.而且您无需阅读以下内容.

If the view server is on, you hierarchy viewer should works well. And you needn't to read below.

不幸的是,如果您的View服务器已关闭,请继续. 我的模拟器的查看服务器和读取设备都关闭了.

Unfortunately, if your view server is off, go on. Both view server of my simulator and read device are off.

b).启动View服务器

bogon:~ roofe$ adb shell service call window 1 i32 4939
Result: Parcel(00000000 00000001   '........')

如果结果为Result: Parcel(00000000 00000001 '........'),则说明视图服务器已启动.如果结果为Result: Parcel(00000000 00000000 '........'),则无法启动视图服务器.

If the result is Result: Parcel(00000000 00000001 '........'), the view server has been started. While if the result is Result: Parcel(00000000 00000000 '........'), the view server cannot be started.

您还可以使用

adb shell service call window 2 i32 4939

在此执行两次命令以将其关闭,也许这里有执行时间.

Here execute the command two times to shutdown it, maybe there is a execution time here.

bogon:~ roofe$ adb shell service call window 2 i32 4939
Result: Parcel(00000000 00000001   '........')
bogon:~ roofe$ adb shell service call window 2 i32 4939
Result: Parcel(00000000 00000000   '........')

大多数实际设备无法启动视图服务器.为了安全起见,真实设备上的Android对此有所限制.您可以在文件

Most of the real device cannot start the view server. For security, Android on real device have restrict on this. You can find the relative code in file WindowManageService.java source code of Andorid

if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
    return false;
} 

因此,如果您是天才破解者,则可以启动您的设备以消除此限制.我没有做到.如果尝试成功,请告诉我.您的聪明工作将不胜感激.

So if you're a genius cracker, you can root your device to remove this restrict. I've not make it. If your try successfull, show me it. I'll be very appreciated on your smart work.

我的模拟器在这里工作.而真正的设备没有.如果您的View服务器仍然关闭,请继续.

Here my simulator works. While real device not. If your view server is still off, go on.

c).使用ddm协议,这是Android Studio文档doc

c). Using the ddm protocol, one method from the doc of Android studio doc Profile Your Layout with Hierarchy Viewer

如果您使用的是Android模拟器,则可以跳过此部分. 否则,您需要按照以下步骤设置设备.

If you're using the Android Emulator, you can skip this section. Otherwise, you need to set up your device as follows.

注意:您的设备必须运行Android 4.1或更高版本.

Note: Your device must be running Android 4.1 or higher.

在设备上启用开发者选项.

Enable Developer Options on your device.

在开发计算机上设置环境变量ANDROID_HVPROTO = ddm.

Set the environment variable ANDROID_HVPROTO=ddm on your development machine.

此变量告诉Hierarchy Viewer使用ddm协议连接到设备,该协议与DDMS协议相同.这 请注意,主机上只有一个进程可以连接 到设备,因此您必须终止任何其他DDMS会话才能运行 层次结构查看器.

This variable tells Hierarchy Viewer to connect to the device using the ddm protocol, which is the same as the DDMS protocol. The caveat is that there can be only one process on the host that connects to the device, so you must kill any other DDMS session to run Hierarchy Viewer.

export ANDROID_HVPROTO=ddm添加到您的.bash_profile中,然后获取./.bash_profile.

Add export ANDROID_HVPROTO=ddm to your .bash_profile then source ./.bash_profile.

删除已安装的应用程序,然后重新启动Android Studio ,然后安装您的应用程序,您可以立即对其进行层次结构查看.

Remove the installed app, and restart Android Studio, then install your app and you can hierarchy view it now.

注意:我设置了ddm而不重新启动Android Studio a,因此无法分层查看它.一天后,我意识到了这一点,并做了一些测试.我发现设置ppm后,最好重新启动android studio.我想当android studio启动时,它将读取该配置,可以对其进行缓存.

Note: I set the ddm without restart Android Studio a, I cannot hierarchy view it. One day later, I realise it, and do some test. I founds after set the ppm, it's better to restart the android studio. I guess when android studio start it will read that config, can cache it.

在没有卸载应用程序的情况下,我没有对其进行测试.

I didn't test it without uninstall the app.

d).设置视图服务器

请不要在这里感到沮丧.启动视图服务器非常简单.

Please don't fell frustrated here. To start a view server is very easy.

工具: github上的ViewServer

将此添加到您的build.gradle

allprojects {
    repositories {
        jcenter()
        maven {url "https://jitpack.io"}
    }
}
dependencies {  
    ...
    compile 'com.github.romainguy:ViewServer:017c01cd512cac3ec054d9eee05fc48c5a9d2de'  
}  

manifest文件中添加INTERNET权限

<uses-permission android:name="android.permission.INTERNET" />

然后将Viewserver重新分配给您要检查的活动

Then regiester the viewserver to the activity you want to inspect

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);
    }
}

现在,我可以在真实设备上运行层次结构"视图.

By now, I can run the Hierarchy view on my real device.

这篇关于Android Debug Monitor层次结构视图未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆