wlan0 UP 10.129.160.99/20 0x00001043 f8:a9:d0:17:42:4d lo UP 127.0.0.1/8 0x00000049 00:00:00:00:00:00 p2p0 UP 0.0.0.0/0 0x00001003 fa:a9:d0:17:42:4d sit0 DOWN 0.0.0.0/0 0x00000080 00:00:00:00:00:00 rmnet0 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00 rmnet1 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00 rmnet3 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00 rmnet2 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00 rmnet4 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00 rmnet6 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00 rmnet5 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00 rmnet7 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00 rev_rmnet3 DOWN 0.0.0.0/0 0x00001002 4e:b7:e4:2e:17:58 rev_rmnet2 DOWN 0.0.0.0/0 0x00001002 4e:f0:c8:bf:7a:cf rev_rmnet4 DOWN 0.0.0.0/0 0x00001002 a6:c0:3b:6b:c4:1f rev_rmnet6 DOWN 0.0.0.0/0 0x00001002 66:bb:5d:64:2e:e9 rev_rmnet5 DOWN 0.0.0.0/0 0x00001002 0e:1b:eb:b9:23:a0 rev_rmnet7 DOWN 0.0.0.0/0 0x00001002 7a:d9:f6:81:40:5a rev_rmnet8 DOWN 0.0.0.0/0 0x00001002 4e:e2:a9:bb:d0:1b rev_rmnet0 DOWN 0.0.0.0/0 0x00001002 fe:65:d0:ca:82:a9 rev_rmnet1 DOWN 0.0.0.0/0 0x00001002 da:d8:e8:4f:2e:fe
可以看到网络连接名称、启用状态、IP 地址和 Mac 地址等信息。
Mac 地址
命令:
adb shell cat /sys/class/net/wlan0/address
输出示例:
f8:a9:d0:17:42:4d
这查看的是局域网 Mac 地址,移动网络或其它连接的信息可以通过前面的小节「IP 地址」里提到的 adb shell netcfg 命令来查看。
Features : swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt CPU implementer : 0x51 CPU architecture: 7 CPU variant : 0x2 CPU part : 0x06f CPU revision : 0
error: protocol fault (couldn't read status): No error
可能原因
adb server 进程想使用的 5037 端口被占用。
解决方案
找到占用 5037 端口的进程,然后终止它。以 Windows 下为例:
netstat -ano | findstr LISTENING
... TCP 0.0.0.0:5037 0.0.0.0:0 LISTENING 1548 ...
这里 1548 即为进程 ID,用命令结束该进程:
taskkill /PID 1548
然后再启动 adb 就没问题了。
com.android.ddmlib.AdbCommandRejectedException
在 Android Studio 里新建一个模拟器,但是用 adb 一直连接不上,提示:
com.android.ddmlib.AdbCommandRejectedException: device unauthorized. This adb server's $ADB_VENDOR_KEYS is not set Try 'adb kill-server' if that seems wrong. Otherwise check for a confirmation dialog on your device.
在手机上安装一个终端然后执行 su 提示没有该命令,这不正常。
于是删除该模拟器后重新下载安装一次,这次就正常了。
adb 的非官方实现
fb-adb - A better shell for Android devices (for Mac).
相关命令
aapt相关命令
Android Asset Packaging Tool
Usage: aapt l[ist] [-v] [-a] file.{zip,jar,apk} List contents of Zip-compatible archive.
aapt d[ump] [--values] [--include-meta-data] WHAT file.{apk} [asset [asset ...]] strings Print the contents of the resource table string pool in the APK. badging Print the label and icon for the app declared in APK. permissions Print the permissions from the APK. resources Print the resource table from the APK. configurations Print the configurations in the APK. xmltree Print the compiled xmls in the given assets. xmlstrings Print the strings of the given compiled xml assets.
Package the android resources. It will read assets and resources that are supplied with the -M -A -S or raw-files-dir arguments. The -J -P -F and -R options control which files are output.
aapt c[runch] [-v] -S resource-sources ... -C output-folder ... Do PNG preprocessing on one or several resource folders and store the results in the output folder.
aapt s[ingleCrunch] [-v] -i input-file -o outputfile Do PNG preprocessing on a single file.
aapt v[ersion] Print program version.
Modifiers: -a print Android-specific data (resources, manifest) when listing -c specify which configurations to include. The default is all configurations. The value of the parameter should be a comma separated list of configuration values. Locales should be specified as either a language or language-region pair. Some examples: en port,en port,land,en_US -d one or more device assets to include, separated by commas -f force overwrite of existing files -g specify a pixel tolerance to force images to grayscale, default 0 -j specify a jar or zip file containing classes to include -k junk path of file(s) added -m make package directories under location specified by -J -u update existing packages (add new, replace older, remove deleted files) -v verbose output -x create extending (non-application) resource IDs -z require localization of resource attributes marked with localization="suggested" -A additional directory inwhich to find raw asset files -G A file to output proguard options into. -D A file to output proguard options for the main dex into. -F specify the apk file to output -I add an existing package to base include set -J specify where to output R.java resource constant definitions -M specify full path to AndroidManifest.xml to include in zip -P specify where to output public resource definitions -S directory inwhich to find resources. Multiple directories will be scanned and the first match found (left to right) will take precedence. -0 specifies an additional extension forwhich such files will not be stored compressed in the .apk. An empty string means to not compress any files at all. --debug-mode inserts android:debuggable="true"in to the application node of the manifest, making the application debuggable even on production devices. --include-meta-data when used with "dump badging" also includes meta-data tags. --pseudo-localize generate resources for pseudo-locales (en-XA and ar-XB). --min-sdk-version inserts android:minSdkVersion in to manifest. If the version is 7 or higher, the default encoding for resources will be in UTF-8. --target-sdk-version inserts android:targetSdkVersion in to manifest. --max-res-version ignores versioned resource directories above the given value. --values when used with "dump resources" also includes resource values. --version-code inserts android:versionCode in to manifest. --version-name inserts android:versionName in to manifest. --replace-version If --version-code and/or --version-name are specified, these values will replace any value already in the manifest. By default, nothing is changed if the manifest already defines these attributes. --custom-package generates R.java into a different package. --extra-packages generate R.java for libraries. Separate libraries with ':'. --generate-dependencies generate dependency files in the same directories for R.java and resource package --auto-add-overlay Automatically add resources that are only in overlays. --preferred-density Specifies a preference for a particular density. Resources that do not match this density and have variants that are a closer match are removed. --split Builds a separate split APK for the configurations listed. This can be loaded alongside the base APK at runtime. --feature-of Builds a split APK that is a feature of the apk specified here. Resources in the base APK can be referenced from the the feature APK. --feature-after An app can have multiple Feature Split APKs which must be totally ordered. If --feature-of is specified, this flag specifies which Feature Split APK comes before this one. The first Feature Split APK should not define anything here. --rename-manifest-package Rewrite the manifest so that its package name is the package name given here. Relative class names (for example .Foo) will be changed to absolute names with the old package so that the code does not need to change. --rename-instrumentation-target-package Rewrite the manifest so that all of its instrumentation components target the given package. Useful when used in conjunction with --rename-manifest-package to fix tests against a package that has been renamed. --product Specifies which variant to choose for strings that have product variants --utf16 changes default encoding for resources to UTF-16. Only useful when API level is set to 7 or higher where the default encoding is UTF-8. --non-constant-id Make the resources ID non constant. This is required to make an R java class that does not contain the final value but is used to make reusable compiled libraries that need to access resources. --shared-lib Make a shared library resource package that can be loaded by an application at runtime to access the libraries resources. Implies --non-constant-id. --app-as-shared-lib Make an app resource package that also can be loaded as shared library at runtime. Implies --non-constant-id. --error-on-failed-insert Forces aapt to return an error if it fails to insert values into the manifest with --debug-mode, --min-sdk-version, --target-sdk-version --version-code and --version-name. Insertion typically fails if the manifest already defines the attribute. --error-on-missing-config-entry Forces aapt to return an error if it fails to find an entry for a configuration. --output-text-symbols Generates a text file containing the resource symbols of the R class in the specified folder. --ignore-assets Assets to be ignored. Default pattern is: !.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~ --skip-symbols-without-default-localization Prevents symbols from being generated for strings that do not have a default localization --no-version-vectors Do not automatically generate versioned copies of vector XML resources. --no-version-transitions Do not automatically generate versioned copies of transition XML resources. --private-symbols Java package name to use when generating R.java for private resources.
am相关命令
usage: am [subcommand] [options] usage: am start [-D] [-W] [-P <FILE>] [--start-profiler <FILE>] [--sampling INTERVAL] [-R COUNT] [-S] [--opengl-trace] [--user <USER_ID> | current] <INTENT> am startservice [--user <USER_ID> | current] <INTENT> am stopservice [--user <USER_ID> | current] <INTENT> am force-stop [--user <USER_ID> | all | current] <PACKAGE> am kill [--user <USER_ID> | all | current] <PACKAGE> am kill-all am broadcast [--user <USER_ID> | all | current] <INTENT> am instrument [-r] [-e <NAME> <VALUE>] [-p <FILE>] [-w] [--user <USER_ID> | current] [--no-window-animation] [--abi <ABI>] <COMPONENT> am profile start [--user <USER_ID> current] [--sampling INTERVAL] <PROCESS> <FILE> am profile stop [--user <USER_ID> current] [<PROCESS>] am dumpheap [--user <USER_ID> current] [-n] <PROCESS> <FILE> am set-debug-app [-w] [--persistent] <PACKAGE> am clear-debug-app am set-watch-heap <PROCESS> <MEM-LIMIT> am clear-watch-heap am monitor [--gdb <port>] am hang [--allow-restart] am restart am idle-maintenance am screen-compat [on|off] <PACKAGE> am package-importance <PACKAGE> am to-uri [INTENT] am to-intent-uri [INTENT] am to-app-uri [INTENT] am switch-user <USER_ID> am start-user <USER_ID> am stop-user [-w] <USER_ID> am stack start <DISPLAY_ID> <INTENT> am stack movetask <TASK_ID> <STACK_ID> [true|false] am stack resize <STACK_ID> <LEFT,TOP,RIGHT,BOTTOM> am stack split <STACK_ID> <v|h> [INTENT] am stack list am stack info <STACK_ID> am task lock <TASK_ID> am task lock stop am task resizeable <TASK_ID> [true|false] am task resize <TASK_ID> <LEFT,TOP,RIGHT,BOTTOM> am get-config am set-inactive [--user <USER_ID>] <PACKAGE> true|false am get-inactive [--user <USER_ID>] <PACKAGE> am send-trim-memory [--user <USER_ID>] <PROCESS> [HIDDEN|RUNNING_MODERATE|BACKGROUND|RUNNING_LOW|MODERATE|RUNNING_CRITICAL|COMPLETE]
am start: start an Activity. Options are: -D: enable debugging -W: waitfor launch to complete --start-profiler <FILE>: start profiler and send results to <FILE> --sampling INTERVAL: use sample profiling with INTERVAL microseconds between samples (use with --start-profiler) -P <FILE>: like above, but profiling stops when app goes idle -R: repeat the activity launch <COUNT> times. Prior to each repeat, the top activity will be finished. -S: force stop the target app before starting the activity --opengl-trace: enable tracing of OpenGL functions --user <USER_ID> | current: Specify which user to run as; if not specified then run as the current user.
am startservice: start a Service. Options are: --user <USER_ID> | current: Specify which user to run as; if not specified then run as the current user.
am stopservice: stop a Service. Options are: --user <USER_ID> | current: Specify which user to run as; if not specified then run as the current user.
am force-stop: force stop everything associated with <PACKAGE>. --user <USER_ID> | all | current: Specify user to force stop; all usersif not specified.
am kill: Kill all processes associated with <PACKAGE>. Only kills. processes that are safe to kill -- that is, will not impact the user experience. --user <USER_ID> | all | current: Specify user whose processes to kill; all usersif not specified.
am kill-all: Kill all background processes.
am broadcast: send a broadcast Intent. Options are: --user <USER_ID> | all | current: Specify which user to send to; if not specified then send to all users. --receiver-permission <PERMISSION>: Require receiver to hold permission.
am instrument: start an Instrumentation. Typically this target <COMPONENT> is the form <TEST_PACKAGE>/<RUNNER_CLASS>. Options are: -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT). Use with [-e perf true] to generate raw output for performance measurements. -e <NAME> <VALUE>: set argument <NAME> to <VALUE>. For test runners a common form is [-e <testrunner_flag> <value>[,<value>...]]. -p <FILE>: write profiling data to <FILE> -w: waitfor instrumentation to finish before returning. Required for test runners. --user <USER_ID> | current: Specify user instrumentation runs in; current user if not specified. --no-window-animation: turn off window animations while running. --abi <ABI>: Launch the instrumented process with the selected ABI. This assumes that the process supports the selected ABI.
am profile: start and stop profiler on a process. The given <PROCESS> argument may be either a process name or pid. Options are: --user <USER_ID> | current: When supplying a process name, specify user of process to profile; uses current user if not specified.
am dumpheap: dump the heap of a process. The given <PROCESS> argument may be either a process name or pid. Options are: -n: dump native heap instead of managed heap --user <USER_ID> | current: When supplying a process name, specify user of process to dump; uses current user if not specified.
am set-debug-app: set application <PACKAGE> to debug. Options are: -w: waitfor debugger when application starts --persistent: retain this value
am clear-debug-app: clear the previously set-debug-app.
am set-watch-heap: start monitoring pss size of <PROCESS>, if it is at or above <HEAP-LIMIT> then a heap dump is collected for the user to report
am clear-watch-heap: clear the previously set-watch-heap.
am bug-report: request bug report generation; will launch UI when done to selectwhere it should be delivered.
am monitor: start monitoring for crashes or ANRs. --gdb: start gdbserv on the given port at crash/ANR
am hang: hang the system. --allow-restart: allow watchdog to perform normal system restart
am restart: restart the user-space system.
am idle-maintenance: perform idle maintenance now.
am screen-compat: control screen compatibility mode of <PACKAGE>.
am package-importance: print current importance of <PACKAGE>.
am to-uri: print the given Intent specification as a URI.
am to-intent-uri: print the given Intent specification as an intent: URI.
am to-app-uri: print the given Intent specification as an android-app: URI.
am switch-user: switch to put USER_ID in the foreground, starting execution of that user if it is currently stopped.
am start-user: start USER_ID in background if it is currently stopped, use switch-user if you want to start the user in foreground.
am stop-user: stop execution of USER_ID, not allowing it to run any code until a later explicit start or switch to it. -w: waitfor stop-user to complete.
am stack start: start a new activity on <DISPLAY_ID> using <INTENT>.
am stack movetask: move <TASK_ID> from its current stack to the top (true) or bottom (false) of <STACK_ID>.
am stack resize: change <STACK_ID> size and position to <LEFT,TOP,RIGHT,BOTTOM>.
am stack split: split <STACK_ID> into 2 stacks <v>ertically or <h>orizontally starting the new stack with [INTENT] if specified. If [INTENT] isn't specified and the current stack has more than one task, then the top task of the current task will be moved to the new stack. Command will also force all current tasks in both stacks to be resizeable. am stack list: list all of the activity stacks and their sizes. am stack info: display the information about activity stack <STACK_ID>. am task lock: bring <TASK_ID> to the front and don't allow other tasks to run.
am task lock stop: end the current task lock.
am task resizeable: change if <TASK_ID> is resizeable (true) or not (false).
am task resize: makes sure <TASK_ID> is in a stack with the specified bounds. Forces the task to be resizeable and creates a stack if no existing stack has the specified bounds.
am get-config: retrieve the configuration and any recent configurations of the device.
am set-inactive: sets the inactive state of an app.
am get-inactive: returns the inactive state of an app.
am send-trim-memory: Send a memory trim event to a <PROCESS>.
<INTENT> specifications include these flags and arguments: [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>] [-c <CATEGORY> [-c <CATEGORY>] ...] [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...] [--esn <EXTRA_KEY> ...] [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...] [--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...] [--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...] [--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE> ...] [--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...] [--ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>] [--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]] (mutiple extras passed as Integer[]) [--eial <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]] (mutiple extras passed as List<Integer>) [--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]] (mutiple extras passed as Long[]) [--elal <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]] (mutiple extras passed as List<Long>) [--efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]] (mutiple extras passed as Float[]) [--efal <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]] (mutiple extras passed as List<Float>) [--esa <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]] (mutiple extras passed as String[]; to embed a comma into a string, escape it using "\,") [--esal <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]] (mutiple extras passed as List<String>; to embed a comma into a string, escape it using "\,") [--grant-read-uri-permission] [--grant-write-uri-permission] [--grant-persistable-uri-permission] [--grant-prefix-uri-permission] [--debug-log-resolution] [--exclude-stopped-packages] [--include-stopped-packages] [--activity-brought-to-front] [--activity-clear-top] [--activity-clear-when-task-reset] [--activity-exclude-from-recents] [--activity-launched-from-history] [--activity-multiple-task] [--activity-no-animation] [--activity-no-history] [--activity-no-user-action] [--activity-previous-is-top] [--activity-reorder-to-front] [--activity-reset-task-if-needed] [--activity-single-top] [--activity-clear-task] [--activity-task-on-home] [--receiver-registered-only] [--receiver-replace-pending] [--selector] [<URI> | <PACKAGE> | <COMPONENT>]
pm list packages: prints all packages, optionally only those whose package name contains the text in FILTER. Options: -f: see their associated file. -d: filter to only show disbled packages. -e: filter to only show enabled packages. -s: filter to only show system packages. -3: filter to only show third party packages. -i: see the installer for the packages. -u: also include uninstalled packages.
pm list permission-groups: prints all known permission groups.
pm list permissions: prints all known permissions, optionally only those in GROUP. Options: -g: organize by group. -f: print all information. -s: short summary. -d: only list dangerous permissions. -u: list only the permissions users will see.
pm list instrumentation: use to list all test packages; optionally supply <TARGET-PACKAGE> to list the test packages for a particular application. Options: -f: list the .apk file for the test package.
pm list features: prints all features of the system.
pm list users: prints all users on the system.
pm path: print the path to the .apk of the given PACKAGE.
pm dump: print system state associated with the given PACKAGE.
pm install: install a single legacy package pm install-create: create an install session -l: forward lock application -r: replace existing application -t: allow test packages -i: specify the installer package name -s: install application on sdcard -f: install application on internal flash -d: allow version code downgrade -p: partial application install -g: grant all runtime permissions -S: size in bytes of entire session
pm install-write: write a package into existing session; path may be '-' to read from stdin -S: size in bytes of package, required for stdin
pm uninstall: removes a package from the system. Options: -k: keep the data and cache directories around after package removal.
pm clear: deletes all data associated with a package.
pm enable, disable, disable-user, disable-until-used: these commands change the enabled state of a given package or component (written as "package/class").
pm grant, revoke: these commands either grant or revoke permissions to apps. The permissions must be declared as used in the app's manifest, be runtime permissions (protection level dangerous), and the app targeting SDK greater than Lollipop MR1. pm reset-permissions: revert all runtime permissions to their default state. pm get-install-location: returns the current install location. 0 [auto]: Let system decide the best location 1 [internal]: Install on internal device storage 2 [external]: Install on external media pm set-install-location: changes the default install location. NOTE: this is only intended for debugging; using this can cause applications to break and other undersireable behavior. 0 [auto]: Let system decide the best location 1 [internal]: Install on internal device storage 2 [external]: Install on external media pm trim-caches: trim cache files to reach the given free space. pm create-user: create a new user with the given USER_NAME, printing the new user identifier of the user. pm remove-user: remove the user with the given USER_IDENTIFIER, deleting all data associated with that user