Android p Adding a New Device

Use the information in this page to create the makefiles for your device and product. Please note, unlike the other pages in this section, the contents here are applicable only when creating an entirely new device type and are intended for company build and product teams only.

Each new Android module must have a configuration file to direct the build system with module metadata, compile-time dependencies and packaging instructions. Android now uses the Soong build system. See Building Android for more information about the Android Build system.

Understand Build Layers

The build hierarchy includes the abstraction layers that correspond to the physical makeup of a device. These layers are described in the table below. Each layer relates to the one above it in a one-to-many relationship. For example, an architecture can have more than one board and each board can have more than one product. You may define an element in a given layer as a specialization of an element in the same layer, thus eliminating copying and simplifying maintenance.

LayerExampleDescription
ProductmyProduct, myProduct_eu, myProduct_eu_fr, j2, sdkThe product layer defines the feature specification of a shipping product such as the modules to build, locales supported, and the configuration for various locales. In other words, this is the name of the overall product. Product-specific variables are defined in product definition makefiles. A product can inherit from other product definitions, which simplifies maintenance. A common method is to create a base product that contains features that apply for all products, then creating product variants based on that base product. For example, you can have two products that differ only by their radios (CDMA vs GSM) inherit from the same base product that does not define a radio.
Board/Devicesardine, trout, goldfishThe device/board layer represents the physical layer of plastic on the device (i.e. the industrial design of the device). For example, North American devices probably include QWERTY keyboards whereas devices sold in France probably include AZERTY keyboards. This layer also represents the bare schematics of a product. These include the peripherals on the board and their configuration. The names used are merely codes for different board/device configurations.
Archarm, x86, mips, arm64, x86_64, mips64The architecture layer describes the processor configuration and ABI (Application Binary Interface) running on the board.

Use Build Variants

When building for a particular product, it's often useful to have minor variations on what is ultimately the final release build. In a module definition, the module can specify tags with LOCAL_MODULE_TAGS, which can be one or more values of optional (default), debugeng.

If a module doesn't specify a tag (by LOCAL_MODULE_TAGS), its tag defaults to optional. An optional module is installed only if it is required by product configuration with PRODUCT_PACKAGES.

These are the currently-defined build variants:

engThis is the default flavor.
  • Installs modules tagged with: eng and/or debug.
  • Installs modules according to the product definition files, in addition to tagged modules.
  • ro.secure=0
  • ro.debuggable=1
  • ro.kernel.android.checkjni=1
  • adb is enabled by default.
userThis is the flavor intended to be the final release bits.
  • Installs modules tagged with user.
  • Installs modules according to the product definition files, in addition to tagged modules.
  • ro.secure=1
  • ro.debuggable=0
  • adb is disabled by default.
userdebugThe same as user, except:
  • Also installs modules tagged with debug.
  • ro.debuggable=1
  • adb is enabled by default.

userdebug guidelines

Running userdebug builds in testing helps device developers understand performance and power of in-development releases. To maintain consistency between user and userdebug builds, and to achieve reliable metrics in builds used for debugging, device developers should follow these guidelines:

  • userdebug is defined as a user build with root access enabled, except:
    • userdebug-only apps that are run only on-demand by the user
    • Operations that run only during idle maintenance (on charger / fully charged), such as using dex2oatd versus dex2oat for background compiles
  • Do not have any features that depend on the build type in order to be enabled by default or not. Developers are discouraged from using any form of logging that affects battery life, such as debug logging or heap dumping.
  • Any debugging features that are enabled by default in userdebug should be clearly defined and shared with all developers working on the project. Only enable those debugging features on a limited-time basis until the issue is resolved.

Customize the Build with Resource Overlays

The Android build system uses resource overlays to customize a product at build time. Resource overlays specify resource files that are applied on top of the defaults. To use resource overlays, modify the project buildfile to set PRODUCT_PACKAGE_OVERLAYS to a path relative to your top-level directory. That path becomes a shadow root searched along with the current root when the build system searches for resources.

The most commonly customized settings are contained in the file frameworks/base/core/res/res/values/config.xml.

To set up a resource overlay on this file, add the overlay directory to the project buildfile, as follows:

PRODUCT_PACKAGE_OVERLAYS := device/DEVICE_IMPLEMENTER/DEVICE_NAME/overlay

 

or

PRODUCT_PACKAGE_OVERLAYS := vendor/VENDOR_NAME/overlay

 

Then, add an overlay file to the directory, for example:

vendor/foobar/overlay/frameworks/base/core/res/res/config.xml

 

Any strings or string arrays found in the overlay config.xml file replace those found in the original file.

Build a Product

There are many ways to organize the source files for your device. We'll briefly go over how the Nexus 6 implementation was organized as an example, but you can organize your source files and build the way you see fit.

Nexus 6 was implemented with a main device configuration named shamu. From this device configuration, a product is created with a product definition makefile that declares product-specific information about the device such as the name and model. You can view the device/moto/shamu directory to see how all of this is setup.

Write the Makefiles

The following steps describe how to set up product makefiles in a way similar to that of the Nexus 6 product line:

  1. Create a device/<company_name>/<device_name> directory for your product. For example, device/moto/shamu. This directory will contain source code for your device along with the makefiles to build them.
  2. Create a device.mk makefile that declares the files and modules needed for the device. For an example, see device/moto/shamu/device.mk.
  3. Create a product definition makefile to create a specific product based on the device. The following makefile is taken from device/moto/shamu/aosp_shamu.mk as an example. Notice the product is inheriting from the device/moto/shamu/device.mk and vendor/moto/shamu/device-vendor.mk files via the makefile while also declaring the product-specific information such as name, brand, and model.
    # Inherit from the common Open Source product configuration
    $(call inherit-product, $(SRC_TARGET_DIR)/product/aosp_base_telephony.mk)
    
    PRODUCT_NAME := aosp_shamu
    PRODUCT_DEVICE := shamu
    PRODUCT_BRAND := Android
    PRODUCT_MODEL := AOSP on Shamu
    PRODUCT_MANUFACTURER := motorola
    PRODUCT_RESTRICT_VENDOR_FILES := true
    
    $(call inherit-product, device/moto/shamu/device.mk)
    $(call inherit-product-if-exists, vendor/moto/shamu/device-vendor.mk)
    
    PRODUCT_NAME := aosp_shamu
    
    PRODUCT_PACKAGES += \
        Launcher3
    

     

    See Product Definition Variables for additional product-specific variables you can add to your makefiles.

  4. Create an AndroidProducts.mk file that points to the product's makefiles. In this example, only the product definition makefile is needed. The example below is fromdevice/moto/shamu/AndroidProducts.mk:
    #
    # This file should set PRODUCT_MAKEFILES to a list of product makefiles
    # to expose to the build system.  LOCAL_DIR will already be set to
    # the directory containing this file.
    #
    # This file may not rely on the value of any variable other than
    # LOCAL_DIR; do not use any conditionals, and do not look up the
    # value of any variable that isn't set in this file or in a file that
    # it includes.
    #
    
    PRODUCT_MAKEFILES := \
        $(LOCAL_DIR)/aosp_shamu.mk
    

     

  5. Create a BoardConfig.mk makefile that contains board-specific configurations. For an example, see device/moto/shamu/BoardConfig.mk.
  6. Create a vendorsetup.sh file to add your product (a "lunch combo") to the build along with a build variantseparated by a dash. For example:
    add_lunch_combo <PRODUCT_NAME>-userdebug
    

     

  7. At this point, you can create more product variants based on the same device.

Set Product Definition Variables

Product-specific variables are defined in the product's makefile. Variables maintained in a product definition files include:

ParameterDescriptionExample
PRODUCT_AAPT_CONFIGaapt configurations to use when creating packages 
PRODUCT_BRANDThe brand (e.g., carrier) the software is customized for, if any 
PRODUCT_CHARACTERISTICSaapt characteristics to allow adding variant-specific resources to a package.tablet,nosdcard
PRODUCT_COPY_FILESList of words like source_path:destination_path. The file at the source path should be copied to the destination path when building this product. The rules for the copy steps are defined in config/makefile 
PRODUCT_DEVICEName of the industrial design. This is also the board name, and the build system uses it to locate the BoardConfig.mk.tuna
PRODUCT_LOCALESA space-separated list of two-letter language code, two-letter country code pairs that describe several settings for the user, such as the UI language and time, date and currency formatting. The first locale listed in PRODUCT_LOCALES is used as the product's default locale.en_GB de_DE es_ES fr_CA
PRODUCT_MANUFACTURERName of the manufactureracme
PRODUCT_MODELEnd-user-visible name for the end product 
PRODUCT_NAMEEnd-user-visible name for the overall product. Appears in the Settings > About screen. 
PRODUCT_OTA_PUBLIC_KEYSList of Over the Air (OTA) public keys for the product 
PRODUCT_PACKAGESLists the APKs and modules to install.Calendar Contacts
PRODUCT_PACKAGE_OVERLAYSIndicate whether to use default resources or add any product specific overlaysvendor/acme/overlay
PRODUCT_PROPERTY_OVERRIDESList of system property assignments in the format "key=value" 

Set ANDROID_VENDOR_KEYS to connect over USB

The ANDROID_VENDOR_KEYS environment variable enables device manufacturers to access production builds over adb. Generate a key for each release that every device will accept, store those internally (such as atvendor/oem-name/security/adb/), and then use ANDROID_VENDOR_KEYS to tell adb to use these canonical keys rather than random keys.

Use the ANDROID_VENDOR_KEYS environment variable to point to the directory containing the generated adbpublic and private keys used for encryption. The private key is stored in file. The public key is stored in file.pub. The ANDROID_VENDOR_KEYS environment variable points to a file or directory where the generated key pairs are stored.

This variable is set to a file or directory that contains 2048-bit RSA authentication key pairs generated with the adb keygen file command. These key pairs are in addition to the RSA key pairs generated by the ADB server. An RSA key pair is needed when you use adb to connect over USB for the first time.

You must accept the host computer's RSA key to explicitly grant adb access to the device. By default key pairs generated by the ADB server are stored in the following key store directories as adbkey (private key) and adbkey.pub (public key):

For file locations, on MacOS, this will likely be: $HOME/.android. On Windows and Linux, this will be:%USERPOFILE%\.android. On Windows, RSA authentication keys can also be in C:\Windows\System32\config\systemprofile\.android in some cases. When the ADB server needs a key, it first searches the ADB server key store directory. If no keys are found, it then checks theANDROID_VENDOR_KEYS environment variable. If no keys are found, the local ADB server generates and saves a new key pair in the ADB server key store directory.

Note: You can override the default directory where the ADB server stores RSA keys by setting theANDROID_SDK_HOME environment variable. On the device, keys are stored in the /data/misc/adb/adb_keys/ file, and new authorized keys are appended to the same file as you accept them.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值