What is AOSP?
AOSP (Android Open Source Project) is an open source project for the Android operating system managed by Google. The goal of this project is to develop and maintain the Android operating system that can run on various platforms such as phones, tablets, wearable devices, etc.
Why is AOSP important?
AOSP provides the basis for developing and modifying the Android operating system which is the most widely used mobile operating system in the world. Through this, developers can customize the Android operating system to suit their needs. Thanks to this flexibility, Android has been able to be used in various devices and scenarios.
AOSP and .mk, .bp files
The build system of AOSP uses .mk and .bp files to manage the project configuration. These files refer to Android Makefile (.mk) and Blueprint (.bp) files respectively, and are used to define and control the build process of the AOSP project.
Android.mk and Android.bp
Android.mk is a file that has been traditionally used in the Android operating system's build system. This file follows the syntax of the make build system and specifies the location of each module's source code, required libraries, build options, etc.
Android.bp is a file for the recently introduced Blueprint build system. This file is processed using a tool called Soong written in the Go language. Android.bp files use a syntax similar to JSON which is more concise and easier to understand compared to Android.mk.
Reason for the change
The transition from Android.mk to Android.bp is part of Google's efforts to make the build system faster and more efficient. In particular, the Blueprint build system provides faster build times compared to Android.mk, and uses a more concise and clearer syntax.
The role of .mk and .bp files
.mk and .bp files are key elements of the AOSP build system. These files represent Android Makefile (.mk) and Blueprint (.bp) files respectively, and play a role in defining the build configuration of the AOSP project and controlling the build process.
The role of Android.mk files
Android.mk files follow the syntax of Make, Android's traditional build system. Each Android.mk file defines one or more modules, which represent units of build output that the AOSP build system needs to generate.
Modules contain information such as source file locations, required C/C++ libraries, compiler flags, etc. Based on this information, the build system generates build rules for each module.
The role of Android.bp files
Android.bp files are for Google's recently introduced Blueprint build system. These files are processed using a tool called Soong written in the Go language.
Android.bp files define build rules using a syntax similar to JSON that is more concise and easier to understand than Android.mk. These files play an important role in making the build system faster and more efficient.
Comparison between Android.mk and Android.bp
While Android.mk and Android.bp have the same goal, the way they process things is very different. Android.mk defines build rules using Makefile syntax, whereas Android.bp defines build rules using a JSON-like syntax.
The complexity of Makefiles and slow build times caused many difficulties for developers with Android.mk. In contrast, Android.bp uses a more concise and understandable syntax, and provides a faster and more efficient build system.
Coexistence of Android.mk and Android.bp
Currently, AOSP supports both Android.mk and Android.bp files. This will continue until the Blueprint build system is fully stabilized and all build rules have been migrated to Android.bp.
Therefore, it is important for developers to understand both Android.mk and Android.bp files, and grasp the pros and cons of each.
Syntax of .mk and .bp files
.mk and .bp files play important roles in the AOSP build system. Understanding each syntax is very important to understand the build process of AOSP.
Android.mk syntax
Android.mk files follow the syntax of GNU Makefiles. These files consist of multiple "variable assignments" and "build rules".
Variable assignments take the form of "variable := value", while build rules take the form of "target: dependencies". The target represents the file that the build system wants to generate, while dependencies represent the input files required to generate that file.
Android.bp syntax
Android.bp files use a syntax similar to JSON. These files consist of one or more "module definitions".
Each module definition takes the form of "module_type { ... }", where module_type is a keyword that indicates how the build system should build the module. Inside the braces { ... } are the properties of the module.
For example, an Android.bp file that defines a C++ library would look like:
cc_library {
name: "my_library",
srcs: ["my_source.cpp"],
cflags: ["-Wall", "-Werror"],
}
In the above example, "cc_library" is the module_type, and "name", "srcs", "cflags" are properties of the module.
Transition from .mk to .bp files
Google is gradually transitioning Android's build system from Android.mk to Android.bp. This is to improve the speed of the build system and make build rules more concise and understandable.
The process of converting Android.mk files to Android.bp files is generally as follows:
- Analyze the contents of the Android.mk file.
- Convert each Android.mk module to the corresponding Android.bp module type.
- Convert Android.mk variable assignments to Android.bp property assignments.
- Convert build rules to Android.bp module definitions.
Example of conversion
For example, here is an example of converting from Android.mk to Android.bp:
Android.mk:
include $(CLEAR_VARS)
LOCAL_MODULE := my_module
LOCAL_SRC_FILES := my_source.c
LOCAL_CFLAGS := -Wall -Werror
include $(BUILD_SHARED_LIBRARY)
Android.bp:
cc_library_shared {
name: "my_module",
srcs: ["my_source.c"],
cflags: ["-Wall", "-Werror"],
}
In the above example, "LOCAL_MODULE", "LOCAL_SRC_FILES", "LOCAL_CFLAGS" variables were converted to "name", "srcs", "cflags" properties in Android.bp, respectively. Also, "include $(BUILD_SHARED_LIBRARY)" was converted to the "cc_library_shared" module type.
Precautions when writing .mk and .bp files
There are some precautions to remember when writing .mk and .bp files. These files are core parts of the AOSP build system, so they must be written accurately for the build process to work correctly.
Android.mk precautions
1. When writing an Android.mk file, you must properly understand GNU Makefile syntax. Makefile syntax is complex and can lead to unexpected results if used improperly.
2. In Android.mk files, you need to precisely understand how each variable assignment affects the build system. For example, the "LOCAL_MODULE" variable defines the name of the generated build output.
Android.bp precautions
1. When writing an Android.bp file, you must properly understand the JSON-like syntax. Using incorrect syntax can prevent the build system from properly parsing the file.
2. In Android.bp files, you need to precisely understand how each property assignment affects the build system. For example, the "name" property defines the name of the generated build output.
General precautions
1. When writing .mk and .bp files, you should always reference the latest AOSP build documentation. The AOSP build system is constantly updated so you need to stay informed.
2. Build rules should be written as concisely as possible. Complex build rules can slow down the build process and cause errors.
Testing and validation
3. Changes to .mk and .bp files should always be tested. Changes to build rules can greatly affect the build process and generated build outputs, so you need to verify the build process still works correctly after applying changes.
4. You should also validate that the generated build outputs work as expected. This is especially important when build rule changes can affect the functionality of the build outputs.
Code reviews
5. When possible, changes to .mk and .bp files should go through code reviews. Code reviews help catch potential issues and improve code quality.
Documentation
6. Finally, changes to .mk and .bp files should be documented. This helps other developers understand and modify the code if needed.
Conclusion
The build system of AOSP manages project build configurations through .mk and .bp files. Android.mk uses traditional Makefile syntax while Android.bp uses a concise and understandable JSON-like syntax.
Google is currently transitioning the build system from Android.mk to Android.bp. This is to improve build system speed and make build rules more concise and understandable.
When writing or modifying .mk and .bp files, you need to properly understand the syntax and grasp how it affects the build system. Testing and documenting changes is also important.
The AOSP build system is a complex and broad topic, so there are many details not covered in this document. To understand these details, referencing AOSP's official documentation and code is best.
Understanding the AOSP build system plays an important role in modifying or customizing the Android operating system. This allows developers to effectively tune the Android OS to their needs.