Built-in Apk to the system (Android10)

1. Android.mk file description

 

       Android.mk is a makefile provided by Android, which can group source files into modules. The header file directory used for quoting, the *.c/*.cpp file that needs to be compiled, the jni source file, the specified compilation to generate the *.so shared library file or the *.a static library file, one or more modules can be defined, and The same source file can be used in multiple modules.

      To facilitate module compilation, the compilation system has set up many module description environment variables and macro definitions. Some commonly used ones are listed below.

   Module description environment variables:

  • LOCAL_SRC_FILES:

               Source files contained in the current module;

  • LOCAL_MODULE:

                 The name of the current module;

  • LOCAL_PACKAGE_NAME

                 The name of the current APK application;

  • LOCAL_C_INCLUDES:

                   The header file path required by C/C++;

  • LOCAL_STATIC_LIBRARIES:

                   The name of the static link library required by the current module during static linking;

  • LOCAL_SHARED_LIBRARIES:

                   The name of the dynamic link library that the current module depends on at runtime;

  • LOCAL_STATIC_JAVA_LIBRARIES:

                    The Java static library that the current module depends on;

  • LOCAL_JAVA_LIBRARIES:

                   The Java shared library that the current module depends on;

  • LOCAL_CERTIFICATE:

                   The signature method of the current application, such as using the system signature platform.

  • LOCAL_MODULE_TAGS:

           Indicates the identifier of the module compilation, which may be eng, user, tests or optional (default value). The value specifically means:

               user: 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

   

  Defined include variables:

  •    include $(BUILD_SHARED_LIBRARY) 

           Indicates that it needs to be compiled into a so dynamic link library.

  •    include $(BUILD_JAVA_LIBRARY) 

           Indicates that it needs to be compiled into a java dynamic library.

  •    include $(BUILD_JAVA_STATIC_LIBRARY) 

           Indicates that it needs to be compiled into a java static library.

  •    include $(BUILD_STATIC_LIBRARY )

         Indicates that it needs to be compiled into a so static library. 

  • include $(BUILD_EXECUTABLE)

         Represents compiled into Native C executable program  

  • include $(BUILD_PREBUILT)

             Indicates that the source file has been compiled and only needs to be copied

    

 

     The defined function macro, the prototype is  $(call <function>), the following are a few:

  • $(call my-dir)

              Get the current folder path;

  • $(call all-java-files-under, )

           Get all Java files in the specified directory;

  • $(call all-c-files-under,)

            Get all C files in the specified directory;

  • $(call all-Iaidl-files-under, )

            Get all AIDL files in the specified directory;

     

       2. Provide several Android.mk templates

#编译so静态库    LOCAL_PATH := $(call my-dir)    include $(CLEAR_VARS)    LOCAL_MODULE = libtest LOCAL_SRC_FILES = testxxx.c    LOCAL_C_INCLUDES = $(INCLUDES)    LOCAL_SHARED_LIBRARIES := libcutils      include $(BUILD_STATIC_LIBRARY)        #编译为so动态库链接库    LOCAL_PATH := $(call my-dir)    include $(CLEAR_VARS)    LOCAL_MODULE = libtest  LOCAL_SRC_FILES = testxx.c    LOCAL_C_INCLUDES = $(INCLUDES)    LOCAL_SHARED_LIBRARIES := libcutils       include $(BUILD_SHARED_LIBRARY)      #编译java动态库LOCAL_PATH:= $(call my-dir)include $(CLEAR_VARS)LOCAL_SRC_FILES := $(call all-subdir-java-files)LOCAL_MODULE := testjarinclude $(BUILD_JAVA_LIBRARY)
#编译java静态库LOCAL_PATH:= $(call my-dir)include $(CLEAR_VARS)LOCAL_SRC_FILES := $(call all-subdir-java-files)LOCAL_MODULE := testjarinclude $(BUILD_STATIC_JAVA_LIBRARY)       #编译为可执行文件  LOCAL_PATH := $(call my-dir)    include $(CLEAR_VARS)    LOCAL_MODULE := hellos    LOCAL_STATIC_LIBRARIES := libhellos    LOCAL_SHARED_LIBRARIES :=    LOCAL_LDLIBS += -ldl    LOCAL_CFLAGS := $(L_CFLAGS)    LOCAL_SRC_FILES := mains.c    LOCAL_C_INCLUDES := $(INCLUDES)    include $(BUILD_EXECUTABLE)        #使用动态库    LOCAL_PATH := $(call my-dir)    include $(CLEAR_VARS)    LOCAL_MODULE := hellod    LOCAL_MODULE_TAGS := debug    LOCAL_SHARED_LIBRARIES := libc libcutils libhellod    LOCAL_LDLIBS += -ldl    LOCAL_CFLAGS := $(L_CFLAGS)    LOCAL_SRC_FILES := maind.c    LOCAL_C_INCLUDES := $(INCLUDES)    include $(BUILD_EXECUTABLE)       #预编so动态链接库到指定目录LOCAL_PATH := $(call my-dir)  include $(CLEAR_VARS)  LOCAL_MODULE := libtest.so  LOCAL_MODULE_CLASS := SHARED_LIBRARIES  LOCAL_MODULE_PATH := $(ANDROID_OUT_SHARED_LIBRARIES)  LOCAL_SRC_FILES := lib/$(LOCAL_MODULE )  OVERRIDE_BUILD_MODULE_PATH := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)  include $(BUILD_PREBUILT)  
#预编二进制文件到系统include $(CLEAR_VARS)LOCAL_MODULE := testbinLOCAL_SRC_FILES := testbinLOCAL_MODULE_CLASS := EXECUTABLESLOCAL_MODULE_TAGS := optionalinclude $(BUILD_PREBUILT)# 内置Apk文件到系统LOCAL_PATH:= $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := adbinputmethodLOCAL_MODULE_CLASS := APPSLOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)LOCAL_MODULE_TAGS := optionalLOCAL_PRIVILEGED_MODULE := trueLOCAL_BUILT_MODULE_STEM := package.apkLOCAL_SRC_FILES := $(LOCAL_MODULE).apk# LOCAL_CERTIFICATE := platformLOCAL_CERTIFICATE := PRESIGNEDinclude $(BUILD_PREBUILT)

3. Built-in apk in the source code to the system

      Here takes the built-in Sogou input method into the system as an example.

    (1). Create a directory to store the built-in App, here I created it as packages/myapps/sougou, as shown below:

qiang@ubuntu:~/lineageOs$ pwd/home/qiang/lineageOsqiang@ubuntu:~/lineageOs$ mkdir -p packages/myapps/sougouqiang@ubuntu:~/lineageOs$ 

       (2). Copy the Sogou input method apk to packages/myapps/sougou, and create the built-in apk to the system Android.mk. As follows:

qiang@ubuntu:~/lineageOs/packages/myapps/sougou$ pwd/home/qiang/lineageOs/packages/myapps/sougouqiang@ubuntu:~/lineageOs/packages/myapps/sougou$ ls -latotal 58480drwxrwxrwx 2 qiang qiang     4096 1月   1 18:22 .drwxrwxr-x 3 qiang qiang     4096 1月   2 02:25 ..-rwxrw-rw- 1 qiang qiang      755 1月   1 18:29 Android.mk-rwxrw-rw- 1 qiang qiang 59870272 11月  3 07:35 sougou.apk

     The corresponding Android.mk content is:

# ///ADD START# ///ADD END# 设置当前工作路径LOCAL_PATH:= $(call my-dir)# 清除变量值include $(CLEAR_VARS)# 生成的模块名称LOCAL_MODULE := sougou# 生成的模块类型LOCAL_MODULE_CLASS := APPS# 生成的模块后缀名,此处为apkLOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)# 设置模块tag,tags取值可以为:user debug eng tests optional# optional表示全平台编译LOCAL_MODULE_TAGS := optional# LOCAL_PRIVILEGED_MODULE := trueLOCAL_BUILT_MODULE_STEM := package.apk# 设置源文件LOCAL_SRC_FILES := $(LOCAL_MODULE).apk# LOCAL_CERTIFICATE := platform# 设置签名,此处表示保持apk原有签名LOCAL_CERTIFICATE := PRESIGNED# 此处表示预编译方式include $(BUILD_PREBUILT)

    (3) Configure the created Sogou input method compilation module to the compilation system. This is very important. If you do not add the compilation image, the module just added will not be compiled by default. In lineageOs, you can add sougou where you add the Settings module in the following path.

File location:

 

build/make/target/product/handheld_product.mk

        Part of the content after adding the sougou content is as follows:

PRODUCT_PACKAGES += \    Browser2 \    Calendar \    Camera2 \    Contacts \    DeskClock \    Gallery2 \    Launcher3QuickStep \    Music \    OneTimeInitializer \    Provision \    QuickSearchBox \    Settings \    SettingsIntelligence \    StorageManager \    SystemUI \    WallpaperCropper \    frameworks-base-overlays \    sougou

   (4) Compile and flash

qiang@ubuntu:~/lineageOs/build/make/target/product$ crootqiang@ubuntu:~/lineageOs$ breakfast oneplus3Looking for dependencies in device/oneplus/oneplus3Looking for dependencies in device/oppo/commondevice/oppo/common has no additional dependencies.Looking for dependencies in kernel/oneplus/msm8996kernel/oneplus/msm8996 has no additional dependencies.============================================PLATFORM_VERSION_CODENAME=RELPLATFORM_VERSION=10LINEAGE_VERSION=17.1-20210102-UNOFFICIAL-oneplus3TARGET_PRODUCT=lineage_oneplus3TARGET_BUILD_VARIANT=userdebugTARGET_BUILD_TYPE=releaseTARGET_ARCH=arm64TARGET_ARCH_VARIANT=armv8-aTARGET_CPU_VARIANT=kryoTARGET_2ND_ARCH=armTARGET_2ND_ARCH_VARIANT=armv8-aTARGET_2ND_CPU_VARIANT=kryoHOST_ARCH=x86_64HOST_2ND_ARCH=x86HOST_OS=linuxHOST_OS_EXTRA=Linux-5.4.0-58-generic-x86_64-Ubuntu-20.04.1-LTSHOST_CROSS_OS=windowsHOST_CROSS_ARCH=x86HOST_CROSS_2ND_ARCH=x86_64HOST_BUILD_TYPE=releaseBUILD_ID=QQ3A.200805.001OUT_DIR=outPRODUCT_SOONG_NAMESPACES=vendor/oneplus/oneplus3 device/oneplus/oneplus3 vendor/nxp/opensource/pn5xx hardware/qcom-caf/msm8996============================================qiang@ubuntu:~/lineageOs$ brunch oneplus3Looking for dependencies in device/oneplus/oneplus3Looking for dependencies in device/oppo/commondevice/oppo/common has no additional dependencies.Looking for dependencies in kernel/oneplus/msm8996kernel/oneplus/msm8996 has no additional dependencies.

4. Effect display

   

image

image

 

Pay attention to the official account and get updated content in time:

image

Guess you like

Origin blog.csdn.net/u011426115/article/details/113306687