In Android.mk, you defined a module using variables and finished with an include $(BUILD_...) rule. In Android.bp, the entire block is defined by the Module Type.
Soong supports dozens of specific module types. Here are the most critical ones you will encounter in the modern AOSP source tree.
C/C++ Native Modules (cc_)
The cc_ prefix stands for C/C++ Compiler. These modules generate native code.
cc_binary: Compiles source files into an executable binary that can be run from the Android shell.cc_library_shared: Compiles source files into a dynamically linked library (.so).cc_library_static: Compiles source files into a statically linked archive (.a).cc_library: A hybrid type. It automatically generates both a shared and a static version of the library, allowing other modules to choose which version they want to link against dynamically.
cc_library {
name: "libcustommath",
srcs: ["math.cpp"],
export_include_dirs: ["include"],
}
Java Modules (java_)
The java_ prefix handles standard Java (and Kotlin) compilation for libraries that do not require Android-specific resources (like XML layouts or a manifest).
java_library: Compiles Java source files into a.jarfile. These are typically used for internal framework components or background services that run on the device.java_library_host: Compiles a.jarfile designed to run on your Ubuntu host machine (often used for build tools or code generators), not on the physical Android device.
Android Application Modules (android_)
The android_ prefix is used when the module relies on the Android SDK and includes Android resources (like the AndroidManifest.xml or res/ folders).
android_app: Compiles an actual Android Package (.apk) that can be installed and launched.android_library: Compiles an Android Archive (.aar), which contains both compiled Java code and Android resources, meant to be consumed by anandroid_app.
android_app {
name: "MyCustomSettings",
srcs: ["src/**/*.java"],
resource_dirs: ["res"],
certificate: "platform",
platform_apis: true,
}
Utility Modules
filegroup: This is a convenience module. Instead of listing 50 source files in multiple different modules, you can define them once in afilegroup. Other modules can then reference the group cleanly by its name.genrule: Because Blueprint does not allow arbitrary shell scripts,genruleis the official escape hatch. It allows you to run a custom bash command during the build process to generate a file (e.g., running a python script to auto-generate a C++ header file).
genrule {
name: "generate_headers",
srcs: ["input.txt"],
out: ["output.h"],
cmd: "python $(location script.py) $(in) > $(out)",
}