Android on-board application development and analysis - integrated third-party APK

Keywords: Android

preface

In the process of on-board application development, there will be a special need to pre install some third-party apps, such as Baidu map on-board version, on-board wechat and so on. This kind of app OEM will not get the source code, but only one apk.

This article demonstrates how to use AOSP based on Android R_ car_ x86_ The third-party apk is pre installed in x64. aosp_car_x86_x64 we are compiling the build selected by AOSP_ Type, if you don't know how to compile AOSP, you can refer to this article Android Automotive application development and analysis (1) - Android Automotive overview and compilation.

In fact, there are different ways for OEM manufacturers to pre install the third-party APK. This article only demonstrates a relatively simple way.

##1. Directory of application installation

/system/priv-app
This path stores some underlying applications of the system, such as Setting, systemUI, etc. The app in this directory has high system permissions, and if you want to use android:protectionLevel=signatureOrSystem, the app must be placed in the priv app directory.

/system/app
The permissions of system apps stored in this directory are relatively low, and when you have root permission, you may uninstall these apps.

/vendor/app
This directory stores the vendor's app

/oem/app
This directory stores oem specific app s.

/data/app
Third party app s installed by users.

When PMS is started, apk s in these directories are scanned and parsed one by one according to the above sequence

##2. Pre install APK
Create a new folder in device/generic/car, such as bilibili, copy the APK to the bilibilibili folder, and create the Android.mk file, as follows:

LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := bilibili.apk
LOCAL_MODULE_CLASS := APPS
#It can be compiled for user, eng, tests and optional. Optional means that it can be compiled under any version
LOCAL_MODULE_TAGS := optional
#The name of the compiled module
LOCAL_MODULE := bilibili
#It can be testkey, platform, shared, media and preset (using the original signature), and platform represents the system application
LOCAL_CERTIFICATE := PRESIGNED
#Application output path, here is system/app
LOCAL_MODULE_PATH := $(TARGET_OUT)/app
#If it is not set or set to false, the installation location is system/app. If it is set to true, the installation location is system / priv app?
LOCAL_PRIVILEGED_MODULE := false
#module suffix, optional
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
# If precompiling is turned off, the OAT file will not be generated
LOCAL_DEX_PREOPT := true
include $(BUILD_PREBUILT)

Add bilibili to device/generic/car/aosp_car_x86_64.mk

PRODUCT_PACKAGE_OVERLAYS := device/generic/car/common/overlay

EMULATOR_VENDOR_NO_SENSORS := true
$(call inherit-product, device/generic/car/emulator/aosp_car_emulator.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/product/aosp_x86_64.mk)

# Add packages to product_ In packages
PRODUCT_PACKAGES += \
  bilibili \

EMULATOR_VENDOR_NO_SOUND := true
PRODUCT_NAME := aosp_car_x86_64
PRODUCT_DEVICE := generic_car_x86_64
PRODUCT_BRAND := Android
PRODUCT_MODEL := Car on x86_64 emulator

Recompile the entire project

# Clear the contents in the corresponding board folder under the out directory
make installclean
make -j8

3. Precautions

  1. Prompt during compilation: Verification error in and Had a hard failure verifying all classes, and was asked to abort in such situations
    Reason: when apk is prefabricated into the system, it will parse the apk and generate an odex file to speed up the startup and operation of the app. Integrate the app developed for the lower version in the higher version Android system (generally, the lower version will report an error), and such a prompt will appear when there is an error in odex file parsing.
    Solution: turn off precompiling in Android.mk in the folder where apk is placed
# If precompiling is turned off, the OAT file will not be generated
LOCAL_DEX_PREOPT := false

Posted by jesseledwards on Mon, 11 Oct 2021 13:22:04 -0700