Android source code customization: remove useless lunch | create new lunch | customize customize.mk

Android source code is a huge code project, including several projects and hundreds of modules, as well as a variety of different hardware platforms and devices. In order to facilitate our selection of appropriate compilation options and configuration files when developing, Android provides a tool called lunch, which can be executed in the source code root directory, lists all available product combinations, and allows us to select one for compilation. Each product combination corresponds to a file such as device.mk, which defines the features and attributes of the product, such as device name, system properties, pre-installed applications, etc.

Obsessive-compulsive disorder like me needs to make some customizations to the Android source code, such as removing some unnecessary lunch options, adding some new lunch options, or modifying some product attributes. This article will introduce how to perform these operations and give some examples. The intention is to flexibly customize the project to avoid coupling.

Remove useless lunch project:

Get the Android source code. It is very annoying every time you compile and select lunch. There are a bunch of lunch options that we don’t need, such as some projects for other hardware platforms or devices, or some outdated or abandoned projects. These projects take up our disk space or interfere with our compilation process (sometimes they are selected incorrectly). In order to remove these useless lunch options, we need to do the following steps:

Step 1:

Open the build/make/target/product/AndroidProducts.mk file. This file is where all available product combinations are defined. In this file, find the COMMON_LUNCH_CHOICES variable. This variable is a list that contains all common lunch options. You can see that there are many options starting with aosp_ in this list, which are common Android systems for different architectures and modes. These are all natively included in the Google Android source code. We don’t need these options at all, just comment them out. For example:

 + + + b/build/make/target/product/AndroidProducts.mk
@@ -79,7 + 79,7 @@ PRODUCT_MAKEFILES + = \
     $(LOCAL_DIR)/module_x86.mk \
     $(LOCAL_DIR)/module_x86_64.mk \
 
-COMMON_LUNCH_CHOICES := \
 + #COMMON_LUNCH_CHOICES := \
     aosp_arm64-eng \
     aosp_arm-eng \
     aosp_x86_64-eng \

Step 2:

Open the device/rockchip/rk356x/AndroidProducts.mk file. This file is where all product combinations for the rk356x platform are defined. Find the PRODUCT_MAKEFILES variable and the COMMON_LUNCH_CHOICES variable in this file. These two variables are respectively a list containing the .mk file path and lunch of all product portfolios for the rk356x platform. Option name. As you can see, there are many options starting or ending with rk3566_ in these two lists. These are systems for different devices and modes of the rk3566 chip. If you only need a system with rk3568 chip, you can delete these options. For example:

 + + + b/device/rockchip/rk356x/AndroidProducts.mk
@@ -15,28 + 15,10 @@
 #
 
 PRODUCT_MAKEFILES := \
- $(LOCAL_DIR)/rk3566_sgo/rk3566_sgo.mk \
- $(LOCAL_DIR)/rk3566_32bit/rk3566_32bit.mk \
- $(LOCAL_DIR)/rk3566_r/rk3566_r.mk \
- $(LOCAL_DIR)/rk3566_s/rk3566_s.mk \
         $(LOCAL_DIR)/rk3568_s/rk3568_s.mk \
- $(LOCAL_DIR)/rk3566_eink/rk3566_eink.mk \
- $(LOCAL_DIR)/rk3566_einkw6/rk3566_einkw6.mk
 
 COMMON_LUNCH_CHOICES := \
- rk3566_32bit-userdebug \
- rk3566_32bit-user \
- rk3566_sgo-userdebug \
- rk3566_sgo-user \
- rk3566_r-userdebug \
- rk3566_r-user \
- rk3566_s-userdebug \
- rk3566_s-user \
     rk3568_s-userdebug \
     rk3568_s-user \
- rk3566_eink-userdebug \
- rk3566_eink-user \
- rk3566_einkw6-userdebug \
- rk3566_einkw6-user

Step 3:

Delete all unnecessary project folders in the device directory, such as device/amlogic and device/google. These folders may contain some source code and configuration files for other hardware platforms or devices, which are not required. For example:

rm -rf device/amlogic
rm -rf device/google
...

New customized lunch project:

Now that the code is customized, add some new customization or custom lunch options, such as targeting different versions or modes of the system for the same hardware platform or device. In order to add a new lunch option, do the following steps:

Step 1:

In the device/rockchip/rk356x directory, copy an existing product portfolio folder, such as rk3568_s, as the basis for a new product portfolio. Give this new folder a meaningful name, I will just give it a random name, such as rk3568_s_beta (the original meaning is for learning), which means that this is a beta system for the rk3568 chip. For example:

rk_android12.0_sdk/device/rockchip/rk356x$ cp -r rk3568_s/ rk3568_s_beta

Step 2:

In the new folder, rename the .mk file so that it is consistent with the folder name, otherwise an error will be reported when lunching again. For example:

rk_android12.0_sdk/device/rockchip/rk356x/rk3568_s_beta$ mv rk3568_s.mk rk3568_s_beta.mk

Step 3:

In the new folder, modify the contents of all files and replace the original product portfolio name with the new product portfolio name. For example:

rk_android12.0_sdk/device/rockchip/rk356x/rk3568_s_beta$ find . -type f | xargs sed -i 's/rk3568_s/rk3568_s_beta/g'

Step 4:

In the device/rockchip/rk356x/AndroidProducts.mk file, add the .mk file path and lunch option name of the new product portfolio to the corresponding list. For example:

 + + + b/device/rockchip/rk356x/AndroidProducts.mk
@@ -15,9 + 15,12 @@
 #
 
 PRODUCT_MAKEFILES := \
 + $(LOCAL_DIR)/rk3568_s_beta/rk3568_s_beta.mk \
         $(LOCAL_DIR)/rk3568_s/rk3568_s.mk
 
 COMMON_LUNCH_CHOICES := \
 + rk3568_s_beta-userdebug \
 + rk3568_s_beta-user \
     rk3568_s-userdebug \
     rk3568_s-user \

Customize customize.mk

Link: Android source code customization: add the customize.mk file for customization by project and customer

In addition to creating a new project lunch, although you can modify the device.mk under the project, I generally don’t want to modify the native things. What we do for customization is usually to modify the attributes of some product combinations, such as turning on or off some functions, compiling module, or adjust some parameter properties. In order to make these modifications conveniently, you can use a file named customize.mk. This file can contain some conditional judgments and attribute assignment statements for different product combinations. You can create a customize directory under the vendor directory and create a customize.mk file in it. Then, in the device/rockchip/rk356x/device.mk file, add a line of include vendor/customize/customize.mk so that the customize.mk file can be referenced in each product combination. The following steps need to be done:

Step 1:

Open the device/rockchip/rk356x/device.mk file and add a line of include vendor/customize/customize.mk statement in it. For example:

 + + + b/device/rockchip/rk356x/device.mk
@@ -2,6 + 2,7 @@
 # Copyright (c) 2020 Rockchip Electronics Co., Ltd
 #
 
 + include vendor/customize/customize.mk
 include $(CLEAR_VARS)
 include $(call all-makefiles-under,$(LOCAL_PATH))

Step 2:

In the vendor directory, create a customize directory and create a customize.mk file in it. For example:

rk_android12.0_sdk$ mkdir vendor/customize/
rk_android12.0_sdk$ touch vendor/customize/customize.mk

Step 3:

In the customize.mk file, write some conditional judgments and attribute assignment statements for different product combinations. We can use ifeq, else, endif and other keywords to make conditional judgments, and use symbols such as + = or := to assign attributes. You can also use the $(warning…) statement to print some prompt information to facilitate our debugging and verification. For example:

# in customize.mk
include $(call all-subdir-makefiles)
$(warning Enter customize.mk is included $(TARGET_PRODUCT))

ifeq ($(TARGET_PRODUCT),rk3568_s_beta)
$(warning Enter rk3568_s_beta)

PRODUCT_PROPERTY_OVERRIDES + = persist.internet_adb_enable=1
PRODUCT_PROPERTY_OVERRIDES + = persist.vendor.orientation=0
endif

The meaning of this code is that if the currently selected product portfolio is rk3568_s_beta, then add two attributes to the product portfolio, which are to enable the network adb function and set the screen orientation to 0 degrees (just write two sentences to express the meaning and usage Same as device.mk etc.).

Step 4:

OK After finishing the previous things, we must re-execute the . build/envsetup.sh & amp; & amp; lunch command to select a product combination for compilation. It can be seen that when the lunch command is executed, the prompt information we set in the customize.mk file will be printed, indicating that the customize.mk file has been referenced in the product portfolio, and the corresponding attribute assignment statement has been executed based on the condition. . For example:

ln28@ln28-pc:~/sourcecode/rk_android12.0_sdk$ . build/envsetup.sh
ln28@ln28-pc:~/sourcecode/rk_android12.0_sdk$ lunch

You're building on Linux

Lunch menu... pick a combo:
     1.rk3568_s-user
     2. rk3568_s-userdebug
     3. rk3568_s_beta-user
     4. rk3568_s_beta-userdebug

Which would you like? [aosp_arm-eng] 4
vendor/customize/customize.mk:3: warning: Enter customize.mk is included rk3568_s_beta
vendor/customize/customize.mk:6: warning: Enter rk3568_s_beta

At this point, we have completed some basic customization of a source code, removed useless lunch options, added new lunch options, and customized ustomize.mk. You can carry out more customization and optimization according to your own needs and preferences to create your own Android system.

I hope this article can be helpful to you. If you have any questions or suggestions, please leave a message in the comment area. Thanks!