-
packages/apps
Create a folder below with the name of the APK that needs to be pre-set. Take pre-setting anMyExample
APK named as an example.
-
MyExample.apk
Placepackages/apps/MyExample
below.
-
packages/apps/MyExample
Create a file belowAndroid.mk
with the following contents:LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_MODULE := < your app folder name > # 签名 LOCAL_CERTIFICATE := < desired key > # 指定 src 目录 LOCAL_SRC_FILES := < app apk filename > LOCAL_MODULE_CLASS := APPS # 该模块的后缀,不用定义 #LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) include $(BUILD_PREBUILT)
explain:
-
LOCAL_PATH := $(call my-dir)
Every Android.mk file must start with the definition of LOCAL_PATH, which is used to find source files in the development tree. -
include $(CLEAR_VARS)
The CLEAR_VARS variable is provided by the Build System and points to a specified GNU Makefile, which is responsible for cleaning up many LOCAL_xxx.
For example: LOCAL_MODULE, LOCAL_SRC_FILES, LOCAL_STATIC_LIBRARIES, etc., but do not clean LOCAL_PATH. -
LOCAL_MODULE_TAGS : = user eng tests optional
optional definition, indicating under what version to compile this version, the default is optionaluser: means that the module is only compiled under the user version
eng: means that the module is only compiled under the eng version
tests: means that the module is only compiled under the tests version
optional: means that the module is compiled under all versions -
LOCAL_MODULE
module name, you don’t need to define it, the default = $(LOCAL_PACKAGE_NAME), it cannot be the same as the existing module, if this variable is not set, use LOCAL_PACKAGE_NAME, if there is no more, the compilation will fail. -
Under what circumstances is LOCAL_CERTIFICATE signed.testkey: normal APK, used by default.
platform: The APK completes some core functions of the system. After the access test to the folders existing in the system, the UID of the process where the APK compiled in this way is system, please refer to Settings.
shared: The APK needs to share data with the home/contacts process, see Launcher.
media: The APK is a part of the media/download system, see Gallery. -
LOCAL_MODULE_CLASS
specifies the type of the module, it does not need to be defined.# 编译 apk 文件 LOCAL_MODULE_CLASS := APPS # 编译 jar 包 LOCAL_MODULE_CLASS := JAVA_LIBRAYIES # 定义动态库文件 LOCAL_MODULE_CLASS := SHARED_LIBRAYIES # 编译可执行文件 LOCAL_MODULE_CLASS := EXECUTABLES
-
include $(BUILD_PACKAGE)
means to generate an apk, which can be of various typesBUILD_PACKAGE(既可以编apk,也可以编资源包文件,但是需要指定LOCAL_EXPORT_PACKAGE_RESOURCES:=true) BUILD_JAVA_LIBRARY(java共享库) BUILD_STATIC_JAVA_LIBRARY(java静态库) BUILD_EXECUTABLE(执行文件) BUILD_SHARED_LIBRARY(native共享库) BUILD_STATIC_LIBRARY(native静态库)
Android.mk file complete configuration:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Module name should match apk name to be installed
LOCAL_MODULE := MyExample
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)
- Add the apps that need to be preset to the system compilation.
1)aosp/build/
Find the location of the added file in the directory:
Because the system comes withCalendar
a calendar application, we canCalendar
determine the location of the file to be added by searching for the location of the file:grep "Calendar" ./ -rn grep "Contacts" ./ -rn
2)打开我们查找到的文件`aosp/build/make/target/product/handheld_product.mk`,在文件中添加内容:
```
PRODUCT_PACKAGES += \
MyExample\
```
- Use
mmm
the command to compile the specified module:cd ~/aosp/packages/apps/MyExample mmm
- Recompile
system.img
:cd ~/aosp make snod
Note : If an error is reported during the compilation process:
build/make/core/Makefile:2787: warning: Warning: with dexpreopt enabled, you may need a full rebuild.
15:02:00 Excepted "out/target/product/sargo/.installable_files" to be readable
Turn off dex optimization:packages/apps/MyExample/Android.mk
LOCAL_DEX_PREOPT := false
Go back to step 5 to recompile the specified module and system.img
:
At this time, it can be successfully compiled, as shown in the figure:
- Burn the compiled file
system.img
to the device for verification.
adb reboot bootloader
fastboot reboot fastboot
fastboot flash system system.img
- Restart the phone to see if the apk we added is built in.
Reference:
https://www.shuzhiduo.com/A/amd0N7BkJg/
http://wuxiaolong.me/2019/02/10/APPPreset/
https://blog.csdn.net/Kitty_Landon/article/details/54584772? utm_medium=distribute.pc_relevant.none-task-blog-2 default baidujs_baidulandingword~default-1.pc_relevant_default&spm=1001.2101.3001.4242.2&utm_relevant_index=4
https://blog.csdn.net/w2064004678/article/details/10794910
8 https:// www.bilibili.com/video/BV1ct4y1i7FV?spm_id_from=333.337.search-card.all.click
https://www.bilibili.com/video/BV1VZ4y1L7rJ?spm_id_from=333.337.search-card.all.click
https:// www.bilibili.com/video/BV1Ar4y1w7bh?spm_id_from=333.337.search-card.all.click