====== 안드로이드 핵심가이드 - 3.ADB 사용하기 ====== ADB(Android Debug Bridge)에 대한 사용법을 다룬다. ====== ADB 란 ====== 안드로이드 개발을 하면 adb 프로그램을 빼놓을 수 없다. 안드로이드 SDK 에 adb 가 들어있고 path 를 잘 잡아놨다면 adb 실행이 가능하다. 디바이스에 파일을 넣거나 꺼내는 기능, 디바이스 쉘로 들어갈 수 있는 기능, 애플리케이션을 설치 또는 삭제할 수 있는 기능, 로그 메시지를 볼 수 있는 기능을 주고 사용하고 그 외에도 많은 기능들이 들어있다. 전통적인 임베디드 리눅스라면 시리얼 포트로 이러한 역할을 수행했겠지만, 안드로이드에서는 USB 포트를 써서 adb 로 디버깅 및 애플리케이션 인스톨, 파일 전송들을 구현하였다. ====== ADB 설치하기 ====== 설치하는 방법에는 2가지가 있다. - 안드로이드 소스코드로부터 빌드하여 사용하는 방법 - 패키지 바이너리를 사용하는 방법 첫번째 방법은 다른 문서를 참고한다. 두번째 방법은 다른 문서를 참고한다. 우분투의 경우, 다음과 같이 설치할 수 있다. #apt-get install adb ====== ADB 옵션 ====== adb 를 실행하면, 아래와 같이 많은 옵션을 지원하는 것을 알 수 있다. root@ubuntu:~# adb Android Debug Bridge version 1.0.31 -a - directs adb to listen on all interfaces for a connection -d - directs command to the only connected USB device returns an error if more than one USB device is present. -e - directs command to the only running emulator. returns an error if more than one emulator is running. -s - directs command to the device or emulator with the given 다 serial number or qualifier. Overrides ANDROID_SERIAL environment variable. // 디바이스가 여러 개 연결되어 있을 경우 serial number 로 선택할 수 있다 -p - simple product name like 'sooner', or a relative/absolute path to a product out directory like 'out/target/product/sooner'. If -p is not specified, the ANDROID_PRODUCT_OUT environment variable is used, which must be an absolute path. -H - Name of adb server host (default: localhost) -P - Port of adb server (default: 5037) devices [-l] - list all connected devices // 연결된 디바이스들의 목록과 시리얼을 볼 수 있다 ('-l' will also list device qualifiers) connect [:] - connect to a device via TCP/IP // 디바이스에 TCP/IP 로 연결할 수 있다 Port 5555 is used by default if no port number is specified. // 포트번호 5555 는 default 설정이다 disconnect [[:]] - disconnect from a TCP/IP device. Port 5555 is used by default if no port number is specified. Using this command with no additional arguments will disconnect from all connected TCP/IP devices. device commands: adb push - copy file/dir to device // 디바이스에 파일을 넣을 수 있다 adb pull [] - copy file/dir from device // 디바이스에 파일을 꺼낼 수 있다 adb sync [ ] - copy host->device only if changed // 안드로이드를 컴파일하여 자동으로 변경된 파일들을 디바이스에 넣어준다 (-l means list but don't copy) (see 'adb help all') adb shell - run remote shell interactively // 디바이스의 쉘로 들어갈 수 있다 adb shell - run remote shell command // 디바이스에 쉘 명령을 실행할 수 있다 adb emu - run emulator console command adb logcat [ ] - View device log // 로그를 볼 수 있다. 태그나 로그 레벨 등으로 필터링 가능하다 adb forward --list - list all forward socket connections. // adb 를 네트워크로 포워딩 가능하다 the format is a list of lines with the following format: " " " " "\n" adb forward - forward socket connections forward specs are one of: tcp: localabstract: localreserved: localfilesystem: dev: jdwp: (remote only) adb forward --no-rebind - same as 'adb forward ' but fails if is already forwarded adb forward --remove - remove a specific forward socket connection adb forward --remove-all - remove all forward socket connections adb jdwp - list PIDs of processes hosting a JDWP transport adb install [-l] [-r] [-s] [--algo --key --iv ] // apk 파일을 디바이스에 인스톨할 수 있다 - push this package file to the device and install it ('-l' means forward-lock the app) ('-r' means reinstall the app, keeping its data) // -r 옵션을 주면 설치되어 있는 어플을 지우고 다시 설치한다 ('-s' means install on SD card instead of internal storage) // -s 옵션은 SD 카드에 설치한다 ('--algo', '--key', and '--iv' mean the file is encrypted already) adb uninstall [-k] - remove this app package from the device // 디바이스에 설치되어 있는 어플을 삭제한다 ('-k' means keep the data and cache directories) adb bugreport - return all information from the device that should be included in a bug report. adb backup [-f ] [-apk|-noapk] [-shared|-noshared] [-all] [-system|-nosystem] [] - write an archive of the device's data to . If no -f option is supplied then the data is written to "backup.ab" in the current directory. (-apk|-noapk enable/disable backup of the .apks themselves in the archive; the default is noapk.) (-shared|-noshared enable/disable backup of the device's shared storage / SD card contents; the default is noshared.) (-all means to back up all installed applications) (-system|-nosystem toggles whether -all automatically includes system applications; the default is to include system apps) ( is the list of applications to be backed up. If the -all or -shared flags are passed, then the package list is optional. Applications explicitly given on the command line will be included even if -nosystem would ordinarily cause them to be omitted.) adb restore - restore device contents from the backup archive adb help - show this help message adb version - show version num scripting: adb wait-for-device - block until device is online adb start-server - ensure that there is a server running // adb 데몬을 시스템에 띄운다 adb kill-server - kill the server if it is running // 시스템에 떠있는 adb 데몬을 중지시킨다 adb get-state - prints: offline | bootloader | device adb get-serialno - prints: adb get-devpath - prints: adb status-window - continuously print device status for a specified device adb remount - remounts the /system partition on the device read-write // system 파티션을 read-write 권한으로 remount 한다 adb reboot [bootloader|recovery] - reboots the device, optionally into the bootloader or recovery program // 디바이스를 재부팅한다 adb reboot-bootloader - reboots the device into the bootloader // 디바이스를 재부팅하여 bootloader 로 진입한다 adb root - restarts the adbd daemon with root permissions // adb 데몬을 root 퍼미션으로 바꾼다 adb usb - restarts the adbd daemon listening on USB adb tcpip - restarts the adbd daemon listening on TCP on the specified port networking: adb ppp [parameters] - Run PPP over USB. Note: you should not automatically start a PPP connection. refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1 [parameters] - Eg. defaultroute debug dump local notty usepeerdns adb sync notes: adb sync [ ] can be interpreted in several ways: - If is not specified, both /system and /data partitions will be updated. - If it is "system" or "data", only the corresponding partition is updated. environmental variables: ADB_TRACE - Print debug information. A comma separated list of the following values 1 or all, adb, sockets, packets, rwx, usb, sync, sysdeps, transport, jdwp ANDROID_SERIAL - The serial number to connect to. -s takes priority over this if given. ANDROID_LOG_TAGS - When used with the logcat option, only these debug tags are printed. 임베디드 리눅스 시스템에 익순한 개발자라면 시리얼 포트로 똑같이 처리할 수 있다. 다만 시리얼 포트로 큰 파일을 전송하기에는 시간이 너무 많이 걸리므로 추천하지 않는다.