Aus Umweltgründen kann ich nur die Befehleadb
verwenden.
Gibt es eine Möglichkeit , um die aktuellen Layoutattribute wie id
, position
, text
etc abzurufen?
Ähnlich wieuiautomatorviewer
.
Verwenden Sie den Befehl adb Shell uiautomator dump
:
Usage: uiautomator <subcommand> [options]
Available subcommands:
help: displays help message
runtest: executes UI automation tests
runtest <class spec> [options]
<class spec>: <JARS> < -c <CLASSES> | -e class <CLASSES> >
<JARS>: a list of jar files containing test classes and dependencies. If
the path is relative, it's assumed to be under /data/local/tmp. Use
absolute path if the file is elsewhere. Multiple files can be
specified, separated by space.
<CLASSES>: a list of test class names to run, separated by comma. To
a single method, use TestClass#testMethod format. The -e or -c option
may be repeated. This option is not required and if not provided then
all the tests in provided jars will be run automatically.
options:
--Nohup: trap SIG_HUP, so test won't terminate even if parent process
is terminated, e.g. USB is disconnected.
-e debug [true|false]: wait for debugger to connect before starting.
-e runner [CLASS]: use specified test runner class instead. If
unspecified, framework default runner will be used.
-e <NAME> <VALUE>: other name-value pairs to be passed to test classes.
May be repeated.
-e outputFormat simple | -s: enabled less verbose JUnit style output.
dump: creates an XML dump of current UI hierarchy
dump [--verbose][file]
[--compressed]: dumps compressed layout information.
[file]: the location where the dumped XML should be stored, default is
/storage/emulated/legacy/window_dump.xml
events: prints out accessibility events until terminated
Standardmäßig werden die Ansichten der Hierarchie in $EXTERNAL_STORAGE/window_dump.xml
ausgegeben.
adb Shell uiautomator dump
UI hierchary dumped to: /sdcard/window_dump.xml
Normalerweise möchten Sie diese Datei zur weiteren Verarbeitung auf Ihren PC ziehen, was ein zusätzlicher Schritt wäre. Es gibt jedoch einen ordentlichen Trick, der das Kombinieren von Dumping und Ziehen in einem einzigen Befehl ermöglicht. Bei Verwendung von /dev/tty
als Speicherauszugsziel würde ein einzelner Befehl erstellt, der den gesamten Speicherauszug in die Variable stdout
ausgeben würde:
adb exec-out uiautomator dump /dev/tty
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><hierarchy rotation="0"><node ...></node></hierarchy>UI hierchary dumped to: /dev/tty
Mit AndroidViewClient/culebradump
können Sie genau das tun. AndroidViewClient kann als Bibliothek verwendet werden und bietet auch einige Tools wie dump
und culebra
.
usage: dump [OPTION]... [serialno]
Options:
-H, --help prints this help
-V, --verbose verbose comments
-v, --version
-I, --ignore-secure-device ignore secure device
-E, --ignore-version-check ignores ADB version check
-F, --force-view-server-use force view server use (even if UiAutomator present:w)
-S, --do-not-start-view-server don't start ViewServer
-k, --do-not-ignore-uiautomator-killed don't ignore UiAutomator killed
-w, --window=WINDOW dump WINDOW content (default: -1, all windows)
-a, --all dump all information about Views
-i, --uniqueId dump View unique IDs
-x, --position dump View positions
-b, --bounds dump View bounds
-d, --content-description dump View content descriptions
-g, --tag dump View tags
-c, --center dump View centers
-f, --save-screenshot=FILE save screenshot to file
-W, --save-view-screenshots=DIR save View screenshots to files in directory
-D, --do-not-dump-views don't dump views, only useful if you specified -f or -W
-A, --device-art=MODEL device art model to frame screenshot (auto: autodetected)
-Z, --drop-shadow drop shadow for device art screenshot
-B, --glare screen glare over screenshot
-h, --use-uiautomator-helper use UiAutomatorHelper Android app
-X, --debug=LIST debug options
wenn Sie dump
ohne Optionen ausführen, wird nur der Baum der Ansichten und einige ihrer grundlegenden Eigenschaften wie ID gedruckt
Android.widget.FrameLayout
com.Android.launcher3.Workspace com.google.Android.apps.nexuslauncher:id/workspace
Android.widget.FrameLayout com.google.Android.apps.nexuslauncher:id/workspace_blocked_row
Android.widget.TextView com.google.Android.apps.nexuslauncher:id/date_text1 May 1
Android.widget.TextView com.google.Android.apps.nexuslauncher:id/date_text2 MONDAY, 2017
Android.widget.TextView Maps
Android.widget.ImageView com.google.Android.apps.nexuslauncher:id/g_icon
Android.widget.ImageView com.google.Android.apps.nexuslauncher:id/all_apps_handle
Android.view.ViewGroup com.google.Android.apps.nexuslauncher:id/layout
Android.widget.TextView Messenger
Android.widget.TextView Chrome
auf der anderen Seite können Sie die Positionen der Ansichten ausführen, wenn Sie möchten
$ dump -x
Android.widget.FrameLayout (0, 0, 1440, 2392)
com.Android.launcher3.Workspace com.google.Android.apps.nexuslauncher:id/workspace (0, 0, 1440, 2392)
Android.widget.FrameLayout com.google.Android.apps.nexuslauncher:id/workspace_blocked_row (30, 126, 1380, 372)
Android.widget.TextView com.google.Android.apps.nexuslauncher:id/date_text1 May 1 (1037, 194, 337, 162)
Android.widget.TextView com.google.Android.apps.nexuslauncher:id/date_text2 MONDAY, 2017 (1092, 356, 282, 73)
Android.widget.TextView Maps (30, 1614, 276, 372)
Android.widget.ImageView com.google.Android.apps.nexuslauncher:id/g_icon (30, 214, 276, 196)
Android.widget.ImageView com.google.Android.apps.nexuslauncher:id/all_apps_handle (636, 1986, 168, 98)
Android.view.ViewGroup com.google.Android.apps.nexuslauncher:id/layout (0, 2084, 1440, 308)
Android.widget.TextView Messenger (306, 2112, 276, 280)
Android.widget.TextView Chrome (858, 2112, 276, 280)
Die Optionen geben Ihnen die Kontrolle über die Ausgabe. Weitere Informationen erhalten Sie hier .
adb pull $(adb Shell uiautomator dump | grep -oP '[^ ]+.xml') /tmp/view.xml
Öffnen Sie /tmp/view.xml
in einem Webbrowser wie:
google-chrome /tmp/view.xml
adb exec-out uiautomator dump/dev/tty
von der anderen antwort funktionierte bei mir nicht.
Ich habe auf einem Mac Folgendes verwendet, um formatierte XML-Dateien auf der Konsole zu drucken:
adb Shell uiautomator dump && adb pull /sdcard/window_dump.xml $TMPDIR && more $TMPDIR/window_dump.xml | xmllint --format -
Möglicherweise müssen Sie den Pfad der /sdcard/window_dump.xml
-Datei ändern, um basierend auf dem Speicherort der XML-Datei abzurufen.
Verwenden Sie die folgenden Anweisungen, um das XML-Layout in Notepad oder in Ihrem Standardtexteditor anzuzeigen
adb Shell uiautomator dump && adb pull /sdcard/window_dump.xml && starte window_dump.xml