Mobile Development 9 min read

Android Build Process: From Resource Merging to APK Packaging

The article walks Android developers through the entire Gradle build pipeline—detailing resource merging and conflict resolution, AAPT compilation into binary resources, Java and AIDL processing, multi‑dex generation with ProGuard considerations, providing code examples for each stage.

Tencent Music Tech Team
Tencent Music Tech Team
Tencent Music Tech Team
Android Build Process: From Resource Merging to APK Packaging

This article provides a comprehensive overview of the Android build process, explaining each major step from resource merging to final APK packaging. The content begins by introducing the curiosity about Android Gradle plugin and then systematically covers resource merging, AAPT packaging, source code compilation, DEX generation, signing, and ZIP alignment.

The resource merging section explains how Android handles conflicts between local resources and third-party dependencies, including the priority order for manifest merging (buildType > productFlavor > src/main > dependency&library) and specific rules for resolving XML element conflicts. It also covers special cases like uses-feature, uses-library, and manifest element merging rules.

The AAPT (Android Asset Packaging Tool) section details how resources are compiled into binary format, including the creation of R.java and resources.arsc files. It explains the resource ID structure (4-byte unsigned integer with package ID, type ID, and resource index) and how the resources.arsc file serves as a mapping between resource IDs and file paths for runtime access.

Source code compilation covers the processing of AIDL and RenderScript files, followed by Java compilation using javac. The section also mentions code obfuscation through ProGuard configuration in build.gradle files.

The DEX generation section is particularly detailed, explaining the multi-dex process including the creation of main dex lists through manifest analysis, component class collection, and the use of shrinkXxxMultiDexComponents tasks. It highlights the challenges when ProGuard is enabled before DEX splitting and suggests using the mapping.txt file to correct manifest_keep.txt.

The final sections cover APK signing using jarsigner and ZIP alignment using the zipalign tool to improve resource access efficiency. The article concludes with a summary diagram showing the complete build process flow.

Throughout the article, code snippets are provided to illustrate Gradle configurations and key implementation details, making it a valuable technical reference for Android developers understanding the build system.

Android DevelopmentGradle PluginAAPT packagingAndroid build processAPK signingDEX generationmulti-dexresource mergingZIP alignment
Tencent Music Tech Team
Written by

Tencent Music Tech Team

Public account of Tencent Music's development team, focusing on technology sharing and communication.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.