Pixel1 源码编译

记录自己Pixel1刷机流程.

相关网站

Requirements
https://source.android.google.cn/setup/build/requirements.html#binaries

https://source.android.com/setup/build/running

buile numbers
https://source.android.com/setup/start/build-numbers

https://source.android.com/setup/build/downloading

驱动
https://developers.google.com/android/drivers

ota, image #

刷机使用. 不需要编译源码, 直接刷机.

下载刷机包

https://developers.google.com/android/images

https://developers.google.com/android/ota

刷入:

$sudo ./flash_all.sh

源码下载 #

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-6.0.1_r77
repo sync -j8

适用于pixel 的: NZH54D android-7.1.2_r33 OPM4.171019.021.P1 android-8.1.0_r38

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-7.1.2_r33

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-8.1.0_r38

编译 #

直接编译userdebug版本, 方便我们调试

安装jdk

sudo add-apt-repository ppa:openjdk-r/ppa  
sudo apt-get update   
sudo apt-get install openjdk-7-jdk  

编译, 如果要刷真机的话, 需要提前下载驱动到源码目录, 并解压之后运行.sh, ACCEPT后释放出来驱动相关文件.(https://developers.google.com/android/drivers)

$source ./build/envsetup.sh
$lunch
编译全部源码
$make -j12 
编译某个module
$make -j12 libart_32

输入系统

这里不需要sudo 
$fastboot flashall -w

root #

root无源码的机型.

  1. 解锁boot
  2. 刷入twrp
  3. 装入supersu.apk
  4. 重启

https://gist.github.com/rhyttr/931f5f14f40793a45170809bec6ca62a

# Download latest Android image, "hammerhead" for Nexus 5 (GSM/LTE)
https://developers.google.com/android/nexus/images#hammerhead

# Download latest TWRP
https://dl.twrp.me/hammerhead/

# Download latest SuperSu
https://download.chainfire.eu/supersu

Enable USB debugging.
Reboot into bootloader (power off, volume down + power on or sudo adb reboot-bootloader)
# Wait for boot loader to start
# Install factory ROM:
unzip hammerhead-m4b30z-factory-625c027b.zip
cd hammerhead-m4b30z
unzip image-hammerhead-m4b30z.zip
fastboot flash bootloader bootloader-hammerhead-hhz20h.img
fastboot reboot-bootloader #or power off/start bootloader
fastboot flash radio radio-hammerhead-m8974a-2.0.50.2.30.img
fastboot flash boot boot.img
fastboot flash cache cache.img
fastboot flash system system.img
# add params -S 256M if remaining memory is not enough . eg: sudo fastboot flash -S 256M system system.img
fastboot flash recovery recovery.img
fastboot reboot

# Wait boot to finish for application upgrade.
adb push SR1-SuperSU-v2.82-SR1-20170608224931.zip /sdcard/
adb reboot-bootloader

# [Wait for bootloader to start]
adb start-server
fastboot flash recovery twrp-3.1.1-0-hammerhead.img
fastboot reboot-bootloader
# on the screen, Navigate into Recovery mode (Reboot) -> Install -> zip, select SR3-SuperSU-v2.79-SR3-20170114223742.zip -> Swipe to confirm Flash
# Reboot System

调试 #

更改system分区读写权限

$adb disable verity
$mount -o remount,rw /system

emulator测试 #

  1. 列出创建avd
emulator -list-avd
  1. emulator 启动avd
$emulator -avd PixelN
  1. 使system分区可写
$emulator -writable-system -avd PixelN
启动之后
$adb remount

n. help

~$ emulator -help
ndroid Emulator usage: emulator [options] [-qemu args]
 options:
   -list-avds                      list available AVDs
   -sysdir <dir>                   search for system disk images in <dir>
   -system <file>                  read initial system image from <file>
   -vendor <file>                  read initial vendor image from <file>
   -writable-system                make system & vendor image writable after 'adb remount'
   -datadir <dir>                  write user data into <dir>
   -kernel <file>                  use specific emulated kernel
   -ramdisk <file>                 ramdisk image (default <system>/ramdisk.img
   -image <file>                   obsolete, use -system <file> instead
   -initdata <file>                same as '-init-data <file>'
   -data <file>                    data image (default <datadir>/userdata-qemu.img
   -encryption-key <file>          read initial encryption key image from <file>
   -logcat-output <file>           output file of logcat(default none)
   -partition-size <size>          system/data partition size in MBs
   -cache <file>                   cache partition image (default is temporary file)
   -cache-size <size>              cache partition size in MBs
   -no-cache                       disable the cache partition
   -nocache                        same as -no-cache
   -sdcard <file>                  SD card image (default <datadir>/sdcard.img
   -quit-after-boot <timeout>      qeuit emulator after guest boots completely, or after timeout in seconds
   -snapstorage <file>             file that contains all state snapshots (default <datadir>/snapshots.img)
   -no-snapstorage                 do not mount a snapshot storage file (this disables all snapshot functionality)
   -snapshot <name>                name of snapshot within storage file for auto-start and auto-save (default 'default-boot')
   -no-snapshot                    perform a full boot and do not auto-save, but qemu vmload and vmsave operate on snapstorage
   -no-snapshot-save               do not auto-save to snapshot on exit: abandon changed state
   -no-snapshot-load               do not auto-start from snapshot: perform a full boot
   -snapshot-list                  show a list of available snapshots
   -no-snapshot-update-time        do not try to correct snapshot time on restore
   -wipe-data                      reset the user data image (copy it from initdata)
   -avd <name>                     use a specific android virtual device
   -skindir <dir>                  search skins in <dir> (default <system>/skins)
   -skin <name>                    select a given skin
   -no-skin                        deprecated: create an AVD with no skin instead
   -noskin                         same as -no-skin
   -memory <size>                  physical RAM size in MBs
   -cores <number>                 Set number of CPU cores to emulator
   -accel <mode>                   Configure emulation acceleration
   -no-accel                       Same as '-accel off'
   -ranchu                         Use new emulator backend instead of the classic one
   -engine <engine>                Select engine. auto|classic|qemu2
   -netspeed <speed>               maximum network download/upload speeds
   -netdelay <delay>               network latency emulation
   -netfast                        disable network shaping
   -code-profile <name>            enable code profiling
   -show-kernel                    display kernel messages
   -shell                          enable root shell on current terminal
   -no-jni                         disable JNI checks in the Dalvik runtime
   -nojni                          same as -no-jni
   -logcat <tags>                  enable logcat output with given tags
   -use-system-libs                Use system libstdc++ instead of bundled one
   -bluetooth <vendorid:productid> forward bluetooth to vendorid:productid
   -no-audio                       disable audio support
   -noaudio                        same as -no-audio
   -audio <backend>                use specific audio backend
   -radio <device>                 redirect radio modem interface to character device
   -port <port>                    TCP port that will be used for the console
   -ports <consoleport>,<adbport>  TCP ports used for the console and adb bridge
   -onion <image>                  use overlay PNG image over screen
   -onion-alpha <%age>             specify onion-skin translucency
   -onion-rotation 0|1|2|3         specify onion-skin rotation
   -dpi-device <dpi>               specify device's resolution in dpi (default 165)
   -scale <scale>                  scale emulator window (deprecated)
   -http-proxy <proxy>             make TCP connections through a HTTP/HTTPS proxy
   -timezone <timezone>            use this timezone instead of the host's default
   -dns-server <servers>           use this DNS server(s) in the emulated system
   -net-tap <interface>            use this TAP interface for networking
   -net-tap-script-up <script>     script to run when the TAP interface goes up
   -net-tap-script-down <script>   script to run when the TAP interface goes down
   -cpu-delay <cpudelay>           throttle CPU emulation
   -no-boot-anim                   disable animation for faster boot
   -no-window                      disable graphical window display
   -no-sim                         device has no SIM card
   -lowram                         device is a low ram device
   -version                        display emulator version number
   -report-console <socket>        report console port to remote socket
   -gps <device>                   redirect NMEA GPS to character device
   -shell-serial <device>          specific character device for root shell
   -tcpdump <file>                 capture network packets to file
   -bootchart <timeout>            enable bootcharting
   -charmap <file>                 use specific key character map
   -studio-params <file>           used by Android Studio to provide parameters
   -prop <name>=<value>            set system property on boot
   -shared-net-id <number>         join the shared network, using IP address 10.1.2.<number>
   -nand-limits <nlimits>          enforce NAND/Flash read/write thresholds
   -gpu <mode>                     set hardware OpenGLES emulation mode
   -camera-back <mode>             set emulation mode for a camera facing back
   -camera-front <mode>            set emulation mode for a camera facing front
   -webcam-list                    lists web cameras available for emulation
   -screen <mode>                  set emulated screen mode
   -selinux <disabled|permissive>  Set SELinux to either disabled or permissive mode
   -unix-pipe <path>               Add <path> to the list of allowed Unix pipes
   -fixed-scale                    Use fixed 1:1 scale for the initial emulator window.
   -wait-for-debugger              Pause on launch and wait for a debugger process to attach before resuming
   -skip-adb-auth                  Skip adb authentication dialogue
   -metrics-to-console             Enable usage metrics and print the messages to stdout
   -metrics-to-file <file>         Enable usage metrics and write the messages into specified file
   -feature <name|-name>           Force-enable or disable (-name) the features
   -sim-access-rules-file <file>   Use SIM access rules from specified file
   -phone-number-prefix <string>   Number to use as the emulator's phone number prefix

    -qemu args...                  pass arguments to qemu
    -qemu -h                       display qemu help

    -verbose                       same as '-debug-init'
    -debug <tags>                  enable/disable debug messages
    -debug-<tag>                   enable specific debug messages
    -debug-no-<tag>                disable specific debug messages

    -help                          print this help
    -help-<option>                 print option-specific help

    -help-disk-images              about disk images
    -help-debug-tags               debug tags for -debug <tags>
    -help-char-devices             character <device> specification
    -help-environment              environment variables
    -help-virtual-device           virtual device management
    -help-sdk-images               about disk images when using the SDK
    -help-build-images             about disk images when building Android
    -help-all                      prints all help content