编译Android 16 TV模拟器(一)

  1. 准备repo工具:

    curl -L https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
    chmod a+x ~/bin/repo
    export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'

  2. 初始化仓库:

    ~/repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-16.0.0_r2

  3. 同步代码:

    ~/repo sync -c -j8

  4. 准备tv x86_64环境的 mk文件。代码里没有 x86_64的 mk,需要根据x86和其他x86_64的mk手动建立一个。

    data/aosp/device/google/atv/products$ ls
    AndroidProducts.mk atv_logpersist.mk bootanimations
    aosp_tv_arm64.mk atv_lowram_defaults.mk gsi_tv_arm64.mk
    atv_mainline_system.mk gsi_tv_arm.mk
    aosp_tv_x86.mk atv_product.mk gsi_tv_base.mk
    atv_base.mk atv_system_ext.mk lowram_boot_profiles
    atv_emulator_vendor.mk atv_system.mk sdk_atv64_arm64.mk
    atv_generic_system.mk atv_vendor.mk sdk_atv_x86.mk

首先拷贝aosp_tv_x86.mk,重命名为aosp_tv_x86_64.mk,把其中 x86的配置改成 x86_64的。

复制代码
$ cat aosp_tv_x86.mk
#
# Copyright (C) 2020 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Generate source.properties for image target
PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP := \
    device/google/atv/sdk/images_source.prop_template

PRODUCT_USE_DYNAMIC_PARTITIONS := true

# The system image of aosp_tv_x86-userdebug is a GSI for the devices with:
# - x86 32 bits user space
# - 64 bits binder interface
# - VNDK enforcement
# - compatible property override enabled

#
# All components inherited here go to system image
#
$(call inherit-product, device/google/atv/products/atv_generic_system.mk)

# Enable mainline checking for excat this product name
ifeq (aosp_tv_x86,$(TARGET_PRODUCT))
PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS := relaxed
endif

#
# All components inherited here go to system_ext image
#
$(call inherit-product, device/google/atv/products/atv_system_ext.mk)
# Packages required for ATV GSI
PRODUCT_PACKAGES += \
    TvProvision

#
# All components inherited here go to product image
#
$(call inherit-product, device/google/atv/products/atv_product.mk)
# Default sound experience
$(call inherit-product-if-exists, frameworks/base/data/sounds/AudioTv.mk)
# Packages required for ATV GSI
ifeq (aosp_tv_x86,$(TARGET_PRODUCT))
PRODUCT_PACKAGES += \
    LeanbackIME \
    TvSampleLeanbackLauncher
endif

#
# All components inherited here go to vendor image
#
$(call inherit-product, device/google/atv/products/atv_emulator_vendor.mk)
$(call inherit-product, device/generic/goldfish/board/emu64x/kernel_fstab_32.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/board/generic_x86/device.mk)

ifeq (aosp_tv_x86,$(TARGET_PRODUCT))
$(call inherit-product, $(SRC_TARGET_DIR)/product/gsi_release.mk)
endif

PRODUCT_NAME := aosp_tv_x86
PRODUCT_DEVICE := generic_x86
PRODUCT_BRAND := Android
PRODUCT_MODEL := AOSP TV on x86

修改之后的 aosp_tv_x86_64.mk:

复制代码
 cat aosp_tv_x86_64.mk
#
# Copyright (C) 2020 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Generate source.properties for image target
PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP := \
    device/google/atv/sdk/images_source.prop_template

PRODUCT_USE_DYNAMIC_PARTITIONS := true

# The system image of aosp_tv_x86-userdebug is a GSI for the devices with:
# - x86 32 bits user space
# - 64 bits binder interface
# - VNDK enforcement
# - compatible property override enabled

#
# All components inherited here go to system image
#
$(call inherit-product, device/google/atv/products/atv_generic_system.mk)

# Enable mainline checking for excat this product name
ifeq (aosp_tv_x86_64,$(TARGET_PRODUCT))
PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS := relaxed
endif

#
# All components inherited here go to system_ext image
#
$(call inherit-product, device/google/atv/products/atv_system_ext.mk)
# Packages required for ATV GSI
PRODUCT_PACKAGES += \
    TvProvision

#
# All components inherited here go to product image
#
$(call inherit-product, device/google/atv/products/atv_product.mk)
# Default sound experience
$(call inherit-product-if-exists, frameworks/base/data/sounds/AudioTv.mk)
# Packages required for ATV GSI
ifeq (aosp_tv_x86_64,$(TARGET_PRODUCT))
PRODUCT_PACKAGES += \
    LeanbackIME \
    TvSampleLeanbackLauncher
endif

#
# All components inherited here go to vendor image
#
$(call inherit-product, device/google/atv/products/atv_emulator_vendor.mk)
$(call inherit-product, device/generic/goldfish/board/emu64x/kernel_fstab_32.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/board/generic_x86_64/device.mk)

ifeq (aosp_tv_x86_64,$(TARGET_PRODUCT))
$(call inherit-product, $(SRC_TARGET_DIR)/product/gsi_release.mk)
endif

TARGET_ARCH := x86_64
TARGET_ARCH_VARIANT := x86_64
TARGET_CPU_ABI := x86_64
TARGET_SUPPORTS_64_BIT_APPS := true

PRODUCT_NAME := aosp_tv_x86_64
PRODUCT_DEVICE := generic_x86_64
PRODUCT_BRAND := Android
PRODUCT_MODEL := AOSP TV on x86_64

然后把

$(LOCAL_DIR)/aosp_tv_x86_64.mk 加到 AndroidProducts.mk里面。

  1. 准备编译目标

    source build/envsetup.sh
    lunch aosp_tv_x86_64-aosp_current-eng

如果没有问题,会输出如下:

复制代码
$ lunch aosp_tv_x86_64-aosp_current-eng
00:39:36 Build sandboxing disabled due to nsjail error.

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=16
TARGET_PRODUCT=aosp_tv_x86_64
TARGET_BUILD_VARIANT=eng
TARGET_ARCH=x86_64
TARGET_ARCH_VARIANT=x86_64
TARGET_2ND_ARCH=x86
TARGET_2ND_ARCH_VARIANT=x86_64
HOST_OS=linux
HOST_OS_EXTRA=Linux-6.8.0-88-generic-x86_64-Ubuntu-24.04.3-LTS
HOST_CROSS_OS=windows
BUILD_ID=BP2A.250605.031.A3
OUT_DIR=out
SOONG_ONLY=false
============================================

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Wondering whether to use user, userdebug or eng?

  user        The builds that ship to users. Reduced debugability.
  userdebug   High fidelity to user builds but with some debugging options
              enabled. Best suited for performance testing or day-to-day use
              with debugging enabled.
  eng         More debugging options enabled and faster build times, but
              runtime performance tradeoffs. Best suited for day-to-day
              local development when not doing performance testing.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

如果没有改好,可能会输出如下:

复制代码
lunch aosp_tv_x86_64-aosp-eng
23:22:01 Build sandboxing disabled due to nsjail error.
In file included from build/make/core/config.mk:422:
In file included from build/make/core/envsetup.mk:368:
build/make/core/board_config.mk:334: error: Building a 32-bit-app-only product on a 64-bit device. If this is intentional, set TARGET_SUPPORTS_64_BIT_APPS := false.
23:22:01 dumpvars failed with: exit status 1
panic: dumpvars failed with: exit status 1

参考:

https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/

相关推荐
千里马学框架16 小时前
一起学 Android 14:ShellTransition 屏幕旋转过程深度剖析
android·智能手机·性能优化·framework·性能·屏幕旋转·rotation
美狐美颜SDK开放平台16 小时前
开发直播APP时如何接入视频美颜SDK?开发流程与注意事项
android·人工智能·计算机视觉·音视频·直播美颜sdk
AFinalStone16 小时前
Android7 SystemUI源码解析(七)Keyguard锁屏模块深度解析
android·systemui
致远ccc17 小时前
Google Play 上架前如何测试 App?多国家 Android 环境测试
android·app测试·googleplay·多国家应用测试
ttyyttemo19 小时前
Kotlin 协程中的 Job 结构化并发与取消
android
sun00770019 小时前
tbox 4g/5g切换,导致wan ip 改变,导致车机旧网络不可用。需要重启车机才行
android
其实防守也摸鱼20 小时前
内网穿透与反向代理:原理、工具与实战指南
android·大数据·运维·安全·网络安全·自动化·渗透
AFinalStone21 小时前
Android7 SystemUI 源码解析(四)NavigationBar 导航栏与 SystemBars
android·systemui
JMchen21 小时前
属性动画原理与高级动画实现
android·kotlin·canvas
AFinalStone21 小时前
Android7 SystemUI 源码解析(二)启动流程深度解析
android·systemui