ADB命令大全
安装软件:adb install apk (文件名称.apk)
重新安装该软件:adb install -r apk (文件名称.apk)
卸载apk软件:adb uninstall apk(包名.apk)
查看手机上的运行日志,此项可以用来查错:adb logcat
查看手机是否连接,以及连接了几台手机:adb devices
A为手机路径,B为电脑路径,意思为:把文件从手机中复制到电脑上:adb pull <A> <B>
A为手机路径,B为电脑路径,意思为:把文件从电脑复制到手机上:adb push <B> <A>
进入手机的超级终端Terminal:adb shell
重新挂载文件系统:adb remount
重启手机:adb reboot
重启到Recovery界面:adb reboot recovery
重启到bootloader界面:adb reboot bootloader
显示该目录下的文件和文件夹:ls
进入某个目录:cd(注意分隔斜杠方向是/)
获得最高权限:su
查找设备:adb wait-for-device
断开连接:adb kill-server
开始连接:adb start-server
1.手机由于替换、由于更改权限等等的造成手机无限重启或者直接无法开机。不刷机解决方法。
启动cmd,追到adb目录。
输入以下命令(括号为显示,没有为无或者未知)(注意大小写)
adb shell(应该显示shell#@android/或类似)
adb remount(应该显示remount succeed)
adb shell chmod #权限代码# /#文件目录#(权限代码查我其他日志,一般都是644,文件目录示例:/system/fonts/DroidSans.ttf)
adb reboot(重启)
2.由于操作不当导致系统损坏而必须刷机,但是又想备份数据。
首先,手机开到REC模式,并且安装了REC的ADB驱动(USB-MS模式)。
然后一样,cmd追到adb目录。(后面的是注释)
adb start-server(然后帮你找手机了)
adb shell(请求shell用户)
# mount /dbdata (其实有些网上说的是直接mount /data就可以,但是我发现我手机上面的数据都是存放在dbdata上)(另一点,这句话我也没试过,自己试试看吧,貌似第三方REC(比如CMW)可以在REC上先挂载。
com.android.providers.contacts 这个是你的电话本
com.android.providers.telephony 这个是你的短信
怎么弄出来呢?我也就不用多解释了,前面已经给出了adb的复制命令了。
3.仿造REC备份整个系统。
一样,先追到adb目录。
然后命令是:adb backup [-system|-nosystem] -all [-apk|-noapk] [-shared|-noshared] -f <档案名称>
(就一条而已)
下面开始解释(相信你会看cmd的也一样看出是什么意思吧)
[-system|-nosystem]
这个指令是告诉adb 在备份时是否要连同系统一起备份。
若没有打的话,默认是-system 表示会一起备份系统。
注意!若连系统一起备份,在还原的时候会复盖系统档案,对于已经升级后的手机是非常不好的
我不知道在没有ROOT的情况下adb是否有权限去还原系统档案,但就算如此 还是不建议这样做。
因此,-nosystem是建议一定要打上的指令。
-all
这个指令是一定要打上去的,问你是否要备份全部的APP。
若有加上-nosystem的指令,那么他就只会备份你目前已经安装上去的APP 而不会连系统APP一起备份。
[-apk|-noapk]
默认是-noapk,这个的意思是是否连安装的APK一起备份。
若为-noapk则只会备份APK的资料档(像是游戏存盘 设定 之类的)。
但我会建议连APK一起备份,因为这样才不会有版本冲突的问题。
[-shared|-noshared]
默认是-noshared 这个会问你是否连手机储存空间或是SD卡的档案一起备份。
我是不知道若有APP安装在SD卡上的时候 没打这指令是否会略过,但若大部分的APP都安装在内部空间的话,这个就可以不用打了。
(注:HTC有保留一个名为com.android.sharedstoragebackup的APK,这个APK会将SD卡或是手机空间的资料都备份 因此除非使用-nosystem指令,否则对于HTC手机来说 不管有无打-shared 手机空间的资料一定会备份)。
-f <档案名称>
这个是指定备份完之后,要存在电脑的哪个地方。
不过记得要打档名 而副档名则一定要打.ab
好的,那么我给出一条比较好的完整命令:
adb backup –system –all –apk –share –f “D:\test\test.ab”
备份补充相关要点:
这边要先说明,由于有些电脑并非使用原生USB3.0,而是使用独立的芯片,并非由芯片组直接提供,因此有时adb会因此无法连线或是传输上出问题,所以 请连接USB2.0或是连接原生的USB3.0。
首先请确定已经有安装手机驱动(特别强调! 至于手机驱动哪找 看你是哪家手机就去哪家的官网找)
接着请连上手机 确定USB侦错模式是否有启动
(注:USB请设定为充电模式或MTP模式 请勿设定成磁盘机或网络分享!)
接下来就可以直接使用backup指令了
比方说我要备份APK资料,要连同APK一起,不要去备份SD卡或外存,不要去备份到系统APP且我要指定档案名称为test,并存在D盘的话,那么指令就是:adb backup -apk -all -nosystem -f "D:\test.ab"
注意1:档案路径和档名若有空格 请记得路径要加双引号””
例:-f "D:\phone backup\htc j.ab",否则会有问题。
注意2:若输入指令后没出现备份画面或是adb显示错误讯息,有可能是adb没抓到手机,请使用adb devices指令(完整指令请输入adb查看)来看adb是否有抓到手机。
这个会要你输入这个备份档案的保护密码,你可以选择不输入。好了之后就按“备份我的资料”。
再来就慢慢等它备份啦……备份的过程中,手机画面会出现正在备份的APK及资料。
备份完后就会自动跳出程序,并且看看D槽。
还原:
既然已经备份好了,那之后要怎么还原呢?
这时候就要使用另一个指令 adb restore
我还是以刚刚的test.ab档案为例 那么打的时候就输入
adb restore "D:\test.ab"
打入你的手机密码以及你的封包所设定的密码(假如有的话)就会开始做还原的动作,而且它会依据一开始备份时存放的路径下去还原。
等到还原成功后,就可以去看看APP是否都回来了,也可以检查游戏存盘或是设定那些是否还在。
进阶作法及额外注意事项:
个别程式备份方法:
有不少人问我如何备份单个APP就好了,说简单不简单,说难也不难。难就难在得找出APP的物件名称。
什么是物件名称?简单来说物件名称才是属于APP真正的名称,由每一个APP开发者(或开发商)所自己定义的Java package名称,别忘了 Android的应用都是由Java写出来的 如果有写过Java的话应该对package不陌生,至于我们一般看到的APP名称都是另外再加上去的。
比如 从iOS移植到Android上的免费游戏之一,Temple Run,它表面名称虽然就叫Temple Run,但它实际的物件名称为 com.imangi.templerun,而不要以为这就是基本的格式了(什么前面一定是com之类的),这个完全是由开发者自行定义。虽然通常开发者都是定义com开头后面加东西,但是当然也有很坑爹的开发者,本人下载上万测试软件中就出现过那么一个新手代码是cmw.firstblood.supersystem……好吧后来我反编译之后改掉了。
OK 这样大概就了解了吧? 不过要怎么去看物件名称?
基本上一般的应用程式管理员和工作管理员都是没办法看到物件名称的,需要安装类似APK管理器之类的软件(像是超级管理器),才可以知道每个APP的类别名称。
特别注意!类别名称是有大小写区分的,请仔细查看,以免备份出问题。
若知道了物件名称后 指令要怎么打呢?我们这边就以Temple Run为例
adb指令就要打成::
adb backup -apk com.imangi.templerun -f "D:\test.ab"
这边说明一下,由于只是备份单一APP的资料,因此不需要加-nosystem -all -noshared等全域指令,只需要这样简单打就可以了,而依照你的喜好,想连APK一起备份就加-apk。
输入完后 手机会再度出现与上头一样的画面,只要按一下备份,就会把指定的APP给备份下来了。
资料另外的储存位置:
有些APP资料或是游戏存盘,并不一定会存在放手机内部的储存空间,有可能会存放在SD卡或是手机的使用者储存空间。
目前已经知道,像是TempleRun,SubwaySurf,以及LINE,他们的纪录都是存在SD卡或是手机储存空间上,至于怎么找他们,只要到SD卡(使用者储存空间)里头看,会有一个Android资料夹,里面有一个data资料夹,就是档案的存放之处,只要备份下来就可以了,但要注意的是,若在备份之前就移除程式,那么该资料也是会从储存空间上移除的,这点还请注意。
使用钛备份还原:
这是我找资料的时候无意间发现的 其实钛备份也支援使用adb备份出来的资料,只要版本是5.6以后的就行了(想要的下载后面的钛备份连接),因此,也可以使用钛备份进行还原的动作,缺点是本身需要root 而且必须是专业版才支援。
Last week, we showed you how to install ADB and fastboot on any OS. If you‘re not sure why you‘d want to go to the (relatively minor) trouble, here are just some of the useful things you can do with these two handy tools.
Disclaimer: These commands are intended to give you an idea of what you can do with ADB and fastboot. They are not direct instructions and not all commands work on all devices. It‘s perhaps better to think of this as a glossary. Due to the sheer number and variety of devices and implementations in the Android world, it‘s impossible for us to provide step-by-step instructions for every single device. Be sure to research your specific phone or tablet before throwing commands at it.
Manage Your Device with ADB
ADB has a wide variety of functions for managing your device, moving content to and from your phone, installing apps, backing up and restoring your software, and more. You can use ADB while your phone is plugged in to a computer. You can also use ADB with your device wirelessly by following these instructions. You‘ll need to briefly connect your device to your computer with a USB cable for this to work, but it should only take a few seconds to execute these commands and then you‘re good to use ADB wirelessly if you so choose.
adb devices
Function: Check connection and get basic information about devices connected to the computer.
When using ADB, this is probably the first one command you‘ll run. It will return a list of all devices that you have connected to your computer. If it returns a device ID like the one seen above, you‘re connected and ready to send commands.
adb reboot recovery
Function: Reboot your phone into recovery mode.
A lot of functions like flashing ROMs to your phone require you to boot into recovery mode. Normally, this requires you to hold down a particular set of buttons on your phone for a certain length of time, which is obnoxious. This command allows you to boot directly into recovery mode without performing the complex finger dance of your people.
adb reboot-bootloader
Function: Reboot your phone into bootloader mode.
Along the same lines as the previous command, this one allows you to boot directly to your phone‘s bootloader. Once you‘re in the bootloader, ADB won‘t work anymore. That‘s where fastboot comes in (which we‘ll get to in a bit). However, much like the recovery command, it‘s much easier to boot into your bootloader with a command on your computer than a complex series of buttons on your phone.
adb push [source] [destination]
Function: Copy files from your computer to your phone.
The push command allows you to copy files from your computer to your phone without touching your device. This is particularly handy for copying large files from your computer to your phone like movies or ROMs. In order to use this command, you‘ll need to know the full file path for both your source and destination. If the file you want to copy is already in your tools folder (where ADB lives), you can simply enter the name of the file as the source.
adb pull
Function: Copy files from your phone to your computer.
The yin to to push‘s yang, the pull command in ADB allows you to copy files from your phone to your computer. When pulling files, you can choose to leave out the destination parameter. In that case, the file will be copied to the folder on your computer where ADB itself lives. You can then move it to wherever you‘d prefer like normal.
adb install [source.apk]
Function: Remotely install APKs on your phone.
You can use this command to install an app on your phone without touching it. While this isn‘t a terribly impressive trick for an app that‘s on the Play Store (where you can already remotely install, uninstall, and update apps), it‘s quite handy if you need to sideload an app.
adb shell [command]
Function: Open or run commands in a terminal on the host Android device.
We love the terminal here at Lifehacker. There are so many great things you can do with it. Most of us don‘t tend to bother with the terminal in Android because we don‘t want to type long text-based commands on a tiny touchscreen. However, the adb shell command allows you to open up a full terminal on the host device. Alternatively, you can type "adb shell" followed by a valid terminal command to execute just that one command by itself.
adb backup
Function: Create a full backup of your phone and save to the computer.
Backing up your Android phone is already something you can and should be doing automatically. However, if you need to create a complete backup before hacking away at something particularly risky, you can create a full backup with a single command. You don‘t even need root access (though this may mean that some protected data can‘t be backed up). You can read more about the parameters for this command—and there are a lot of them—here.
adb restore
Function: Restore a backup to your phone.
The corollary to the previous command, adb restore allows you to point to an existing backup file and restore it to your device. So, for example, type "adb restore C:\[restorefile].zip" and your phone will shortly be back to normal.
adb sideload
Function: Push and flash custom ROMs and zips from your computer.
This command is a relative newcomer to the ADB field and is only supported by some custom recoveries. However, you can use this single command to flash a .zip that‘s on your computer to your phone. Once again, this allows you to flash whole ROMs (or anything else you can flash with a .zip file) without touching your phone.
These commands are just some of the more useful ones you can use with ADB installed on your computer. You may not want to use it all the time for everyday tasks, but when you need them, you‘ll be glad you have them.
Unlock and Modify Your Phone‘s Firmware with Fastboot
As stated in our previous article, fastboot allows you to send commands to your phone while in the bootloader (the one place ADB doesn‘t work). While you can‘t do quite as many things here, the things you can do are awesome, including unlocking certain phones—like Nexuses and certain others—as well as flashing custom recoveries and even some ROMs. It should be noted, though, that not all phones support fastboot and if you have a locked bootloader, you‘re probably out of luck here. That being said, here are some of the most useful tools in fastboot‘s arsenal.
fastboot oem unlock
Function: Unlock your bootloader, making root access possible.
When people go on about how "open" Nexus devices are, this is what they‘re talking about. Most phones require a root exploit to gain superuser access and the ability to heavily modify your phone‘s firmware. With a Nexus device, you can unlock your bootloader with a single command. From there, you‘ll be allowed to install custom recoveries or give yourself root access.
It should be noted, this command will also completely wipe your phone. This means it‘s a great command to run when you get a brand new phone, but if you‘ve been using yours for a while, do a backup first.
fastboot devices
Function: Check connection and get basic information about devices connected to the computer.
This is essentially the same command as adb devices from earlier. However, it works in the bootloader, which ADB does not. Handy for ensuring that you have properly established a connection.
fastboot flash recovery
Function: Flash a custom recovery image to your phone.
Flashing a custom recovery is an essential part of the ROM-swapper lifestyle. As with everything else in this list, you can install a custom recovery on your device without touching it by using this command.
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。