编译 Android 时如何指定输出目录?
Posted 洛奇看世界
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了编译 Android 时如何指定输出目录?相关的知识,希望对你有一定的参考价值。
文章目录
0. 导读
偶尔会有朋友问编译 android 时如何指定输出目录?
这里有两种情况:
一是如何将 Android 默认的输出目录 out 改到其它位置?
二是指定某个模块的输出目录。
设置 Android 默认输出的目录,请参考第 1 节;
设置 Android dist 编译输出目录,请参考第 2 节;
设置 Android 某个模块的编译输出目录,请参考第 3 节;
如何查找系统中的文档,请参考第 4 节;
1. 指定 Android 编译输出目录
比如我现在要基于 android-12.0.0_r28 的源码编译 Pixel 5a 设备(代号: barbet)的 image。
Android 默认的输出目录为 out
,想将默认的输出目录修改为 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$
在这里我们能够看到,输出目录已经设置为: OUT_DIR=out-barbet
了。
如果在 source 以后的环境中查看当前编译的配置,可以在命令行执行 printconfig 查看:
$ printconfig
2. 指定 Android dist 编译输出目录
Android 编译输出目录 OUT_DIR
(默认为 “out”)存放的是非发布的文件。
当你要发布版本时,通常会编译 dist 目标,这个目标默认输出路径在 “out/dist” 下,可以通过设置 DIST_DIR
进行修改,如下:
make aosp_barbet-userdebug dist DIST_DIR=dist-barbet
这里的 dist 是 distribution 的简称,字面意思是“发布、分发”
3. 指定 Android 模块编译输出目录
有时候自己开发一个模块,想把这个模块编译输出到指定目录下(例如 “/vendor/app”),或者已经编译好的 apk,想存放到系统预制的 app 目录下(例如: “/system/priv-app”),可以通过修改模块对应 Android.mk 中的变量 LOCAL_MODULE_PATH
来达到这个目的。
我们看两个 Android 自带的例子吧。
- 将库文件
librecovery_ui_ext
编译输出到某个lib64
或lib
录下。
# 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)
如果是 64 位的目标环境,则输出到目录:
out/target/product/xxx/recovery/root/system/lib64
其它情况输出到目录:
out/target/product/xxx/recovery/root/system/lib
- 将应用
LeanbackCustomizer
放到系统预置目录system-priv
目录中
# 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. Android 源码中编译相关的文档
其实在 Android 代码中有包含一些如何编译 Android 的说明文档,主要有以下几个:
- build/soong/README.md
- Android 编译相关说明文档的主入口
- build/make/Usage.txt
- Android 编译说明
- build/make/Changes.md
- Android 编译和上一版本的改变
- build/make/Deprecation.md
- Android 编译中一些过时的不再使用的设置
- build/core/build-system.html
- Android 以前的编译说明文档,也仍然值得一看
记不住这些文档的路径和名字怎么办?
又或者除了这些文档,想看下 soong, kati, bazel, blueprint 等其它工具要如何使用该怎么办?
一条 find 命令即可解决这个问题,在 Android 源码的根目录下执行下面这条 find 命令:
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
上面这条 find 命令查找 build 目录下所有后缀为 md, txt, pdf 和 html 的文件,基本上包含了常用的文档格式。
如果觉得不能满足需要,那就根据情况将这条 find 命令稍微调整一下吧。
思考题:
Android 编译时有 m, mm, mmm 这些命令,你能在 Android 代码中找到这些命令的使用说明吗?
Linux内核编译输出到指定目录
1. 创建编译路径
mkdir output
OUTPUT_PATH=$PWD/output
2. 编译配置
手动copy来替换make xxx_defconfig:
cp -v arch/arm/configs/imx_atk_emmc_defconfig $OUTPUT_PATH/.config
menuconfig配置:
make menuconfig O=$OUTPUT_PATH
3. 编译
make O=$OUTPUT_PATH all -j16
编译完成之后的输出目录如图:
以上是关于编译 Android 时如何指定输出目录?的主要内容,如果未能解决你的问题,请参考以下文章
怎么改变android studio中库的aar文件的输出目录
在eclipse中编译的Android文件,如何指定它在哪个虚拟机上运行