This SO post has a good explanation of what `afterEvaluate` does. Just a quote:

The afterEvaluate is useful in the root gradle file of a multi project build when you want to configure specific items based on the configuration made in subprojects

  1. Connect through USB
  2. adb devices
  3. adb tcpip 5555
  4. Disconnect from USB, and find IP_address of the Android device
  5. adb connect IP_address:5555
    e.g. adb connect 192.168.1.100:5555
  6. adb devices, and the devices shows as e.g. 192.168.1.100:5555

Note: FIRST read this thread on XDA to determine which boot-to-root to download. As of today (2017-01-24), I used v2.78 SR3 for non-TWRP.

1. In Developer options, enable OEM unlocking

2. Unlock bootloader (this only works on Pixel directly bought from Google, not carrier versions):
(a) boot into bootloader mode:

adb reboot bootloader

(b)

fastboot flashing unlock

then confirm on phone

3. Download boot-to-root image from Chainfire (read this thread on XDA to determine the download version), then

fastboot boot boot-to-root.img

Note: after root, if Pixel is stuck in the booting process (e.g. because wrong version of boot-to-root.img is used), flash the factory boot.img from Google (fastboot flash boot boot.img), normal reboot, and repeat Step 3 above.

This procedure works on macOS 10.12.2

Establishing build environment:
1. Creating a case-sensitive disk image

hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 100g ~/android.dmg

2. Mount the image

hdiutil attach ~/android.dmg.sparseimage -mountpoint /Volumes/android

Continue reading