Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android & Maven: Speed up project compilation and deploy

Tags:

android

maven

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?

like image 544
agamov Avatar asked Nov 28 '12 15:11

agamov


2 Answers

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.

like image 88
rciovati Avatar answered Nov 16 '22 01:11

rciovati


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

like image 39
Matt Broekhuis Avatar answered Nov 16 '22 02:11

Matt Broekhuis