adb commands reference
文章推薦指數: 80 %
Backup and restore commands · -apk | -noapk : Back up or do not back up . · -obb | -noobb : Back up or do not back up . · -shared | -noshared : Back up or do not ... ToggleMenu AndroidDebugBridge(ADB)CommandsManual Home ADB fastboot AwesomeAdb adbcommandsreference Youcanissueadbcommandsfromacommandlineonyourdevelopmentmachineorfromascript. adb[-d|-e|-sserial_number]command Ifthere\'sonlyoneemulatorrunningoronlyonedeviceconnected,theadbcommandissenttothatdevicebydefault.Ifmultipleemulatorsarerunningand/ormultipledevicesareattached,youneedtousethe-d,-e,or-soptiontospecifythetargetdevicetowhichthecommandshouldbedirected. Thetablebelowlistsallofthesupportedadbcommandsandexplainstheirmeaningandusage. Globaloptions Listenonallnetworkinterfacesinsteadofonlyonlocalhost. adb-a DirectanadbcommandtotheonlyattachedUSBdevice.ReturnsanerrorwhenmorethanoneUSBdeviceisattached. adb-d Directanadbcommandtotheonlyrunningemulator.Returnsanerrorwhenmorethanoneemulatorisrunning. adb-e Directanadbcommandtoaspecificdevice,referredtobyitsadb-assignedserialnumber(suchasemulator-5556).Overridestheserialnumbervaluestoredinthe$ANDROID_SERIALenvironmentvariable. adb-s serial_number Thenameoftheadbserverhost.Thedefaultvalueislocalhost. adb-Hserver Theadbserverportnumber.Thedefaultvalueis5037. adb-Pport Listenontheprovidedadbserversocket.Thedefaultvalueistcp:localhost:5037. adb-Lsocket Generalcommands Printalistofalldevices.Usethe-loptiontoincludethedevicedescriptions. adbdevices[-l] Printalistofsupportedadbcommandsandtheirdescriptions. adbhelp Printtheadbversionnumber. adbversion Runcommandsonadeviceasanapp(specifiedusingpackage_name).Thisletsyouruncommandsinadbasiftheappyouspecifyisrunningthecommand(thatis,youhavethesamedeviceaccessthattheapphas),withoutrequiringrootaccess.Thismightbenecessarywhenusingadbonanon-rooteddeviceoranemulatorwithaPlayStoreimage.Theappmustbedebuggable. adbrun-aspackage_name Networkingcommands ConnecttoadeviceoverTCP/IP.Ifyoudonotspecifyaport,thenthedefaultport,5555,isused. adbconnecthost[:port] DisconnectfromthespecifiedTCP/IPdevicerunningonthespecifiedport.Ifyoudonotspecifyahostoraport,thenalldevicesaredisconnectedfromallTCP/IPports.Ifyouspecifyahost,butnotaport,thedefaultport,5555,isused. adbdisconnect[host|host:port] Listallforwardedsocketconnections. adbforward--list Forwardsocketconnectionsfromthespecifiedlocalporttothespecifiedremoteportonthedevice.Youcanspecifybothlocalandremoteportsinthefollowingways: tcp:port.Tochooseanyopenport,makethelocalvaluetcp:0. localabstract:unix_domain_socket_name. localreserved:unix_domain_socket_name. localfilesystem:unix_domain_socket_name. dev:character_device_name. jdwp:pid. adbforward[--no-rebind]localremote Removethespecifiedforwardedsocketconnection. adbforward--removelocal Listallreversesocketconnectionsfromthedevice. adbreverse--list Reverseasocketconnection.The--no-rebindoptionmeansthereversalfailsifthespecifiedsocketisalreadyboundthroughapreviousreversecommand.Youcanspecifytheportforbothlocalandremoteargumentsinthefollowingways: tcp:port.Tochooseanyopenport,maketheremotevaluetcp:0. localabstract:unix_domain_socket_name. localreserved:unix_domain_socket_name. localfilesystem:unix_domain_socket_name. adbreverse[--no-rebind]remotelocal Removethespecifiedreversesocketconnectionfromthedevice. adbreverse--removeremote Removeallreversesocketconnectionsfromthedevice. adbreverse--remove-all Filetransfercommands Copyfilesanddirectoriesfromthelocaldevice(computer)toaremotelocationonthedevice. adbpushlocalremote Copyremotefilesanddirectoriestoadevice.Usethe-aoptiontopreservethefiletimestampandmode. adbpull[-a]remotelocal Synchronizealocalbuildfromthelocationspecifiedin$ANDROID_PRODUCT_OUTtothedevice.Allchangedfilesarecopiedfromthespecifiedpartition.Thedefaultistosyncallpartitions.ThiscommandisonlyusedwhenyoubuildtheAndroidplatformsource.Appdevelopersdon’tneedtousethiscommand. The$ANDROID_PRODUCT_OUTenvironmentvariableisautomaticallysetbytheAndroidbuildsystemtocontainthelocationofthesystemimages.Normallyyouwon'tneedtoset$ANDROID_PRODUCT_OUTwhendoingadbsync,butitcanbeusefulifyou'renotinabuildtree(buthaveone)oraresyncingbetweenbuildtreeswithoutswitchingbetweenthem. $ANDROID\_PRODUCT\_OUT=/out/target/product/generic adbsync adbsync [system|vendor|oem|data|all] Appinstallationcommands Pushpackagestothedeviceandinstallthem.Possibleoptionsarethefollowing: -l:Forwardlockapp. -r:Replacetheexistingapp. -t:Allowtestpackages.IftheAPKisbuiltusingadeveloperpreviewSDK(ifthetargetSdkVersionisaletterinsteadofanumber),youmustincludethe-toptionwiththeinstallcommandifyouareinstallingatestAPK. -s:InstalltheappontheSDcard. -d:Allowversioncodedowngrade(debuggingpackagesonly). -g:Grantallruntimepermissions. adbinstall[options]package Sameoptionsasinstallwiththeadditionofthefollowing: -p:Partialappinstall. adbinstall-multiple[options]packages Removethisapppackagefromthedevice.Addthe-koptiontokeepthedataandcachedirectories. adbuninstall[-k]package Backupandrestorecommands Writeanarchiveofthedevice'sdatatofile.Ifyoudonotspecifyafilename,thedefaultfileisbackup.adb.Thepackagelistisoptionalwhenyouspecifythe-alland-sharedoptions.Thefollowingdescribestheusagesfortheotheroptions: -apk|-noapk:Backupordonotbackup.apkfiles.Thedefaultvalueis-noapk. -obb|-noobb:Backupordonotbackup.obbfiles.Thedefaultvalueis-noobb. -shared|-noshared:Backupordonotbackupsharedstorage.Thedefaultvalueis-noshared. -all:Backupallinstalledapps. -system|-nosystem:Includeordonotincludesystemappswhenbackingupallinstalledapps(-all).Thedefaultvalueis-system. adbbackup`\[`-ffile`\]\[`-apk`|`-noapk`\]\[`-obb`|`-noobb`\]\[`-shared`|`-noshared`\]\[`-all`\]\[`-system`|\[`-nosystem`\]`package_names Restorethedevicecontentsfromfile. adbrestorefile Debugcommands Printabugreporttothespecifiedpath.Ifpathisadirectory,thenthebugreportissavedtothatdirectoryusingthedefaultfilename,bugreport.zip.Devicesthatdonotsupportzippedbugreportsprinttostdout. adbbugreportpath PrintalistoftheavailableJDWPprocessesonagivendevice.Useforwardjdwp:pidtoconnecttoaspecificJDWPprocess.Forexample: adbforwardtcp:8000jdwp:472 jdb-attachlocalhost:8000 adbjdwp Printlogdatatothescreen. The$ADB_TRACEenvironmentvariablecontainsacomma-separatedlistofthedebuginformationtolog.Valuescanbeanycombinationofthefollowing:all,adb,sockets,packets,rwx,usb,sync,sysdeps,transport,andjdwp. adblogcat[-help][option][filter-spec] Securitycommands Disabledm-veritycheckingonuserdebugbuilds.Thedm-verityoptionensuresthatwhenauserbootsadevicethatitisinthesamestatethatitwasinwhenitwaslastused. adbdisable-verity Re-enabledm-veritycheckingonuserdebugbuilds.Thedm-verityoptionensuresthatwhenauserbootsadevicethatitisinthesamestatethatitwasinwhenitwaslastused. adbenable-verity GenerateadbpublicandprivateRSAencryptedkeys.Theprivatekeyisstoredinfile.Thepublickeyisstoredinfile.pub.AnRSAkeypairisneededwhenyouuseadbtoconnectoverUSBforthefirsttime.Youmustacceptthehostcomputer'sRSAkeytoexplicitlygrantadbaccesstothedevice. Usethe$ANDROID_VENDOR_KEYSenvironmentvariabletopointtoafileordirectorythatcontains2048-bitRSAauthenticationkeypairsthatyougeneratedwiththekeygencommand.ThesekeypairsareinadditiontotheRSAkeypairsgeneratedbytheadbserver. Whentheadbserverneedsakey,itfirstsearchestheadbserverkeystoredirectory.Ifnokeysarefound,itthenchecksthe$ANDROID_VENDOR_KEYSenvironmentvariableforalocation.Ifstillnokeysarefound,thelocaladbservergeneratesandsavesanewkeypairintheadbserverkeystoredirectory.Forthisreason,onlyanOEMcreatinganewAndroiddeviceshouldneedtorun'adbkeygen'themselves. Bydefaultkeypairsgeneratedbytheadbserverarestoredinthefollowingkeystoredirectoriesasadbkey(privatekey)andadbkey.pub(publickey): LinuxandMac:$HOME/.android. Windows:%USERPOFILE%\.android. adbkeygenfile Scriptingcommands Waitforthedevicetobeinthespecifiedstate. state:Valuescanbedevice,recovery,sideload,orbootloader. transport:Valuescanbeusb,local,orany. adbwait-for[-transport]-state Printtheadbstateofadevice.Theadbstatecanbeprintoffline,bootloader,ordevice. adbget-state Printtheadbdeviceserialnumberstring. adbget-serialno Printtheadbdevicepath. adbget-devpath Remountthe/system,/vendor,and/oempartitionsinread-writemode. adbremount Rebootthedevice.Thiscommanddefaultstobootingthesystemimage,butalsosupportsbootloaderandrecovery. Thebootloaderoptionrebootsintobootloader. Therecoveryoptionrebootsintorecovery. Thesideloadoptionrebootsintorecoveryandstartssideloadmode. Thesideload-auto-rebootoptionisthesameassideload,butrebootsaftersideloadingcompletes. adbreboot[bootloader|recovery|sideload|sideload-auto-reboot] Sideload(installinAPKformat)thespecifiedfullOTApackageontothedevice. adbsideloadotapackage Restartadbdwithrootpermissions. adbroot Restartadbdwithoutrootpermissions. adbunroot RestarttheadbserverlisteningonUSB. adbusb RestarttheadbserverlisteningonTCPatthespecifiedport. adbtcpipport-number Internaldebuggingcommands Checkwhethertheadbserverprocessisrunning. adbstart-server Terminatetheadbserverprocess. adbkill-server Forceareconnectfromthehost. adbreconnect Forceareconnectfromthedevicetoforceareconnect. adbreconnectdevice Shellcommands Startaremoteinteractiveshellinthetargetdevice. adbshell Issueashellcommandinthetargetdeviceandthenexittheremoteshell.Useanycombinationofthefollowingoptions: -e:Specifyanescapecharacterorthevaluenoneifyoudonotwanttouseanescapecharacter.Ifyoudonotprovideavalue,thedefaultescapecharacter(adash(-)),isused. -n:Donotreadfromstdin. -T:Disablepseudo-terminalutiity(PTY)allocation. -t:ForcePTYallocation. -x:Disableremoteexitcodesandstdout/stderrseparation. adbshell-eescape_char[-n][-T][-t][-x][command] Runanemulatorconsolecommand adbemucommand
延伸文章資訊
- 1Table of all ADB & Fastboot Commands for Android (Windows ...
ADB Shell Commands list
- 2Android Debug Bridge (adb)
- 3List of Useful ADB and Fastboot Commands - DroidWin
Most Commonly Used ADB Commands: Check ADB Connection; ADB Shell Command; Reboot to Bootloader/Fa...
- 4ADB Commands List – A Detailed ADB Cheat Sheet
- 5Most Complete ADB Cheat Sheet - Automate The Planet
ADB, Android Debug Bridge, is a command-line utility included with Google's Android SDK. ADB can ...