Android:编译系统总结

总结一下android的编译系统

一.Android的编译脚本在哪里?

在build/core目录下,使用的是makefile的方式。入口是main.mk。
一般我们执行make去编译。
在根目录下可以看到一个Makefile,这个就是入口了。


image.png

看一下编译的目标:


image.png

第一个定义的PHONY就是目标了。所以目标是droid

TARGET_BUILD_TYPE和TARGET_BUILD_VARIANT的区别

1.TARGET_BUILD_VARIANT:表示编译产品的类型,可能的值有eng、user和userdebug
adb的属性就是通过这个来设置的


image.png

2.TARGET_BULD_TYPE:表示编译的类型,可选的值是release和debug

PRODUCT_PACKAGES怎样控制编译到img中的?

在build/core/main.mk中,

product_MODULES := $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES)
product_FILES := $(call module-installed-files, $(product_MODULES))
modules_to_install := $(sort \
    $(ALL_DEFAULT_INSTALLED_MODULES) \
    $(product_FILES) \
    $(foreach tag,$(tags_to_install),$($(tag)_MODULES)) \
    $(CUSTOM_MODULES) \
  )

droidcore: files \
    systemimage \
    $(INSTALLED_BOOTIMAGE_TARGET) \
    $(INSTALLED_RECOVERYIMAGE_TARGET) \
    $(INSTALLED_VBMETAIMAGE_TARGET) \
    $(INSTALLED_USERDATAIMAGE_TARGET) \
    $(INSTALLED_CACHEIMAGE_TARGET) \
    $(INSTALLED_BPTIMAGE_TARGET) \
    $(INSTALLED_VENDORIMAGE_TARGET) \
    $(INSTALLED_SYSTEMOTHERIMAGE_TARGET) \
    $(INSTALLED_FILES_FILE) \
    $(INSTALLED_FILES_FILE_VENDOR) \
    $(INSTALLED_FILES_FILE_SYSTEMOTHER)

# Building a full system-- the default is to build droidcore
droid_targets: droidcore dist_files

编译系统初始化过程

主要是设置了一些产品product的变量。
参考:http://www.lupaworld.com/article-235956-3.html

makefile依赖中的竖线

ninja编译系统

脚本在build/soong/ui/build下
main.go (main函数) ->build.go(Build函数)

build/soong/soong_ui.bash --make-mode

ninja的go语言

//返回所给路径的绝对路径
path, _ := filepath.Abs("./1.txt");

ALL_MODULE

http://android.cloudchou.com/build/core/base_rules.html

INTERNAL_PRODUCT是什么?

是一个mk文件,例如
INTERNAL_PRODUCT=device/huawei/XXX/full_huawei.mk

如何编译apk删除apk内部的dex文件?

通过方法dexpreopt-remove-classes.dex实现

客制化img编译流程是怎样的?

1.在build_custom_images.mk中给PRODUCT_CUSTOM_IMAGE_MAKEFILES赋值若干个makefile
build_custom_images.mk
PRODUCT_CUSTOM_IMAGE_MAKEFILES :=
XXX.mk

2.遍历每一个makefile,执行build_custom_image.mk
(PRODUCT_CUSTOM_IMAGE_MAKEFILES),
(mk))
(BUILD_SYSTEM)/tasks/tools/build_custom_image.mk))

$(call clear-var-list, $(custom_image_parameter_variables))   ##清理环境遍历

include $(my_custom_imag_makefile)  ##执行我们定义的makefile,这个makefile中指定了分区的大小等信息

my_custom_image_name := $(basename $(notdir $(my_custom_imag_makefile))) ##分区的名字,去makefile的名字

intermediates := $(call intermediates-dir-for,PACKAGING,$(my_custom_image_name))  ##中间目录
my_built_custom_image := $(intermediates)/$(my_custom_image_name).img  ##生成的img
my_staging_dir := $(intermediates)/$(CUSTOM_IMAGE_MOUNT_POINT)   ##中间目录 例如huawei_product/produtc/

# Collect CUSTOM_IMAGE_MODULES's installd files and their PICKUP_FILES.
my_built_modules :=                       ##安装的module
my_copy_pairs :=                          ##需要拷贝的文件
my_pickup_files :=                        ##需要pickup的文件

#$(ALL_MODULES.$(m).BUILT_INSTALLED)的格式是 源地址:目标地址 的格式,类似于out/target/product/sdm660_64/obj/APPS/Camera.apk_intermediates/package.apk:out/target/product/sdm660_64/system/app/Camera/Camera.apk
#因此需要分割出来,ins代表目标地址,bui代表源地址或者中间文件地址
$(foreach m,$(CUSTOM_IMAGE_MODULES),\
  $(eval _pickup_files := $(strip $(ALL_MODULES.$(m).PICKUP_FILES)\
    $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).PICKUP_FILES)))\
  $(eval _built_files := $(strip $(ALL_MODULES.$(m).BUILT_INSTALLED)\
    $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).BUILT_INSTALLED)))\
  $(if $(_pickup_files)$(_built_files),,\
    $(warning Unknown installed file for module '$(m)'))\
  $(eval my_pickup_files += $(_pickup_files))\
  $(foreach i, $(_built_files),\
    $(eval bui_ins := $(subst :,$(space),$(i)))\
    $(eval ins := $(word 2,$(bui_ins)))\
    $(if $(filter $(TARGET_OUT_ROOT)/%,$(ins)),\
      $(eval bui := $(word 1,$(bui_ins)))\
      $(eval my_built_modules += $(bui))\
      $(eval my_copy_dest := $(patsubst $(PRODUCT_OUT)/%,%,$(ins)))\
      $(eval my_copy_dest := $(subst /,$(space),$(my_copy_dest)))\
      $(eval my_copy_dest := $(wordlist 2,999,$(my_copy_dest)))\
      $(eval my_copy_dest := $(subst $(space),/,$(my_copy_dest)))\
      $(eval my_copy_pairs += $(bui):$(my_staging_dir)/$(my_copy_dest)))\
  ))

# Collect CUSTOM_IMAGE_COPY_FILES.
my_image_copy_files :=
$(foreach f,$(CUSTOM_IMAGE_COPY_FILES),\
  $(eval pair := $(subst :,$(space),$(f)))\
  $(eval src := $(word 1,$(pair)))\
  $(eval my_image_copy_files += $(src))\
  $(eval my_copy_pairs += $(src):$(my_staging_dir)/$(word 2,$(pair))))

ifndef CUSTOM_IMAGE_AVB_KEY_PATH
# If key path isn't specified, use the default signing args.
my_avb_signing_args := $(INTERNAL_AVB_SIGNING_ARGS)
else
my_avb_signing_args := \
  --algorithm $(CUSTOM_IMAGE_AVB_ALGORITHM) --key $(CUSTOM_IMAGE_AVB_KEY_PATH)
endif

$(my_built_custom_image): PRIVATE_INTERMEDIATES := $(intermediates)
$(my_built_custom_image): PRIVATE_MOUNT_POINT := $(CUSTOM_IMAGE_MOUNT_POINT)
$(my_built_custom_image): PRIVATE_PARTITION_SIZE := $(CUSTOM_IMAGE_PARTITION_SIZE)
$(my_built_custom_image): PRIVATE_FILE_SYSTEM_TYPE := $(CUSTOM_IMAGE_FILE_SYSTEM_TYPE)
$(my_built_custom_image): PRIVATE_STAGING_DIR := $(my_staging_dir)
$(my_built_custom_image): PRIVATE_COPY_PAIRS := $(my_copy_pairs)
$(my_built_custom_image): PRIVATE_PICKUP_FILES := $(my_pickup_files)
$(my_built_custom_image): PRIVATE_SELINUX := $(CUSTOM_IMAGE_SELINUX)
$(my_built_custom_image): PRIVATE_SUPPORT_VERITY := $(CUSTOM_IMAGE_SUPPORT_VERITY)
$(my_built_custom_image): PRIVATE_SUPPORT_VERITY_FEC := $(CUSTOM_IMAGE_SUPPORT_VERITY_FEC)
$(my_built_custom_image): PRIVATE_VERITY_KEY := $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY)
$(my_built_custom_image): PRIVATE_VERITY_BLOCK_DEVICE := $(CUSTOM_IMAGE_VERITY_BLOCK_DEVICE)
$(my_built_custom_image): PRIVATE_DICT_FILE := $(CUSTOM_IMAGE_DICT_FILE)
$(my_built_custom_image): PRIVATE_AVB_AVBTOOL := $(AVBTOOL)
$(my_built_custom_image): PRIVATE_AVB_SIGNING_ARGS := $(my_avb_signing_args)
$(my_built_custom_image): PRIVATE_AVB_HASH_ENABLE := $(CUSTOM_IMAGE_AVB_HASH_ENABLE)
$(my_built_custom_image): PRIVATE_AVB_ADD_HASH_FOOTER_ARGS := $(CUSTOM_IMAGE_AVB_ADD_HASH_FOOTER_ARGS)
$(my_built_custom_image): PRIVATE_AVB_HASHTREE_ENABLE := $(CUSTOM_IMAGE_AVB_HASHTREE_ENABLE)
$(my_built_custom_image): PRIVATE_AVB_ADD_HASHTREE_FOOTER_ARGS := $(CUSTOM_IMAGE_AVB_ADD_HASHTREE_FOOTER_ARGS)
ifeq (true,$(filter true, $(CUSTOM_IMAGE_AVB_HASH_ENABLE) $(CUSTOM_IMAGE_AVB_HASHTREE_ENABLE)))
  $(my_built_custom_image): $(AVBTOOL)
else ifneq (,$(filter true, $(CUSTOM_IMAGE_AVB_HASH_ENABLE) $(CUSTOM_IMAGE_AVB_HASHTREE_ENABLE)))
  $(error Cannot set both CUSTOM_IMAGE_AVB_HASH_ENABLE and CUSTOM_IMAGE_AVB_HASHTREE_ENABLE to true)
endif
ifeq (true,$(CUSTOM_IMAGE_SUPPORT_VERITY_FEC))
  $(my_built_custom_image): $(FEC)
endif
my_custom_image_modules_var:=BOARD_$(strip $(call to-upper,$(my_custom_image_name)))_KERNEL_MODULES
my_custom_image_modules:=$($(my_custom_image_modules_var))
my_custom_image_modules_dep:=$(if $(my_custom_image_modules),$(my_custom_image_modules) $(DEPMOD),)
$(my_built_custom_image): PRIVATE_KERNEL_MODULES := $(my_custom_image_modules)
$(my_built_custom_image): PRIVATE_IMAGE_NAME := $(my_custom_image_name)
$(my_built_custom_image): $(INTERNAL_USERIMAGES_DEPS) $(my_built_modules) $(my_image_copy_files) $(my_custom_image_modules_dep) \
  $(CUSTOM_IMAGE_DICT_FILE)
    @echo "Build image $@"
    $(hide) rm -rf $(PRIVATE_INTERMEDIATES) && mkdir -p $(PRIVATE_INTERMEDIATES)  ##删除中间目录,并且重新穿件
    $(hide) rm -rf $(PRIVATE_STAGING_DIR) && mkdir -p $(PRIVATE_STAGING_DIR)
    # Copy all the files.
    $(hide) $(foreach p,$(PRIVATE_COPY_PAIRS),\                              ##拷贝CUSTOM_IMAGE_COPY_FILES定义的拷贝文件
              $(eval pair := $(subst :,$(space),$(p)))\
              mkdir -p $(dir $(word 2,$(pair)));\
              cp -Rf $(word 1,$(pair)) $(word 2,$(pair));)
    $(if $(PRIVATE_KERNEL_MODULES), \
        $(call build-image-kernel-modules,$(PRIVATE_KERNEL_MODULES),$(PRIVATE_STAGING_DIR),$(PRIVATE_IMAGE_NAME)/,$(call intermediates-dir-for,PACKAGING,depmod_$(PRIVATE_IMAGE_NAME))))
    $(if $($(PRIVATE_PICKUP_FILES)),$(hide) cp -Rf $(PRIVATE_PICKUP_FILES) $(PRIVATE_STAGING_DIR))  ##拷贝PRIVATE_PICKUP_FILES文件
    # Generate the dict.
    $(hide) echo "# For all accepted properties, see BuildImage() in tools/releasetools/build_image.py" > $(PRIVATE_INTERMEDIATES)/image_info.txt ##往image_info.txt记录信息
    $(hide) echo "mount_point=$(PRIVATE_MOUNT_POINT)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt
    $(hide) echo "partition_name=$(PRIVATE_MOUNT_POINT)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt
    $(hide) echo "fs_type=$(PRIVATE_FILE_SYSTEM_TYPE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt
    $(hide) echo "partition_size=$(PRIVATE_PARTITION_SIZE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt
    $(hide) echo "ext_mkuserimg=$(notdir $(MKEXTUSERIMG))" >> $(PRIVATE_INTERMEDIATES)/image_info.txt
    $(if $(PRIVATE_SELINUX),$(hide) echo "selinux_fc=$(SELINUX_FC)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt)
    $(if $(PRIVATE_SUPPORT_VERITY),\
      $(hide) echo "verity=$(PRIVATE_SUPPORT_VERITY)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\
        echo "verity_key=$(PRIVATE_VERITY_KEY)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\
        echo "verity_signer_cmd=$(VERITY_SIGNER)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\
        echo "verity_block_device=$(PRIVATE_VERITY_BLOCK_DEVICE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt)
    $(if $(PRIVATE_SUPPORT_VERITY_FEC),\
      $(hide) echo "verity_fec=$(PRIVATE_SUPPORT_VERITY_FEC)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt)
    $(hide) echo "avb_avbtool=$(PRIVATE_AVB_AVBTOOL)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt
    $(hide) echo "avb_signing_args=$(PRIVATE_AVB_SIGNING_ARGS)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt
    $(if $(PRIVATE_AVB_HASH_ENABLE),\
      $(hide) echo "avb_hash_enable=$(PRIVATE_AVB_HASH_ENABLE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\
        echo "avb_add_hash_footer_args=$(PRIVATE_AVB_ADD_HASH_FOOTER_ARGS)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt)
    $(if $(PRIVATE_AVB_HASHTREE_ENABLE),\
      $(hide) echo "avb_hashtree_enable=$(PRIVATE_AVB_HASHTREE_ENABLE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\
        echo "avb_add_hashtree_footer_args=$(PRIVATE_AVB_ADD_HASHTREE_FOOTER_ARGS)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt)
    $(if $(PRIVATE_DICT_FILE),\
      $(hide) echo "# Properties from $(PRIVATE_DICT_FILE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\
        cat $(PRIVATE_DICT_FILE) >> $(PRIVATE_INTERMEDIATES)/image_info.txt)
    # Generate the image.
    $(if $(filter oem,$(PRIVATE_MOUNT_POINT)), \
      $(hide) echo "oem.buildnumber=$(BUILD_NUMBER)" >> $(PRIVATE_STAGING_DIR)/oem.prop)
    $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \           ##生成img
      ./build/tools/releasetools/build_image.py \
      $(PRIVATE_STAGING_DIR) $(PRIVATE_INTERMEDIATES)/image_info.txt $@ $(TARGET_OUT)

my_installed_custom_image := $(PRODUCT_OUT)/$(notdir $(my_built_custom_image))  ##将img拷贝到PRODUCT_OUT目录
$(my_installed_custom_image) : $(my_built_custom_image)
    $(call copy-file-to-new-target-with-cp)

.PHONY: $(my_custom_image_name)
custom_images $(my_custom_image_name) : $(my_installed_custom_image)

# Archive the built image.
$(call dist-for-goals, $(my_custom_image_name) custom_images,$(my_installed_custom_image))

my_staging_dir :=
my_built_modules :=
my_copy_dest :=
my_copy_pairs :=
my_pickup_files :=

Jack编译报错ssl

解决方式是java需要使能ssl,参考
https://blog.csdn.net/qq_43617656/article/details/116900785

你可能感兴趣的:(Android:编译系统总结)