利用adb 在macOS上 為Nexus Android 手機(jī)線刷原生鏡像固件

1. 前往?Google?開(kāi)發(fā)者網(wǎng)站,下載對(duì)應(yīng)手機(jī)型號(hào)的完整版工廠鏡像?解壓

2. 下載操作所需Android SDK Platform-tools工具,并進(jìn)行解壓備用

3.? 下載TWRP for shamu

4.? 下載Zip ROOT工具?SuperSU

Download Factory Images??https://developers.google.com/android/images

https://dl.google.com/dl/android/aosp/shamu-n6f27m-factory-bf5cce08.zip

1.? 進(jìn)入Bootloader模式

終端輸入: ? ? ? ?adb reboot bootloader

2. ?解壓鏡像文件 ? cd到此文件夾路徑下

終端輸入:? ? ? ? cd /Users/XLsn0w/Desktop/shamu-mob31t

3. ?執(zhí)行命令行"?sh ./?" ? 運(yùn)行" flash-all.sh "文件, ?執(zhí)行刷機(jī)

終端輸入:? ? sh ./flash-all.sh

手機(jī)將自動(dòng)執(zhí)行刷機(jī)腳本操作,請(qǐng)耐心等待直至手機(jī)重啟并出現(xiàn)開(kāi)機(jī)畫(huà)面...

$? adb push /Users/XLsn0w/Desktop/SuperSU.zip /sdcard

$ ?adb reboot bootloader

$? cd /Users/XLsn0w/Desktop

$? fastboot flash recovery twrp-3.1.1-0-shamu.img?

adb reboot bootloader? ? 進(jìn)入bootloader刷機(jī)界面

fastboot reboot ? ? ? ? ? ? ? ?重啟

adb shell reboot -p ? ? ? ? ?關(guān)機(jī)

fastboot devices ? ? ? ? ? ? ? 判斷設(shè)備是否連接

fastboot flash recovery twrp.img ? ?刷入TWRP

adb devices? ? ? ? ? ? ? ? ? ? 確定手機(jī)與電腦相連

adb reboot recovery ? ?進(jìn)入刷機(jī)界面

Mac 通過(guò)命令行adb install安裝apk

$? ? ? cd 到apk所在文件夾路徑

$? ? adb install xlsn0w.apk

1、安裝APK(如果加 -r 參數(shù),保留已設(shè)定數(shù)據(jù),重新安裝filename.apk)

adb install xxx.apk

adb install -r xxx.apk

2、卸載APK(如果加 -k 參數(shù),為卸載軟件但是保留配置和緩存文件)

adb uninstall xxx.apk

adb uninstall -k xxx.apk

3、查看當(dāng)前所有連接的模擬器設(shè)備

adb devices

4、對(duì)某一模擬器操作

adb -s 模擬器編號(hào) 命令

5、導(dǎo)入文件到模擬器 (該命令也可以實(shí)現(xiàn)安裝APK,只要把APK導(dǎo)入到"/system/app"或者"/data/app"就OK)

adb push 文件 模擬器路徑

6、從模擬器導(dǎo)出文件

adb pull 模擬器文件 本地路徑

7、查看模擬器log信息

adb logcat

8、獲取管理員權(quán)限

adb root

9、進(jìn)入shell模式

adb shell

10、啟動(dòng)activity (adb shell后面跟的命令主要來(lái)自源碼\system\core\toolbox目錄和源碼\frameworks\base\cmds目錄)

adb shell am start -n 包名/包名+類名(-n 類名,-a action,-d date,-m MIME-TYPE,-c category,-e 擴(kuò)展數(shù)據(jù),等)

11、獲取設(shè)備ID號(hào)

adb get-serialno

12、開(kāi)啟adb服務(wù)

adb start-server

13、關(guān)閉adb服務(wù)

adb kill-server

14、訪問(wèn)sqlite3

adb shell

sqlite3

15、重啟設(shè)備

adb reboot

16、掛在分區(qū)(可使系統(tǒng)分區(qū)重新可寫(xiě))

adb remount

17、發(fā)布端口(可以設(shè)置任意的端口號(hào),做為主機(jī)向模擬器或設(shè)備的請(qǐng)求端口)

adb forward tcp:5555 tcp:8000

18、關(guān)機(jī)命令

adb shell reboot -p

Android?SDK?Platform-tools 工具里面包含的?adb?及?fastboot?指令環(huán)境,是我們?cè)诤竺孢\(yùn)行相關(guān)指令所需要的,接下來(lái)先講解如何讓 macOS 運(yùn)行 Android SDK。

配置?macOS?中?Android?SDK?的環(huán)境變量

無(wú)論是?Windows?還是?macOS?環(huán)境中,我們都是通過(guò)?Terminal(Windows?稱為「命令提示符」)?來(lái)對(duì)手機(jī)下達(dá)操作指令的。

而在對(duì)手機(jī)控制之前,我們需要先搭建好?Android?SDK?的環(huán)境變量,使得?Terminal?能夠調(diào)取、運(yùn)行?adb?和?fastboot?指令。在?macOS?中搭建?Android?SDK?的操作如下:

啟動(dòng)?Spotlight,輸入「終端」找到?Terminal;

1. ? ?在?Terminal?中輸入cd?~,并按下回車執(zhí)行,將?Terminal?中目錄位置切換至目前登陸用戶的「Home目錄」位置;

2. ? ?輸入touch?.bash_profile,并按下回車執(zhí)行,創(chuàng)建出「.bash_profile」環(huán)境配置文件;

3. ?輸入open?-e?.bash_profile,并按下回車執(zhí)行,編輯「.bash_profile」環(huán)境配置文件;

4. ? 輸入路徑

export PATH=$PATH:/Users/XLsn0w/Desktop/platform-tools

此時(shí)將會(huì)打開(kāi)「.bash_profile」文件,在里面輸入export PATH=$PATH:/Users/登陸用戶名/存放的文件夾路徑名稱/platform-tools/代碼。在此舉個(gè)例子,若電腦登陸用戶名為xlsn0w,且 Platform-tools 工具解壓并放置在了「下載」文件夾,則此處需輸入的代碼為:export PATH=$PATH:/Users/xlsn0w/Downloads/platform-tools/,隨后保存并關(guān)閉即可;

5. ? 輸入source?.bash_profile,并按下回車執(zhí)行,執(zhí)行創(chuàng)建好的環(huán)境配置。

完成上述幾步簡(jiǎn)單的指令操作后,我們便完成了?Android?SDK?的環(huán)境變量配置,往后運(yùn)行?Platform-tools?工具的基礎(chǔ)準(zhǔn)備工作也已完成。

解鎖?Bootloader

Bootloader?是我們?cè)趩?dòng) Android 系統(tǒng)內(nèi)核之前運(yùn)行的底層模式,在這個(gè)底層模式下,我們能夠?qū)κ謾C(jī)進(jìn)行初始化硬件設(shè)備、建立內(nèi)存空間映射圖等操作。刷入官方工廠鏡像等操作也是需要在這個(gè)模式下執(zhí)行的。

(注意:此操作將清除手機(jī)中的所有資料,建議備份好手機(jī)中的所需資料后,再進(jìn)行下述解鎖?Bootloader?操作)

打開(kāi)「開(kāi)發(fā)者選項(xiàng)」:在「設(shè)置」中進(jìn)入「關(guān)于手機(jī)」,持續(xù)點(diǎn)擊「?版本號(hào)」7次;

依次打開(kāi)「USB?調(diào)試」及「OEM?解鎖」:在「設(shè)置」找到「開(kāi)發(fā)者選項(xiàng)」,找到并打開(kāi)對(duì)應(yīng)選項(xiàng)。而 Pixel?用戶需注意的是,「OEM?解鎖」選項(xiàng)必須是在能夠連接至?Google?服務(wù)器的聯(lián)網(wǎng)狀態(tài)才可打開(kāi);

隨后進(jìn)入?Bootloader?界面等候操作:將手機(jī)關(guān)機(jī),隨后同時(shí)按住「電源鍵+音量下鍵」,進(jìn)入到?Bootloader?界面并使用數(shù)據(jù)線與電腦連接;

執(zhí)行解鎖?Bootloader?操作指令:在?macOS?打開(kāi)?Terminal,并輸入fastboot?flashing?unlock指令,手機(jī)將會(huì)提示你是否要解鎖?Bootloader。

完成?Bootloader?解鎖:隨后按音量鍵選中「Yes」選項(xiàng)?,并按下電源鍵確認(rèn),此時(shí)手機(jī)便完成了解鎖?Bootloader,此時(shí)請(qǐng)勿關(guān)閉手機(jī),我們將繼續(xù)執(zhí)行刷機(jī)操作。

完成刷入 Android?官方系統(tǒng)操作

完成了?Bootloader?解鎖操作,我們現(xiàn)在可以執(zhí)行刷入官方工廠鏡像到手機(jī)了。

在?Finder?找到下載好的完整版工廠鏡像,并確認(rèn)已經(jīng)解壓完成;

在?Terminal?將路徑切換至鏡像文件夾中。假設(shè)我的文件夾路徑為/Users/jackcivlie/Downloads/bullhead-opp1.170223.012/,則輸入cd?/Users/jackcivlie/Downloads/bullhead-opp1.170223.012/即可;

倘若對(duì)?macOS?文件夾路徑不熟悉,難以辨別其路徑位置的話,這里可以使用一個(gè)取巧的辦法:先在 Terminal?中輸入cd(注意「cd」后面有空格),并在 Finder 將鏡像文件夾下拖拽任意一個(gè)文件到?Terminal?窗口,并將生成的路徑代碼中,將文件名的部分刪除,按下回車便完成了操作;

終端代碼如下

XLsn0ws-MacBook:~ XLsn0w$ adb reboot bootloader

* daemon not running. starting it now at tcp:5037 *

* daemon started successfully *

XLsn0ws-MacBook:~ XLsn0w$ cd /Users/XLsn0w/Desktop/shamu-mob31t

XLsn0ws-MacBook:shamu-mob31t XLsn0w$ sh ./flash-all.sh

(bootloader) slot-count: not found

(bootloader) slot-suffixes: not found

(bootloader) slot-suffixes: not found

(bootloader) has-slot:bootloader: not found

target reported max download size of 536870912 bytes

sending 'bootloader' (3807 KB)...

OKAY [0.120s]

writing 'bootloader'...

(bootloader) flashing partition ...

(bootloader) This may take a few seconds if a

(bootloader) different partition table is being

(bootloader) flashed since we need to backup

(bootloader) and restore a few partitions

(bootloader) Flashing primary GPT image...

(bootloader) Flashing backup GPT image...

(bootloader) flashing aboot ...

(bootloader) flashing sbl1 ...

(bootloader) flashing rpm ...

(bootloader) flashing tz ...

(bootloader) flashing sdi ...

(bootloader) flashing logo ...

OKAY [0.788s]

finished. total time: 0.908s

(bootloader) slot-count: not found

(bootloader) slot-suffixes: not found

(bootloader) slot-suffixes: not found

rebooting into bootloader...

OKAY [0.002s]

finished. total time: 0.002s

(bootloader) slot-count: not found

(bootloader) slot-suffixes: not found

(bootloader) slot-suffixes: not found

(bootloader) has-slot:radio: not found

target reported max download size of 536870912 bytes

sending 'radio' (115508 KB)...

OKAY [3.619s]

writing 'radio'...

(bootloader) flashing modem ...

(bootloader) flashing mdm1m9kefs1 ...

(bootloader) flashing mdm1m9kefs2 ...

(bootloader) flashing mdm1m9kefs3 ...

(bootloader) flashing versions ...

OKAY [1.689s]

finished. total time: 5.308s

(bootloader) slot-count: not found

(bootloader) slot-suffixes: not found

(bootloader) slot-suffixes: not found

rebooting into bootloader...

OKAY [0.002s]

finished. total time: 0.002s

(bootloader) slot-count: not found

(bootloader) slot-suffixes: not found

(bootloader) slot-suffixes: not found

(bootloader) current-slot: not found

(bootloader) slot-count: not found

(bootloader) slot-suffixes: not found

(bootloader) slot-count: not found

(bootloader) slot-suffixes: not found

target reported max download size of 536870912 bytes

(bootloader) has-slot:boot: not found

archive does not contain 'boot.sig'

(bootloader) has-slot:recovery: not found

archive does not contain 'recovery.sig'

(bootloader) has-slot:system: not found

archive does not contain 'system.sig'

archive does not contain 'vendor.img'

(bootloader) slot-count: not found

(bootloader) slot-suffixes: not found

(bootloader) slot-suffixes: not found

wiping userdata...

Creating filesystem with parameters:

Size: 59751923712

Block size: 4096

Blocks per group: 32768

Inodes per group: 8192

Inode size: 256

Journal blocks: 32768

Label:

Blocks: 14587872

Block groups: 446

Reserved block group size: 1024

Created filesystem with 11/3653632 inodes and 275392/14587872 blocks

wiping cache...

Creating filesystem with parameters:

Size: 268435456

Block size: 4096

Blocks per group: 32768

Inodes per group: 8192

Inode size: 256

Journal blocks: 1024

Label:

Blocks: 65536

Block groups: 2

Reserved block group size: 15

Created filesystem with 11/16384 inodes and 2089/65536 blocks

--------------------------------------------

Bootloader Version...: moto-apq8084-71.22

Baseband Version.....: D4.01-9625-05.34+FSG-9625-02.111

Serial Number........: ZX1G3268PW

--------------------------------------------

checking product...

OKAY [0.002s]

checking version-bootloader...

OKAY [0.002s]

checking version-baseband...

OKAY [0.002s]

sending 'boot' (8183 KB)...

OKAY [0.259s]

writing 'boot'...

OKAY [0.275s]

sending 'recovery' (8901 KB)...

OKAY [0.284s]

writing 'recovery'...

OKAY [0.126s]

sending sparse 'system' 1/4 (517178 KB)...

OKAY [ 18.982s]

writing 'system' 1/4...

OKAY [7.726s]

sending sparse 'system' 2/4 (515137 KB)...

OKAY [ 19.296s]

writing 'system' 2/4...

OKAY [7.407s]

sending sparse 'system' 3/4 (515644 KB)...

OKAY [ 19.295s]

writing 'system' 3/4...

OKAY [7.353s]

sending sparse 'system' 4/4 (514697 KB)...

OKAY [ 19.084s]

writing 'system' 4/4...

OKAY [6.867s]

erasing 'userdata'...

OKAY [9.301s]

sending 'userdata' (141067 KB)...

OKAY [4.432s]

writing 'userdata'...

OKAY [2.187s]

erasing 'cache'...

OKAY [0.043s]

sending 'cache' (6248 KB)...

OKAY [0.210s]

writing 'cache'...

OKAY [0.094s]

rebooting...

finished. total time: 123.237s

XLsn0ws-MacBook:shamu-mob31t XLsn0w$

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容