標籤:
adb用法:
準備:
1、在電腦上安裝相應的USB驅動,在各分區置頂文章有下載連結
2、手機進入設定->開發人員選項->勾選USB調試
adb devices 查看是否有裝置
adb shell ——登入到手機,可以執行各種linux命令。
運行後會出現上面提到的提示符,然後游標閃動等待輸入命令,比如:
ls ——列出目前的目錄下的目錄和檔案
cd xxx ——進入xxx目錄,可以是相對或絕對路徑
其他常用命令很多,具體可以百度。
adb shell 查看是否root、是否完全root
1、在電腦上依次點擊:開始菜單->運行,然後輸入cmd,斷行符號後會彈出Dos視窗
2、輸入adb shell,然後斷行符號
3、此時注意手機的反應,如果手機彈出ADB shell請求超級使用者權限,是否允許的對話方塊,請點擊允許。這個只有第一次運行時會出現。
4、這時如果出現的是:[email protected]# 就代表手機已經完全root,很多功能需要在這個模式下才能正常工作。
如果出現的是:[email protected]$ 則需要進一步判斷
4、再輸入su,然後斷行符號
此時注意手機的反應,如果手機彈出ADB shell請求超級使用者權限,是否允許的對話方塊,請點擊允許。這個只有第一次運行時會出現。
5、如果此時出現 [email protected]# 則代表手機已經root,不過kernel沒有破解,稱為不完全root,
這時adb和fastboot日常的需要root許可權的操作應該都能正常運行。
如果出現報錯,或仍然是 [email protected]$ 則代表手機沒有root,adb和fastboot的很多功能不可以用
adb shell 備份匯出分區, 可用ADB通過命令查看系統磁碟分割,命令如下:
su
cat /proc/mtd
假設mtd1對應 boot分區,mtd2對應system分區,備份匯出boot.img與system.img命令如下:
cat /dev/mtd/mtd1 > /sdcard/boot.img
cat /dev/mtd/mtd2 > /sdcard/system.img
adb shell dd命令來刷recovery.img
adb shell
su
1)高通平台 :dd if=/data/local/tmp/recovery.img of=/dev/block/platform/msm_sdcc.1/by-name/recovery
2)MTK平台 :dd if=/data/local/tmp/recovery.img of=/dev/recovery
3)英偉達平台:dd if=/data/local/tmp/recovery.img of=/dev/block/platform/sdhci-tegra.3/by-name/SOS
adb remount(需要完全root)
——把system目錄以讀寫的方式重新掛載,運行後就可以修改system目錄下的東西了
adb push object dest
主要用於上傳檔案到手機,其中object是要上傳的檔案,如果在目前的目錄下則可以省略路徑名,否則必須加路徑,
dest是檔案將要放到手機上的路徑,也可以跟上檔案名稱。
舉例如下:
adb push 1.zip /sdcard ——把目前的目錄下的1.zip檔案上傳到手機上/sdcard目錄下,檔案名稱不變
adb push 2.rar /external_sd/22.rar ——把目前的目錄下的2.rar檔案上傳到手機上/external_sd目錄下,檔案名稱變成22.rar
注意:這裡的dest在上面提到的非root、不完全root和root環境下有著不同的限制。
非root環境、不完全root環境:常用的只有/sdcard、/external_sd,還有折騰可能用到/data/local/tmp
完全root環境: 運行adb remount之後dest可以是system目錄或其子目錄(部分特殊目錄除外)。
adb pull object dest
——從手機下載檔案到本地
object是手機上某個檔案的路徑,需要以/開頭的完整路徑,dest可以省略,省略的話是下載到目前的目錄。
舉例如下:
adb pull /system/app/Maps.apk ——把手機上/system/app/Maps.apk檔案下載到目前的目錄下
adb pull /system/app/Maps.apk 2dir/ ——把手機上/system/app/Maps.apk檔案下載到目前的目錄下的2dir目錄下,前提是目前的目錄下存在2dir目錄
adb pull /system/app/Maps.apk 2dir/Map.apk ——把手機上/system/app/Maps.apk檔案下載到目前的目錄下
的2dir目錄下,改名為Map.apk,前提是目前的目錄下存在2dir目錄
adb reboot ——重啟手機
adb reboot bootloader ——重啟手機到fastboot模式 直接重啟手機到fastboot模式,不用關機後再按按鍵組合
adb reboot recovery ——重啟手機到recovery模式 直接重啟手機到fastboot模式,不用關機後再按按鍵組合
adb install xxx.apk ——安裝目前的目錄下的apk包到手機
fastboot命令
fastboot是配合手機的fastboot模式使用的一種工具。
可以在手機系統損壞(非磚)的情況下不依賴手機軟體,而是使用本地的鏡像操作手機。
下面列舉常用的用法:
fastboot devices 查看是否有裝置
fastboot boot boot.img|recovery.img ——用目前的目錄下的boot.img或者recovery.img啟動手機,具體如下
fastboot boot boot.img ——用目前的目錄下的boot.img啟動手機,在手機boot分區損壞的情況下可以用這個正常進入系統
fastboot boot recovery.img ——用目前的目錄下的recovery.img啟動手機到recovery模式,
這個和手機上現有的系統完全無關,只要本地的 recovery.img是以前能正常進rec的,那就絕對沒問題。
那些官升或者刷rom後無法進入rec的其實都可以通過這種方式進入recovery 環境進行刷機、刷rec,刷各種zip……
上面介紹兩種操作都是臨時的,也就是說重啟之後手機還是原來的狀態,沒有任何變動。
典型的應用情境是修改boot.img,可以用fastboot boot bootnew.img來測試新的boot.img,不對的話只需要重啟手機。
下面這個的話就是真正改變了手機的boot分區,改寫成了目前的目錄下 boot.img的內容。
fastboot flash boot boot.img ——把目前的目錄下的boot.img刷入手機的boot分區。
fastboot flash recovery recovery.img ——把目前的目錄下的recovery.img刷入手機的recovery分區。
fastboot flash system system.img ——把目前的目錄下的system.img刷入手機的system分區。
fastboot flash userdata userdata.img ——把目前的目錄下的userdata.img刷入手機的data分區。
fastboot erase system
fastboot erase cache
fastboot erase config
fastboot erase data
fastboot erase logs
fastboot erase factory
fastboot reboot —— 重啟手機
Android系統的分區為:
boot分區對應 /boot
recovery分區對應 /recovery
system分區對應的目錄 /system
userdata分區對應 /data
cache分區對應 /cache
Let’s move forward to the useful commands:
Commands |
Use |
Basic ADB Commands |
adb devices |
Shows a list of devices attached to the computer. |
adb reboot |
Reboots a device connected to the PC. |
adb reboot recovery |
Reboots a device into recovery mode. |
adb reboot download |
Reboots the connected device into download mode. E.G Download mode on Samsung Galaxy devices. |
adb reboot bootloader |
Reboots a device into Bootloader. Once in Bootloader, you can make further selections here. |
adb reboot fastboot |
Reboots a connected device into Fastboot mode. |
Installing / Uninstalling / Updating Apps with ADB. |
adb install <ApplicationpathPackagename>.apk |
ADB install let’s you install APK files directly to your phone. To use this command type adb install application path, as shown in the commands part and hit enter key and it will start installing the app on your phone. e.g adb install C:/Users/UsamaM/Desktop/CandyCrushSaga.apk. If process succeeds it will show you “Success” in the command window. |
adb install -r <AplicationpathPackagename>.apk |
If you have already installed an app, and you just want to update it then this command will let you do so. e.g adb install -r C:/Users/UsamaM/Desktop/CandyCrushSaga.apk |
adb unistall package_namee.g adb uninstall com.android.chrome |
Uninstalls and application from your device. The easiest way to find a package name is, install Package Name Viewer from the play store and find the name of the package under the App Name. If process succeeds it will show you “Success” in the command window. |
adb uninstall -K package_namee.g adb uninstall -K com.android.chrome |
Uninstall an app but keeps it’s data and cache directories. If process succeeds it will show you “Success” in the command window. |
Push and Pull files |
adb rootadb push >e.gadb push c:\users\UsamaM\desktop\Song.mp3 \system\media adb push filepathonPC/filename.extension path.on.phone.toplace.the.file |
the adb push commands let’s you transfer any files to your phone from your PC. You simply need to provide the path of file on your PC and path where to place this file on your phone. |
adb rootadb pull>e.gadb pull \system\media\Song.mp C:\users\UsamaM\desktop adb pull [Path of file on phone] [Path on PC where to place the file] |
Similar to the adb push command. Using adb pull, you can simply pull any files from your phone. |
Backing up system and installed apps. Before doing this, in your adb folder create a folder Backup and under the backup folder create two folders named SystemApps and InstalledApps. These folders are necessary as you’ll be pushing the backed up apps to these folders. |
adb pull /system/app backup/systemapps |
backs up all the system apps of your phone to the Systemapps folder that you created in the ADB folder. |
adb pull /system/app backup/installedapps |
backs up all the installed apps of your phone to the installedapps folder that you created in the ADB folder. |
Background Terminal |
adb shell |
starts the background terminal. |
exit |
exits the background terminal. |
adb shell <command you want>e.g adb shell su |
switches to the root of your phone. Please make sure that you’re rooted in case you wish to use adb shell su. |
Fastboot commands To flash files using fastboot, place the desired files in Fastboot folder or Platform-tools folder that you obtained after installation of Android SDK tools. |
Fastboot Flash File.zip |
Flashes a .zip file to your phone, when your phone is connected in Fastboot mode. |
Fastboot Flash recovery recoveryname.img |
Flashes a recovery to your phone when it’s connected in Fastboot mode. |
Fastboot flash boot bootname.img |
Flashes a boot or kernel image when your phone is connected in Fastboot mode. |
Fastboot getvar cid |
shows you the CID of your phone. |
Fastboot oem writeCID xxxxx |
writes the super CID. |
fastboot erase system fastboot erase data fastboot erase cache |
In case you want to restore a nandroid backup, you’ll have to delete the current system/data/cache of your phone first. Before doing this, it is always recommended to have backed up your system using a custom recovery>backup option and copy the backed up .img files to Fastboot or Platform-tools folder in Android SDK folder. Then performing these commands will erase everything. |
fastboot flash system system.img fastboot flash data data.img fastboot flash cache cache.img |
These commands will restore the backup that you made using a custom recovery on your phone and placed in the Fastboot folder under Android SDK tools. |
fastboot oem get_unlock_data fastboot oem unlock UNIQUE_KEY
fastboot oem get_identifier_token fastboot oem flash Unlock_code.bin
fastboot oem lock |
These commands help you to get the identifier token of your phone that can be used for unlocking the bootloader. The second command helps your to flash the bootloader unlock code, and the 3rd commands helps you to lock your phone’s bootloader once again if locking it is actually allowed. |
Logcat |
adb logcat |
Shows you the real time logs of your phone, these logs represent the ongoing process on your device.It is recommended that you run this command while your device boots up to check what’s going on. |
adb logcat > logcat.txt |
Creates a .txt file containing the logs in the Platform-tools folder or Fastboot folder in Android SDK tools directory. |
Android 手機 ADB FastBoot 命令基本用法