Android aapt: Merging resources from libraries

Refer to Android Application, Android Libraries and Jar Libraries for a good explanation of how Android sdk compiles Android libraries into an application apk.

To generate the R.java manually with aapt tool, use for example: (the command is a single line)

1     aapt package -v -f -m --auto-add-overlay
2 -S res -S libs/supertooltips/res -J gen
3 --extra-packages com.haarman.supertooltips
4 -M AndroidManifest.xml
5 -I /opt/java/adk/platforms/android-14/android.jar
6

In the newer version of aapt, --extra-packages is used to generate the same R.java for each of the libraries with just a single call to aapt.

See Android Tools: Build changes in revision 14

aapt performance with library projects.
A project that references libraries must generate the R class in its package for its own code, but it must also generate the same file in each of its libraries’ packages so that the library code can find their resources.

The previous implementation ran the same aapt command multiple times to generate all those files leading to long build time for large project where aapt can take a while to run. In r14 (requiring Platform-Tools r8), aapt is run only once to generate all the necessary files. This basically at least halves the aapt step for projects with libraries.

In prior version of aapt, one will need to generate the R.java multiple times with aapt tool. For example, for the application R.java

1     aapt package -v -f -m --auto-add-overlay
2 -S res -S libs/supertooltips/res -J gen
3 -M AndroidManifest.xml
4 -I /opt/java/adk/platforms/android-14/android.jar
5

and for the library R.java using --custom-package

1     aapt package -v -f -m --auto-add-overlay
2 -S res -S libs/supertooltips/res -J gen
3 --custom-package com.haarman.supertooltips
4 -M AndroidManifest.xml
5 -I /opt/java/adk/platforms/android-14/android.jar
6

Comments

blog comments powered by Disqus