Reputation: 7806
We have changed our Android app project to use gradle, but have noticed it is building significantly slower.
Before with ANT:
6 sek / 50 sec (with clean)
After with gradle:
30 sek / 80 sec (with clean)
I have profiled the solution with:
gradle assembleDebug --profile
The main tasks in the resulting report was thies tasks: (in the build without clean)
:packageDebug 10.690s
:processDebugResources 8.795s
:compileDebugJava 7.644s
I don't have any ideas about getting more details information about thies tasks.
Is this normal? How could this be improved?
I know the new build system is still in betas, but it seems like others are building much faster.
I have looked around without finding a solution I have tried several things including making sure gradle deamon is enabled with a gradle.properties file containing this:
org.gradle.daemon=true
org.gradle.jvmargs=-Xms128m -Xmx256m
org.gradle.parallel=true
build.gradle:
buildscript {
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
classpath 'com.google.guava:guava:14.0.1'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
classpath 'me.tatarka:gradle-retrolambda:1.1.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2'
}
}
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
apply plugin: 'android'
apply plugin: 'crashlytics'
apply plugin: 'retrolambda'
apply plugin: 'android-apt'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.google.guava:guava:14.0.1'
compile 'com.crashlytics.android:crashlytics:1.+'
apt "org.androidannotations:androidannotations:3.0.1"
compile "org.androidannotations:androidannotations-api:3.0.1"
}
apt {
arguments {
resourcePackageName "com.example"
androidManifestFile variant.processResources.manifestFile
}
}
android {
packagingOptions { //Fix: http://stackoverflow.com/a/20675331/860488
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileSdkVersion 10
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 10
buildConfigField "boolean", "useProductionServices", "true"
}
buildTypes {
testflight.initWith(buildTypes.debug)
debug {
packageNameSuffix ".debug"
buildConfigField "boolean", "useProductionServices", "false"
}
testflight {
packageNameSuffix ".testflight"
buildConfigField "boolean", "useProductionServices", "true"
}
release {
buildConfigField "boolean", "useProductionServices", "true"
}
}
}
retrolambda {
compile "net.orfjackal.retrolambda:retrolambda:1.1.2"
jdk System.getenv("JAVA8_HOME")
}
Upvotes: 14
Views: 10393
Reputation: 7806
Adding a gradle.properties
file with this content helps a bit:
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx256m
EDIT:
I have just read this blogpost which has 6 tips to improve gradle build speed:
6 tips to speed up your Gradle build
Upvotes: 3
Reputation: 9697
I have same issue and solved by this setting :
File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle -> Offline work
after this setting reduce time by 3 minute to 2s728ms
Upvotes: 3
Reputation: 3221
**** Talking about new version of AS in old question thread may look weird.But I feel it may help someone else, who looks for an answer****
AndroidStudio 2.0 Will probably help you out to improve the build process.
The following things will play major role in improving the build process with 2.0
Instant Run - You need to enable it in the Settings. File-Settings-Instant Run. Then enable it
AS 2.0 Actually includes the app restart option to improve the deployment.
If you have modules in your project. 2.0 will do pre-dexing it and keep it to build. Until we have any changes in the module, it does not require to re-dex and it dex'es only the modify piece to run on the device/emulator. Seriously, that saves lot of time. Do module based business.
Progaurd optimization and obfuscation tasks also plays a role in slowing down the building process. Do the following to stop optimizing and obfuscating with progaurd while you wants only debug mode.
android { buildTypes { debug { minifyEnabled true useProgaurd false } release { minifyEnabled true useProgaurd true } } }
One more tips every developer would suggest commonly is make the Gradle plugin offline mode enabled if you do not added any new library dependencies for particular build process.
Upvotes: 0