[Lenovo Zuk Z2 Pro Guides, News, & Discussion] InterfaceNode:
Requirements

- Linux Mint 18 XFCE

- 20GB SWAP

- 130 GB HDD space

Configuring the OS

When the OS is installed, open terminal and issue:

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update && mkdir ~/bin && PATH=~/bin:~/sdk/tools:~/sdk/platform-tools:~/sdk/build-tools:$PATH && sudo apt-get install curl bison build-essential curl flex git gnupg gperf libesd0-dev liblz4-tool libncurses5-dev libsdl1.2-dev libwxgtk3.0-dev libxml2 libxml2-utils lzop maven openjdk-7-jdk pngcrush repo schedtool squashfs-tools xsltproc zip zlib1g-dev g++-multilib gcc-multilib lib32ncurses5-dev lib32readline6-dev lib32z1-dev && curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo && chmod a+x ~/bin/repo

Download the Android SDK tools: https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz

Extract them to your home folder and rename the folder containing them to 'sdk', so it matches the path that was set.

After issue the following in terminal:

android

Update it and get all of the required things for the version of Android you're building.

Downloading the source

We'll use my own personal choice... Issue the following in terminal:

PATH=~/bin:~/sdk/tools:~/sdk/platform-tools:~/sdk/build-tools:$PATH && repo init -u git://github.com/SlimRoms/platform_manifest.git -b mm6.0

It will ask you to configure your git Username and PW, you can either do it or ignore it; it's your prerogative.

After issue into terminal:

repo sync

Prepare to wait for quite a few hours.

Understanding the Layout

The layout of AOSP or any android firmware looks like this:

[IMG="AOSP"]http://oi67.tinypic.com/2icbfdc.jpg[/IMG]

The important folders for basic building are the following:

- Device

[IMG="Device Configs"]http://oi66.tinypic.com/24edjyt.jpg[/IMG]

The configurations for your device files should follow this layout.

Device/OEMname/Devicename

In the case of Z2 Pro it is 'Device/Zuk/Z2pro'

- Kernel

[IMG="Woof"]http://oi65.tinypic.com/14act2x.jpg[/IMG]

Kernel/OEMname/kernelname

The name of the kernel is specified in the main makefile of the Device configurations.

The kernel can be called anything in reality...

Vendor is where the files we cannot generate from source go; they are proprietary files that have already been created and must be pulled from an already working ROM that shares the same HW as the phone you are developing for.

Device Makefile operations explained

In my SlimROM Z2 configurations, the main makefile of relevance here is slim.mk

# Props
PRODUCT_PACKAGES += \
libloc_api_v02 \
libthermalclient \
datastatusnotification \
QtiTelephonyService \
shutdownlistener \
TimeService \
CNEService \
com.qualcomm.location \
dpmserviceapp \
qcrilmsgtunnel \
QtiTetherService \
colorservice \
ims \
imssettings \
qcnvitems \
libtime_genoff \
libbtnv \
qcrilhook

Normally VENDOR files are defined in the vendor folder; but I have defined them here instead which is fine.

$(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/product/full_base_telephony.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/product/languages_full.mk)
$(call inherit-product, vendor/zuk/z2pro/z2pro-vendor.mk)

The inherit-product command adds an outside makefile to the main makefile.

By noticing 'inherit vendor z2pro-vendor.mk' we are observe that SlimROM will use the makefiles in Vendor that has been specified.

$(call inherit-product, vendor/slim/config/common_full_phone.mk)

As we can see, this 'Common_full_phone' config is generic, it should be used for every model.

Certain models will inherit certain makefiles; as this is a x64 phone we are using:

$(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)

This should be used on any x64 phone; things are quite generic across makefiles very few things are device-specific in reality.

Inside the device folder there is a .dependencies file; for example the contents of one file are as follows:

[
{
"repository": "android_device_qcom_common",
"target_path": "device/qcom/common"
},
{
"repository": "android_vendor_nxp-nfc_opensource_frameworks",
"target_path": "vendor/nxp-nfc/opensource/frameworks"
},
{
"repository": "android_vendor_nxp-nfc_opensource_libnfc-nci",
"target_path": "vendor/nxp-nfc/opensource/libnfc-nci"
},
{
"repository": "android_vendor_nxp-nfc_opensource_Nfc",
"target_path": "vendor/nxp-nfc/opensource/Nfc"
}
]

"target_path" will show you additional folders you may need from Github that are required for the device to function properly.

If you do not have your device dependencies it will not build, they must also be obtained.

Kernel explanation

Some kernels are useful across multiple devices; but how are they defined for an individual device?

They are defined with a file called 'defconfig', it is located here:

[IMG="Kernel"]http://oi68.tinypic.com/2igetxd.jpg[/IMG]

On a x86 device, we would use the ARM folder and not ARM64 but I digress. :P

In the 'Device' folder, there is a file called 'Boardconfig.mk', this is relevant to building the kernel.

TARGET_KERNEL_SOURCE := kernel/zuk/msm8996
TARGET_KERNEL_CONFIG := z2p_defconfig

TARGET_SOURCE = The kernel folder

TARGET_CONFIG = The defconfig for your device.

When trying to build with another kernel; the kernel author may be calling the defconfig something else so this field will need to be changed; or the name of the defconfig file will need to be changed.

I will not explain much about the 'Vendor' folder in this time, it requires higher-end methodology to determine what proprietary files a phone does and does not need.

Anyway, for the Z2 I have already made vendor configs so people here do not need to worry much about it although they are a little incomplete...

Understanding Github

Github is fantastic, rather than to mess around with terminal for pulling things from it I'd rather demystify it and for this reason am encouraging people to DL, unzip and stage things manually rather than to depend on .xmls

[IMG="Github"]http://oi66.tinypic.com/2n1i3vo.jpg[/IMG]

Notice "android_device_xiaomi_libra"

This is to say the contents of this git should end up in device/xiaomi/libra; you will need to create these folders and place the contents inside of them manually.

It is the same with kernel, and vendor files.

Building the OS

Now that device, kernel and vendor configurations are in place it's time to attempt a build, eh?

issue the following into terminal:

PATH=~/bin:~/sdk/tools:~/sdk/platform-tools:~/sdk/build-tools:$PATH && . build/envsetup.sh

The build engine will now start.

Issue the following:

breakfast z2

The breakfast command will prepare all the ingredients; if no error is thrown here next issue:

brunch z2

This will begin the building process for the Zuk Z2.

This will take a really long time to complete.