9

Is there a way to speed up the compilation and deployment to device of the android project using maven?

I tested build time of a blank android project (created from command line using 'android create project') in IntelliJ Idea - it took me 4 seconds from pressing the 'run' button until launching the app on device. Then I added maven support to it - now it takes almost 7 seconds.

For bigger projects it takes even more time. For example, blank project with ActionBarSherlock dependency added takes about 25-30 seconds to compile, deploy and run.

Is there a way to speed up this process?

I would like to hear answers from Square developers (especially Jake Wharton) :) how long does it take your android projects to compile?

agamov
  • 4,407
  • 1
  • 27
  • 31
  • 1
    AAPT trick mentioned in [this answer](http://stackoverflow.com/questions/13335674/speed-up-android-project-build-time-in-intellij-idea/13391537#13391537) may help. – yorkw Nov 28 '12 at 20:07

6 Answers6

4

Couple things I did which gave me a little improvement:

  • Turning off dex optimization for debug builds
  • Turning on library pre-dexing (which slows down the first build but speed up the followings)

Configuration is something like:

<plugin>
    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
    <artifactId>android-maven-plugin</artifactId>
    <inherited>true</inherited>
    <configuration>
        <!-- All your current configuration -->
        <dexOptimize>false</dexOptimize>
         <dex>
            <preDex>true</preDex>
            <preDexLibLocation>/tmp/predexedLibs</preDexLibLocation>
        </dex>
    </configuration>
</plugin>

BTW I suspect there are some problems with the incremental compiler and every time all the code is ricompiled from scratch.

rciovati
  • 27,603
  • 6
  • 82
  • 101
  • I have the same issue, my build time is around 26 seconds. I tried the settings rciovati mentioned but with false in dexOptimize tag and I gained 2 secs. Here are the tags I used: !-- All your current configuration --> false true /tmp/predexedLibs – dimlah Sep 18 '13 at 07:35
  • I guess there is a bigger speedup if you use a fair number of libraries. – rciovati Sep 18 '13 at 09:05
  • I am using around 15 libs including android, compatibility etc. The thing is that during build I can see that dex command takes still some time to be executed, even if the libraries are predexed. Any ideas? – dimlah Sep 18 '13 at 09:15
  • The bottleneck is that AFAIK (but maybe I'm wrong) Android Maven Plugin doesn't support incremental dexing. – rciovati Sep 18 '13 at 09:29
  • Thanks for this. Give me a slight boost. – AndroidDev Apr 08 '14 at 09:34
3

Maven 3 has multi-threaded builds. I'd at least try it out. Given you're already at 20 secs, it might not do much, but it certainly sped up our larger maven builds

mvn -T 4 clean install # Builds with 4 threads
mvn -T 1C clean install # 1 thread per cpu core
mvn -T 1.5C clean install # 1.5 thread per cpu core

Parallel builds in Maven 3

Matt Broekhuis
  • 1,985
  • 2
  • 26
  • 35
2

25-30 Seconds to make, deploy and run an App? Lucky guy! I'm working on a Windows Laptop...

Here're the few things I do to speed up my development:

  • I made some good progress by putting the emulators image and SD-Drive on an SSD.
  • Running the emulator from a snapshot starts it faster.
  • When it's possible I run my code on an actual device instead of an emulator - depending on the actual device this is much faster (2x on my Sony Xperia) even with the virtualized emulator. Of course the downside of this is, that you cannot test different Android versions and device profiles.

But still with all the little changes in the emulator, deployment goes thru the TCP/IP Stack which is the bottleneck for it.

PS: I'm not Jake Wharton and dont know him. But if he can change something on the deployment he should do so :-)

jboi
  • 11,324
  • 4
  • 36
  • 43
1

You can try setting higher -Xms and -Xmx options for MAVEN_OPTS.

Also, ensure maven in idea is not configured to download/syncronizing with repository for jars every time.

You can also through some decent hardware upgrade ;-)

appbootup
  • 9,537
  • 3
  • 33
  • 65
1

The answer is somehow strange, but Jake Wharton advised to move to gradle-builds which are truly incremental. Also using Genymotion instead of SDK emulators and USB-devices gave me much needed decrease in deploy time.

So now my build time decreased from ~1m to ~10-20sec.

agamov
  • 4,407
  • 1
  • 27
  • 31
0

You can try to use tools that upload only delta changes to the emulator: only changed classes will be pushed to the device, should save some time. You can try the tool: http://www.instareloader.com/download/ use "inirwetrust" as the password

Den Fokas
  • 340
  • 3
  • 4