How to specify the output directory when compiling Android?

0. Introduction

Occasionally, a friend asks how to specify the output directory when compiling Android?

There are two cases here:

One is how to change the Android default output directory out to another location?

The second is to specify the output directory of a module.

To set the Android default output directory, please refer to Section 1;

Set the Android dist compilation output directory, please refer to Section 2;

Set the compiled output directory of a certain Android module, please refer to Section 3;

How to find documents in the system, please refer to Section 4;

1. Specify the Android compilation output directory

For example, I now want to compile the image of Pixel 5a device (codename: barbet) based on the source code of android-12.0.0_r28.

The default output directory of Android is out, want to change the default output directory to out-barbet:

android-12.0.0_r28$ export OUT_DIR=out-barbet
android-12.0.0_r28$ source build/envsetup.sh 
android-12.0.0_r28$ lunch aosp_barbet-userdebug

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=12
TARGET_PRODUCT=aosp_barbet
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv8-a
TARGET_2ND_CPU_VARIANT=generic
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.4.0-54-generic-x86_64-Ubuntu-20.04.4-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=SQ1A.220205.002
OUT_DIR=out-barbet
PRODUCT_SOONG_NAMESPACES=hardware/google/av hardware/google/camera...
============================================
android-12.0.0_r28$ 

Here we can see that the output directory has been set to: OUT_DIR=out-barbet.

If you view the current compiled configuration in the environment after source, you can execute printconfig on the command line to view:

$ printconfig

2. Specify the Android dist compilation output directory

The Android build output directory OUT_DIR("out" by default) contains non-release files.

When you want to release a version, you usually compile the dist target. The default output path of this target is under "out/dist", which can DIST_DIRbe , as follows:

make aosp_barbet-userdebug dist DIST_DIR=dist-barbet

The dist here is the abbreviation of distribution, which literally means "publishing, distributing"

3. Specify the Android module compilation output directory

Sometimes you develop a module by yourself and want to compile and output the module to a specified directory (such as "/vendor/app"), or you want to store the compiled apk in the system's prefabricated app directory (such as "/system/ priv-app"), you can achieve this LOCAL_MODULE_PATHby .

Let's look at two examples that come with Android.

  • Compile and output the library librecovery_ui_extfile to a certain lib64or librecord .
# bootable/recovery/Android.mk

# librecovery_ui_ext (shared library)
# ===================================
include $(CLEAR_VARS)

LOCAL_MODULE := librecovery_ui_ext

# LOCAL_MODULE_PATH for shared libraries is unsupported in multiarch builds.
LOCAL_MULTILIB := first

ifeq ($(TARGET_IS_64_BIT),true)
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/lib64
else
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/lib
endif

LOCAL_WHOLE_STATIC_LIBRARIES := \
    $(TARGET_RECOVERY_UI_LIB)

LOCAL_SHARED_LIBRARIES := \
    libbase \
    liblog \
    librecovery_ui.recovery

include $(BUILD_SHARED_LIBRARY)

If it is a 64-bit target environment, output to a directory:

out/target/product/xxx/recovery/root/system/lib64

In other cases output to directory:

out/target/product/xxx/recovery/root/system/lib

  • Put the application LeanbackCustomizerinto the system preset directory system-privdirectory
# device/sample/apps/tv/LeanbackCustomizer/Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(PRODUCT_OUT)/system/priv-app

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_PACKAGE_NAME := LeanbackCustomizer

LOCAL_SDK_VERSION := current

include $(BUILD_PACKAGE)

4. Documents related to compilation in Android source code

In fact, there are some instructions on how to compile Android in the Android code, mainly as follows:

  • build/soong/README.md
    • The main entry of Android compilation related documentation
  • build/make/Usage.txt
    • Android compilation instructions
  • build/make/Changes.md
    • Android compilation and previous version changes
  • build/make/Deprecation.md
    • Some obsolete and no longer used settings in Android compilation
  • build/core/build-system.html
    • Android's previous compilation documentation is still worth a look

What if I can't remember the paths and names of these documents?

Or in addition to these documents, what should I do if I want to see how to use soong, kati, bazel, blueprint and other tools?

A find command can solve this problem. Execute the following find command in the root directory of the Android source code:

android-12.0.0_r28$ find build/ -type f -a \( -iname "*.md" -o -iname "*.txt" -o -iname "*.pdf" -o -iname "*.html" \)
build/make/target/board/generic_x86_64_arm64/README.txt
build/make/target/board/generic_arm64/README.txt
build/make/target/board/generic_x86/README.txt
build/make/target/board/generic_64bitonly_x86_64/README.txt
build/make/target/board/generic_x86_arm/README.txt
build/make/target/board/module_arm/README.md
build/make/target/board/module_arm64/README.md
build/make/target/board/generic_x86_64/README.txt
build/make/target/board/generic/README.txt
build/make/target/board/module_x86/README.md
build/make/target/board/module_x86_64/README.md
build/make/target/board/mainline_sdk/README.md
build/make/target/product/gsi/31.txt
build/make/target/product/gsi/current.txt
build/make/target/product/gsi/29.txt
build/make/target/product/gsi/28.txt
build/make/target/product/gsi/30.txt
build/make/target/product/virtual_ab_ota/README.md
build/make/Deprecation.md
build/make/README.md
build/make/core/build-system.html
build/make/navbar.md
build/make/tools/fs_config/README.md
build/make/tools/zipalign/README.txt
build/make/tools/docker/README.md
build/make/tools/rbcrun/README.md
build/make/tools/ziptime/README.txt
build/make/tools/releasetools/jarjar-rules.txt
build/make/tools/releasetools/testdata/apexkeys_framework.txt
build/make/tools/releasetools/testdata/apkcerts_framework.txt
build/make/tools/releasetools/testdata/apexkeys_vendor.txt
build/make/tools/releasetools/testdata/apexkeys_merge.txt
build/make/tools/releasetools/testdata/apkcerts_vendor.txt
build/make/tools/releasetools/testdata/apexkeys_framework_conflict.txt
build/make/tools/releasetools/testdata/apkcerts_merge.txt
build/make/Changes.md
build/make/Usage.txt
build/soong/README.md
build/soong/navbar.md
build/soong/java/lint_defaults.txt
build/soong/cc/config/integer_overflow_blocklist.txt
build/soong/python/scripts/stub_template_host.txt
build/soong/scripts/check_boot_jars/package_allowed_list.txt
build/soong/docs/map_files.md
build/soong/docs/best_practices.md
build/soong/docs/clion.md
build/soong/docs/compdb.md
build/soong/docs/perf.md
build/bazel/README.md
build/bazel/examples/queryview/README.md
build/bazel/examples/queryview/apex_available.txt
build/bazel/examples/queryview/nocrt.txt
build/bazel/examples/queryview/android_apps.txt
build/bazel/examples/queryview/libc.txt
build/bazel/bazel_skylib/README.md
build/bazel/rules_cc/README.md
build/bazel/json_module_graph/README.md
build/bazel/docs/concepts.md
build/blueprint/README.md
build/blueprint/CONTRIBUTING.md
build/pesto/experiments/prepare_bazel_test_env/README.md

The above find command searches for all files with the suffixes of md, txt, pdf and html in the build directory, basically including common document formats.

If you feel that it cannot meet your needs, then adjust this find command a little according to the situation.

Thinking questions:

There are m, mm, mmm commands when compiling Android. Can you find the instructions for using these commands in the Android code?

Guess you like

Origin blog.csdn.net/guyongqiangx/article/details/128973555