• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

[DevTOOL][2012-10-01] Fast AAPT (#2) - Speed up Eclipse/apktool/etc

Search This thread

Chainfire

Moderator Emeritus / Senior Recognized Developer
Oct 2, 2007
11,442
87,710
www.chainfire.eu
Presenting: Fast AAPT - aka FAAPT ;)

Lately Android development has been getting me down. Slow builds all over the place in many of my app projects, and my PC is blazing fast - it shouldn't all be that slow, even if you're running Eclipse!

Working on DSLR Controller has been driving me mad - testing a minor change in the underlying communications library, then building and launching the app - ugh! So I set out to fix this. I had done all the usual tricks, even gave Eclipse loads more memory (helped with regular performance, but not building) but nothing major seemed to change. Then I figured out most of the time building was spent in AAPT. So I synced my AOSP repo (2012.09.26, took a few minutes), tried to get the Windows SDK to build on my Linux box (took several hours) and finally got to actually mucking with the source.

Found the bottleneck (for my long-build-time projects at least, related to XML file compilation) and fixed it (by introducing a simple cache). "DLSR Controller" build time has gone down from 35 seconds minimum, to 2-3 seconds ( >10 times faster). Hell, I can even turn "Build Automatically" back on without getting constant delays!

Note that my build times quoted only apply to incremental internal builds. If your images still need to be "crushed" (optimized), or you're "exporting" an APK (final build for publication), build time will still be significantly longer. However, during normal development and testing (by far most builds if you're making an app in Eclipse) those stages are not performed, and builds should be lightning fast.

"Fixed" is a big word though, right now it's more of a "hack", and it needs some pollish, so the patch can be submitted to AOSP. I don't want to keep it from you for that long, so my first test build is attached - don't use it in production builds..

Patch code has been submitted to:
AOSP - #1 Cancelled, #2 Review in Progress ... superseded by ctate rewrite
AOKP - #1 Merged, #2 Merged
CM - #1 Cancelled, #2 Merged

Attached ZIP includes Linux, Windows and Mac OS X versions.

The files are drop-in replacement, but I would certainly advise you to backup the originals for your production builds! :) Also, don't forget to chmod/chown on Linux or it won't work.

Enjoy and leave some feedback :)

Will this help your project build ?

A quick way to spot if this will have effect on your slow build is as follows:

- In Eclipse, set Build output to Verbose under Window -> Preferences -> Android -> Build.
- Clean and build your project.
- If the build pauses on lines in the "(new resource id <filename> from <filename>)" format, you have the problem FAAPT fixes :)

(of course, you can also run aapt manually if you know how, you'll get the same output)

In a full framework build the optimizations only affect a very small portion of the actions done during the build, so you won't see any spectaculair speed increases there.

Update (#2)

I have updated the patch code to fix problems with Mac OS X compatibility, I've also included a Mac OS X binary in the new zip file.

-----

( v1: 557 )
 

Attachments

  • faapt-2.zip
    1.1 MB · Views: 4,208
Last edited:

Chainfire

Moderator Emeritus / Senior Recognized Developer
Oct 2, 2007
11,442
87,710
www.chainfire.eu
Thanks brother, gonna give it a try right now on Linux :)

EDIT:

It works. Gave it three tries. Went consistently around 19.1 sec with FAAPT and 33.9 sec with regular AAPT. This is on the Linux version. Good job :)

Glad to hear the Linux version also works! Too bad your increase is not as much as mine, but I guess it depends heavily on the amount and type of assets in your project.
 

wildstang83

Inactive Recognized Developer / Recognized Themer
Oct 14, 2010
4,627
4,089
Nowheresville
forum.xda-developers.com
Glad to hear the Linux version also works! Too bad your increase is not as much as mine, but I guess it depends heavily on the amount and type of assets in your project.

I tested on a theme project of mine, so its heavy in img files. Thats probably why. I'm not complaining one bit. Absolutely love it and can't wait to try it out on my other apps :)
 

wanam

Recognized Contributor / Developer
Jan 26, 2011
6,194
29,976
Toulouse
wanam.net
Glad to hear the Linux version also works! Too bad your increase is not as much as mine, but I guess it depends heavily on the amount and type of assets in your project.

Indeed, tested the Windows version and yes it gives a very good result with a amount of assets, i got 7 time faster than the normal one on Eclipse, too bad we can't use it for production, we need one for Apktool :) .
 

zoltan.fekete

Member
Dec 23, 2009
32
3
On my projects I see anywhere from 5 to 20x speed increase on build. Thank you for this magic.
I don't get how the google android SDK team did not optimize this (I know they done some crazy optimizations for different stuff).
 

Top Liked Posts

  • There are no posts matching your filters.
  • 113
    Presenting: Fast AAPT - aka FAAPT ;)

    Lately Android development has been getting me down. Slow builds all over the place in many of my app projects, and my PC is blazing fast - it shouldn't all be that slow, even if you're running Eclipse!

    Working on DSLR Controller has been driving me mad - testing a minor change in the underlying communications library, then building and launching the app - ugh! So I set out to fix this. I had done all the usual tricks, even gave Eclipse loads more memory (helped with regular performance, but not building) but nothing major seemed to change. Then I figured out most of the time building was spent in AAPT. So I synced my AOSP repo (2012.09.26, took a few minutes), tried to get the Windows SDK to build on my Linux box (took several hours) and finally got to actually mucking with the source.

    Found the bottleneck (for my long-build-time projects at least, related to XML file compilation) and fixed it (by introducing a simple cache). "DLSR Controller" build time has gone down from 35 seconds minimum, to 2-3 seconds ( >10 times faster). Hell, I can even turn "Build Automatically" back on without getting constant delays!

    Note that my build times quoted only apply to incremental internal builds. If your images still need to be "crushed" (optimized), or you're "exporting" an APK (final build for publication), build time will still be significantly longer. However, during normal development and testing (by far most builds if you're making an app in Eclipse) those stages are not performed, and builds should be lightning fast.

    "Fixed" is a big word though, right now it's more of a "hack", and it needs some pollish, so the patch can be submitted to AOSP. I don't want to keep it from you for that long, so my first test build is attached - don't use it in production builds..

    Patch code has been submitted to:
    AOSP - #1 Cancelled, #2 Review in Progress ... superseded by ctate rewrite
    AOKP - #1 Merged, #2 Merged
    CM - #1 Cancelled, #2 Merged

    Attached ZIP includes Linux, Windows and Mac OS X versions.

    The files are drop-in replacement, but I would certainly advise you to backup the originals for your production builds! :) Also, don't forget to chmod/chown on Linux or it won't work.

    Enjoy and leave some feedback :)

    Will this help your project build ?

    A quick way to spot if this will have effect on your slow build is as follows:

    - In Eclipse, set Build output to Verbose under Window -> Preferences -> Android -> Build.
    - Clean and build your project.
    - If the build pauses on lines in the "(new resource id <filename> from <filename>)" format, you have the problem FAAPT fixes :)

    (of course, you can also run aapt manually if you know how, you'll get the same output)

    In a full framework build the optimizations only affect a very small portion of the actions done during the build, so you won't see any spectaculair speed increases there.

    Update (#2)

    I have updated the patch code to fix problems with Mac OS X compatibility, I've also included a Mac OS X binary in the new zip file.

    -----

    ( v1: 557 )
    2
    Thanks brother, gonna give it a try right now on Linux :)

    EDIT:

    It works. Gave it three tries. Went consistently around 19.1 sec with FAAPT and 33.9 sec with regular AAPT. This is on the Linux version. Good job :)

    Glad to hear the Linux version also works! Too bad your increase is not as much as mine, but I guess it depends heavily on the amount and type of assets in your project.
    2
    The patch is indeed in the very latest ADT tools !
    2
    apktool and Maps.apk on Linux.
    aapt - 29.2s to compile
    faapt - 2.2s to compile
    Amazing job, Chainfire!
    2
    Hey,

    Disclaimer: this might just be me missing a readme somewhere or doing something wrong!

    I've been building K-9 ( android e-mail client ) since 2 years, when I read about this I tried it. Just swapped out the aapt binary on my linux system. Ever since I had resource troubles ( weren't found in the app ). Only when I switched back it worked again. I'm back at the default aapt for now, just letting you know.

    Will try to reproduce and fix :)

    Note sure what is going on here. I have installed the sources and dependencies on my Windows system (my Linux system is currently not equipped to build stuff like this, will try later) and produced files both in aapt as well as in faapt mode - with identical results.

    I'm going to try this on my pc running linux

    Any chance for arm version ?

    The patches have been posted/submitted (see first post, AOKP currently has a full up-to-date merge), feel free to build an ARM version yourself - I'm not planning to.