Doug
Doug

Reputation: 313

Why does my build takes so long is Android Studio?

My build takes to long in Android Studio, more than 2 minutes, sometimes 3'. I tried some methods explained in StackOverflow to accelerate the build time, but it didn't solve my problem.

My build.gradle code for app module is the following:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

// Adding The GIT SHA to Crashlytics crash reporting
def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.moymer"
        minSdkVersion 11
        targetSdkVersion 22
        multiDexEnabled true
        versionCode 5
        versionName "2.0.0"

        buildConfigField "String", "GIT_SHA", "\"${gitSha}\""
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            testCoverageEnabled true
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.google.android.gms:play-services:7.5.0'
    compile 'com.android.support:design:22.2.0'
    compile 'com.github.nirhart:parallaxscroll:1.0'
    compile 'com.android.support:multidex:1.0.0'
    compile('com.crashlytics.sdk.android:crashlytics:2.4.0@aar') {
        transitive = true;
    }
    compile 'in.srain.cube:grid-view-with-header-footer:1.0.12'
    compile 'com.android.support:recyclerview-v7:23+'
    compile 'com.squareup:otto:1.3.8'
    compile 'com.android.support:percent:23.0.0'
    compile 'com.jakewharton.timber:timber:3.1.0'
    compile project(':androidffmpeglibrary')
}

My gradle.properties file is the following:

org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.configureondemand=true

Upvotes: 3

Views: 2227

Answers (2)

Akeshwar Jha
Akeshwar Jha

Reputation: 4576

As CommonsWare depicted, having a lot of dependencies does slow down the overall build. As of now, you can start using Android Studio 2.0 which has the instant run feature.

Instant run cuts down the build time by a big factor because it only pushes the small changes that are not. Whatever changes you do in the code, are first classified into three categories - hot swap, warm swap and cold swap. Lesser the load, warmer the swap, quicker the build-time.

Big structural changes like changing annotations, static fields etc come into cold swap. Changes in the manifest file also comes in the cold swap. You can check the full list here.

The good news is most of the small changes fall in the hot swap and these changes are quickly pushed in the running application as soon as you press the run button. The relevant activity restarts, and you can see your changes in a few seconds.

Stable version of Android Studio 2.0 is released and you can download it from this link. It has this instant run feature. Hope this helps.

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1007494

You have 11+ dependencies and an extra plugin. At least one (androidffmpeglibrary) would appear to involve the NDK. That is not going to be fast, particularly depending on your build hardware.

If you want a faster build, get rid of some of that junk. For example, there have been finer-grained Play Services SDK dependencies for over a year; use only the pieces that you need, rather than the "everything but the kitchen sink" play-services artifact. That, in turn, might allow you to dump multidex, as you might fall back below the 64K DEX method reference limit.

The Android Tools team is working on improving the build speed, which will show up in newer versions of the Android Plugin for Gradle. That must be in your top-level build.gradle file, as I don't see where you are including that here. Make sure you are on the latest one, and keep updating it as new editions come out.

Upvotes: 5

Related Questions