1. 前往 Google 开发者网站,下载对应手机型号的完整版工厂镜像 解压
2. 下载操作所需Android SDK Platform-tools工具,并进行解压备用
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. 进入Bootloader模式
终端输入: adb reboot bootloader
2. 解压镜像文件 cd到此文件夹路径下
终端输入: cd /Users/XLsn0w/Desktop/shamu-mob31t
3. 执行命令行" sh ./ " 运行" flash-all.sh "文件, 执行刷机
终端输入: sh ./flash-all.sh
手机将自动执行刷机脚本操作,请耐心等待直至手机重启并出现开机画面...
$ 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 进入bootloader刷机界面
fastboot reboot 重启
adb shell reboot -p 关机
fastboot devices 判断设备是否连接
fastboot flash recovery twrp.img 刷入TWRP
adb devices 确定手机与电脑相连
adb reboot recovery 进入刷机界面
Mac 通过命令行adb install安装apk
$ cd 到apk所在文件夹路径
$ adb install xlsn0w.apk
1、安装APK(如果加 -r 参数,保留已设定数据,重新安装filename.apk)
adb install xxx.apk
adb install -r xxx.apk
2、卸载APK(如果加 -k 参数,为卸载软件但是保留配置和缓存文件)
adb uninstall xxx.apk
adb uninstall -k xxx.apk
3、查看当前所有连接的模拟器设备
adb devices
4、对某一模拟器操作
adb -s 模拟器编号 命令
5、导入文件到模拟器 (该命令也可以实现安装APK,只要把APK导入到"/system/app"或者"/data/app"就OK)
adb push 文件 模拟器路径
6、从模拟器导出文件
adb pull 模拟器文件 本地路径
7、查看模拟器log信息
adb logcat
8、获取管理员权限
adb root
9、进入shell模式
adb shell
10、启动activity (adb shell后面跟的命令主要来自源码\system\core\toolbox目录和源码\frameworks\base\cmds目录)
adb shell am start -n 包名/包名+类名(-n 类名,-a action,-d date,-m MIME-TYPE,-c category,-e 扩展数据,等)
11、获取设备ID号
adb get-serialno
12、开启adb服务
adb start-server
13、关闭adb服务
adb kill-server
14、访问sqlite3
adb shell
sqlite3
15、重启设备
adb reboot
16、挂在分区(可使系统分区重新可写)
adb remount
17、发布端口(可以设置任意的端口号,做为主机向模拟器或设备的请求端口)
adb forward tcp:5555 tcp:8000
18、关机命令
adb shell reboot -p
Android SDK Platform-tools 工具里面包含的 adb 及 fastboot 指令环境,是我们在后面运行相关指令所需要的,接下来先讲解如何让 macOS 运行 Android SDK。
配置 macOS 中 Android SDK 的环境变量
无论是 Windows 还是 macOS 环境中,我们都是通过 Terminal(Windows 称为「命令提示符」) 来对手机下达操作指令的。
而在对手机控制之前,我们需要先搭建好 Android SDK 的环境变量,使得 Terminal 能够调取、运行 adb 和 fastboot 指令。在 macOS 中搭建 Android SDK 的操作如下:
启动 Spotlight,输入「终端」找到 Terminal;
1. 在 Terminal 中输入cd ~,并按下回车执行,将 Terminal 中目录位置切换至目前登陆用户的「Home目录」位置;
2. 输入touch .bash_profile,并按下回车执行,创建出「.bash_profile」环境配置文件;
3. 输入open -e .bash_profile,并按下回车执行,编辑「.bash_profile」环境配置文件;
4. 输入路径
export PATH=$PATH:/Users/XLsn0w/Desktop/platform-tools
此时将会打开「.bash_profile」文件,在里面输入export PATH=$PATH:/Users/登陆用户名/存放的文件夹路径名称/platform-tools/代码。在此举个例子,若电脑登陆用户名为xlsn0w,且 Platform-tools 工具解压并放置在了「下载」文件夹,则此处需输入的代码为:export PATH=$PATH:/Users/xlsn0w/Downloads/platform-tools/,随后保存并关闭即可;
5. 输入source .bash_profile,并按下回车执行,执行创建好的环境配置。
完成上述几步简单的指令操作后,我们便完成了 Android SDK 的环境变量配置,往后运行 Platform-tools 工具的基础准备工作也已完成。
解锁 Bootloader
Bootloader 是我们在启动 Android 系统内核之前运行的底层模式,在这个底层模式下,我们能够对手机进行初始化硬件设备、建立内存空间映射图等操作。刷入官方工厂镜像等操作也是需要在这个模式下执行的。
(注意:此操作将清除手机中的所有资料,建议备份好手机中的所需资料后,再进行下述解锁 Bootloader 操作)
打开「开发者选项」:在「设置」中进入「关于手机」,持续点击「 版本号」7次;
依次打开「USB 调试」及「OEM 解锁」:在「设置」找到「开发者选项」,找到并打开对应选项。而 Pixel 用户需注意的是,「OEM 解锁」选项必须是在能够连接至 Google 服务器的联网状态才可打开;
随后进入 Bootloader 界面等候操作:将手机关机,随后同时按住「电源键+音量下键」,进入到 Bootloader 界面并使用数据线与电脑连接;
执行解锁 Bootloader 操作指令:在 macOS 打开 Terminal,并输入fastboot flashing unlock指令,手机将会提示你是否要解锁 Bootloader。
完成 Bootloader 解锁:随后按音量键选中「Yes」选项 ,并按下电源键确认,此时手机便完成了解锁 Bootloader,此时请勿关闭手机,我们将继续执行刷机操作。
完成刷入 Android 官方系统操作
完成了 Bootloader 解锁操作,我们现在可以执行刷入官方工厂镜像到手机了。
在 Finder 找到下载好的完整版工厂镜像,并确认已经解压完成;
在 Terminal 将路径切换至镜像文件夹中。假设我的文件夹路径为/Users/jackcivlie/Downloads/bullhead-opp1.170223.012/,则输入cd /Users/jackcivlie/Downloads/bullhead-opp1.170223.012/即可;
倘若对 macOS 文件夹路径不熟悉,难以辨别其路径位置的话,这里可以使用一个取巧的办法:先在 Terminal 中输入cd(注意「cd」后面有空格),并在 Finder 将镜像文件夹下拖拽任意一个文件到 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$
网友评论