Add third-party APP to Android ROM

Keywords: Android xml Java Apache

Students who make customized ROM must have such experience: the company requires to add some pre-installed applications in customized ROM, there are two main types: 1) the project developed by the company has source code; 2) other applications, only the apk installation package.
1. Active code.
[Source source directory / packages/apps /] (or [packages / experiments /], this directory puts some experimental applications) create a new folder, rename it Hello Android, and put the project source code in it. At the same time, create a new Android.mk file, the directory structure is roughly as follows:

---AndroidMenifest.xml
---Android.mk
---src
------com/itant/test
---------HelloAndroid.java
---res
------layout
---------main.xml
------values
---------strings.xml
------drawable
---------icon.png

The Android.mk file is as follows:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := HelloAndroid
include $(BUILD_PREBUILT)

Next, execute Step 3 of "Only the apk installation package", and add the project folder name to the core.mk file.
Then compile, the specific compilation process can refer to another article of mine. Android 5.0 source code compiling and burning to the real machine

2. Only APK files, assuming HelloAndroid.apk
1. Also create a new folder Hello Android in the source directory / packages/apps /, and copy Hello Android. APK into it.
2. New Android.mk file:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := HelloAndroid
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_SRC_FILES := HelloAndroid.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)

3. Add the name of the project folder you just added to the source directory/build/target/product/core.mk

#
# Copyright (C) 2007 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.
#

# Base configuration for communication-oriented android devices
# (phones, tablets, etc.).  If you want a change to apply to ALL
# devices (including non-phones and non-tablets), modify
# core_minimal.mk instead.

PRODUCT_PACKAGES += \
    HelloAndroid \
    BasicDreams \
    Browser \
    Calculator \
    Calendar \
    CalendarProvider \
    CaptivePortalLogin \
    CertInstaller \
    Contacts \
    DeskClock \
    DocumentsUI \
    DownloadProviderUi \
    Email \
    Exchange2 \
    ExternalStorageProvider \
    FusedLocation \
    InputDevices \
    KeyChain \
    Keyguard \
    LatinIME \
    Launcher2 \
    ManagedProvisioning \
    PicoTts \
    PacProcessor \
    libpac \
    PrintSpooler \
    ProxyHandler \
    QuickSearchBox \
    Settings \
    SharedStorageBackup \
    Telecom \
    TeleService \
    VpnDialogs \
    MmsService

$(call inherit-product, $(SRC_TARGET_DIR)/product/core_base.mk)

4. Compile the source code

Refer to the following
https://stackoverflow.com/questions/10579827/how-do-i-add-apks-in-an-aosp-build
https://groups.google.com/forum/#!topic/android-building/i4oaJ2DtadM
https://stackoverflow.com/questions/12643465/include-app-in-rom-as-system-app

If you don't have ROM source code, try APK Swapper, a tool of XDA forum god, to remove unwanted pre-installed software from packaged ROMs and add third-party software you need.
https://stackoverflow.com/questions/30865870/install-an-app-as-a-system-app-programmatically/30872375#30872375

Posted by michaelh613 on Sat, 11 May 2019 10:36:27 -0700