- Chapter 1. AOSP and System App Overview
- Chapter 2. Writing .mk files
- Chapter 3. Additional Configuration Methods
- Chapter 4. Building and Testing System Apps
- Chapter 5. Conclusion and Summary
Chapter 1. AOSP and System App Overview
This chapter provides an introduction to the Android system app development. System apps are somewhat different from regular apps, so we’ll examine those differences and understand why there might be a need to develop system apps.
1.1. What is a System App?
A system app is an application that runs on an Android device, is grouped separately from other applications, and is installed in the system area (/system/app, /system/priv-app). It has special permissions and capabilities and plays an important role in the stability and security of the device, as it performs core functions unlike regular user applications.
1.2. The Need for a System App
There are several reasons to develop a system app, such as:
- To provide essential system services: For example, contact management, telephone calls, text messages, system settings management, etc.
- To control hardware and access interfaces: Apps that directly access hardware features, such as camera, GPS, sensors, etc.
- To protect user privacy and provide security: System apps are often used for providing security features and protecting user's privacy for the device.
1.3. Setting up the Development Environment
For system app development, Android Open Source Project (AOSP) source code is used. To develop a system app within AOSP, you will need to:
- Download the AOSP code and set up your development environment.
- Create a project for your system application, and set up the necessary build configuration files.
- Add the project to AOSP and build it together with the platform.
- Install the built system image to the device (or emulator) and check the operation of the system app.
In this overview, we have briefly examined the concepts of system app development. In the next chapter, we will cover the process of writing a build configuration file, called a .mk file, for system apps.
Chapter 2. Writing .mk files
In this chapter, we will learn how to write .mk files used in AOSP. .mk files are Makefiles that define build settings for system apps.
2.1. Core Components and Structure
A typical .mk file includes the following core components and structure:
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_MODULE := MySystemApp LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_PRIVILEGED_MODULE := true LOCAL_JAVA_LIBRARIES := framework include $(BUILD_PACKAGE)
LOCAL_PATH
LOCAL_PATH specifies the path of the current directory.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
CLEAR_VARS includes a file that initializes build variables. This must be executed first.
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS
LOCAL_MODULE_TAGS define when this module should be built. The value 'optional' means that the module is not built by default and is only included when explicitly built.
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE
LOCAL_MODULE specifies the name of your system app. It does not have to match the package name.
LOCAL_MODULE := MySystemApp
LOCAL_SRC_FILES
LOCAL_SRC_FILES lists the source files to be used in the build. You can use the 'call all-java-files-under' function to reference all Java files within a specific folder.
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PRIVILEGED_MODULE
LOCAL_PRIVILEGED_MODULE determines whether the system app is a privileged module. If set to true, the app will be built as a privileged system app.
LOCAL_PRIVILEGED_MODULE := true
LOCAL_JAVA_LIBRARIES
LOCAL_JAVA_LIBRARIES specify additional Java libraries needed for building the app.
LOCAL_JAVA_LIBRARIES := framework
include $(BUILD_PACKAGE)
BUILD_PACKAGE includes a script file containing commands needed to build the system app package.
include $(BUILD_PACKAGE)
2.2. Additional Settings
If needed, you can apply additional settings to the .mk file. For example, to limit the permissions defined in AndroidManifest.xml to be only available for system apps, you can add the following line to the .mk file:
LOCAL_REQUIRED_PERMISSIONS := android.permission.MY_SYSTEM_ONLY_PERMISSION
In the above example, replace 'android.permission.MY_SYSTEM_ONLY_PERMISSION' with the desired system-only permission.
Through additional settings, you can fine-tune various aspects of the build, such as source code, resource files, dependencies, etc.
With that, we have learned how to write .mk files. In the next chapter, we will discuss other additional configuration methods.
Chapter 3. Additional Configurations
In this chapter, we will explore additional elements to consider in the configuration process for AOSP system apps.
3.1. Building AIDL Interfaces
If the system app uses an AIDL interface, the interface file must be added to the .mk file.
LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/aidl LOCAL_SRC_FILES := $(call all-aidl-files-under, aidl)
The code above sets the reference to the 'aidl' directory containing AIDL interface files. This will automatically compile AIDL files in the directory during the system app build process.
3.2. Configuring Additional Resource Directories
If the app uses multiple resource folders, these additional folders must be included in the .mk file. For instance, if using an additional resource directory called 'res_extra', configure it as follows:
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/res_extra
3.3. Building C/C++ Native Code
If the app uses C/C++ native code, the code must be built and incorporated using the NDK with the following additional settings in the .mk file:
LOCAL_C_INCLUDES := $(LOCAL_PATH)/native/include LOCAL_SRC_FILES := native/my_native_lib.c LOCAL_CFLAGS := -DUSE_MY_NATIVE_LIB
The code above references the native library 'my_native_lib.c' file and related header directories while specifying the symbol definition for using the library.
Example:LOCAL_C_INCLUDES := $(LOCAL_PATH)/jni/include LOCAL_SRC_FILES += $(call all-c-files-under, jni) LOCAL_JNI_SHARED_LIBRARIES := my-native-lib
3.4. ProGuard Configuration
If the system app employs ProGuard for code reduction and obfuscation, the .mk file must include the ProGuard configuration file like this:
LOCAL_PROGUARD_ENABLED := $(MY_PROGUARD_ENABLED) LOCAL_PROGUARD_FLAG_FILES := $(LOCAL_PATH)/proguard.flags
The code above enables ProGuard and utilizes the 'proguard.flags' file.
We have now reviewed additional configurations for AOSP system app settings. The proper use of these configurations allows fine-tuning of system app build attributes.
Chapter 4. Building and Testing System Apps
In this chapter, we will explore how to build and test system apps developed in AOSP.
4.1. Building System Apps
First, you need to ensure that your development environment supports AOSP builds. Factors such as the operating system, Java Development Kit (JDK) version, and source code must all be compatible. For more information, please refer to the official Android Build Requirements document.
Once your development environment is ready, you need to add your system app to the AOSP build. Include the app's source code directory and the path containing the .mk files in the AOSP build system. Generally, system apps are located in the `packages/apps` directory.
After successfully adding the app, the entire AOSP build process will also build the system app. Start the build with the following commands:
source build/envsetup.sh lunch make -j4
After the AOSP build is complete, you can find the built system app in the `out/target/product/{device-name}/system/app` path.
4.2. Testing System Apps
To test the developed system app on a real device or emulator, follow these steps:
- Install the system image created by the AOSP build on the device.
- After booting the device, launch the developed app and verify it functions correctly.
- Examine the app's overall functionality, performance, and usability.
- If a problem occurs, debug and fix it by checking the logs.
- Test in various environments and devices with both the device and emulator to check compatibility.
- Prepare for deployment once all tests are complete.
System app testing involves not only verifying the app's proper functioning but also reviewing various factors such as interaction with the system and resource usage.
With this, we have explored how to build and test system apps. In the next chapter, we will summarize and conclude the entire content.
Chapter 5. Overall Review and Summary
In this document, we have addressed the main concepts and processes related to system app development through AOSP. In this chapter, we will provide a brief summary of the information covered in previous chapters.
5.1. Summary
- System App Development Overview: A system app is installed in the system area and can use special permissions and features, unlike regular apps.
- Writing .mk Files: Build settings are defined in .mk files, which control the system app build process. This file contains variables and commands, as well as various settings depending on the requirements.
- Additional Configurations: Additional elements needed for the system app build process can be applied. These settings include AIDL interfaces, extra resource folders, native code builds, and ProGuard configurations.
- Building and Testing System Apps: Build system apps in AOSP and test them on a device or emulator to verify their correct operation. The testing process involves various factors such as functionality, performance, and compatibility.
5.2. In Conclusion
Android system app development is a challenging topic and requires a lot of experience and expertise. This guide has covered the basics of AOSP system app development. We hope this serves as a foundation for further study and practical experience. We look forward to seeing you create apps that provide a safe and rich user experience to users through system app development.
0 개의 댓글:
Post a Comment