3

I upgraded Android Studio to version 2.2.3 recently but since then build time has gone up to more than 5 minutes which is extremely frustrating. I have browsed through similar posts and tried to change configurations but nothing seems to work.

build.gradle

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

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
        classpath 'com.android.tools.build:gradle:2.1.3'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.3"
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    defaultConfig {
        applicationId "in.xx.yy"
        minSdkVersion 17
        targetSdkVersion 24
        versionCode 2001
        versionName "Stable Release 20"
        multiDexEnabled = true

        manifestPlaceholders = [manifestApplicationId          : "${applicationId}",
                                onesignal_app_id               : "XYZ",
                                onesignal_google_project_number: "XYZ"]
    }
    signingConfigs {
        debug {
            storeFile file("C:\\keys\\app.jks")
            storePassword "XYZ"
            keyAlias "XYZrelease"
            keyPassword "XYZ"
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.debug
            minifyEnabled true
            shrinkResources true
            debuggable false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            signingConfig signingConfigs.debug
            debuggable true
            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    dexOptions {
//        incremental true
        preDexLibraries false
        javaMaxHeapSize "4g"
    }

repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
    maven { url 'https://jitpack.io' }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
        transitive = true;
    }
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:cardview-v7:24.2.1'
    compile 'com.facebook.android:facebook-android-sdk:4.+'
    compile 'com.prolificinteractive:material-calendarview:1.2.0'
    compile 'com.onesignal:OneSignal:3.+@aar'
    compile 'com.google.android.gms:play-services-gcm:8.4.0'
    compile 'com.google.android.gms:play-services-auth:8.4.0'
    compile 'com.google.android.gms:play-services-ads:8.4.0'
    compile 'com.android.support:recyclerview-v7:24.2.1'
    compile 'com.makeramen:roundedimageview:2.2.1'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'commons-validator:commons-validator:1.4.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1@aar'
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.heinrichreimersoftware:material-intro:1.5.5'
}
apply plugin: 'com.google.gms.google-services'

gradle.properties

systemProp.http.proxyHost=192.168.1.200
org.gradle.jvmargs=-Xms1024m -Xmx4608m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.parallel=true
systemProp.http.proxyPort=3128
android.enableBuildCache=true

I am an Android newbie; am using Windows 10 PC with 8GB RAM. Any help will be appreciated.

Ranjan
  • 858
  • 2
  • 10
  • 17
  • 1
    What was the older version prior to the upgrade? – yogur Dec 26 '16 at 17:03
  • I was using version 2.2.1 – Ranjan Dec 26 '16 at 17:05
  • I have experienced performance issues in the past which were only solved by a fresh re-install of Android Studio. However, I've recently updated to version 2.2.3 as well and performance is decent. But, I also switched gradle to version 2.2.3. `classpath 'com.android.tools.build:gradle:2.2.3'` – yogur Dec 26 '16 at 17:09
  • I have already tried compiling with the gradle plugin version 2.2.3 but unfortunately the problem persisted – Ranjan Dec 26 '16 at 18:27
  • Can you show us which similar posts you have tried – cokceken Jan 02 '17 at 07:11
  • 1
    Did you check my answer here? http://stackoverflow.com/a/31633775/3145960 – Reaz Murshed Jan 02 '17 at 07:26
  • Your suggestion has helped. I have been able to reduce build time from 8 minutes to less than 2 minutes. Moreover, I am new to Android therefore wasn't aware that "Clean" is not required every time I run the application. "Clean" was removing all dex outputs which was taking a very long time to recreate. Thanks – Ranjan Jan 06 '17 at 12:16

1 Answers1

1

Please check the docs, especially the part about the "studio.vmoptions". With this file you can tell how much RAM can be used to run AS. Keep in mind to set/use the correct (desktop)-shortcuts... By default a 32-Bit-config shortcut is created, I guess (can't check it right now).

Martin Pfeffer
  • 12,471
  • 9
  • 59
  • 68