I have 5 modules in my project, it takes me 2 mins to build everytime, is there any way to speed up android studio build time?
You can try to add this in your build.gradle file inside the android closure
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
It will allocate large heap size for your dex process which usually takes more time in build.
You can change your your heap size according to RAM you have in your system like "2048M" for 2GB allocation.
Another idea might be using a faster repository. If your build is using mavenCentral() try to replace it with jcenter().
For me, adding the following two properties to the "gradle.properties" file in the project root improved performance considerably.
org.gradle.parallel=true
org.gradle.daemon=true
"org.gradle.parallel=true" does parallel processing of the modules. You may receive a message that the feature is experimental but it has worked for me without any problems.
"org.gradle.daemon=true" will keep a dedicated Gradle JVM running so that it is not re-started each time you do a build. This first build takes as long but subsequent builds are much quicker.
Hope this helps.
Yup you can speed up android studio build time.
1. You need to clean your project before building your project.
2. Close all other projects on which you are not working before build.
3. Allow auto build option.
According to this document https://developer.android.com/studio/build/multidex.html#dev-build
If you are using MultiDexApplication you can set minSdkVersion 21 for your develop productFlavors to mitigate the longer build times for multidex output.
productFlavors {
dev {
// Enable pre-dexing to produce an APK that can be tested on
// Android 5.0+ without the time-consuming DEX build processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the production version.
minSdkVersion 14
}
}
Related
We are having problems in building our multidex App. We keep receiving different java.lang.NoClassDefFoundError erros during the application boot.
We noticed that they are very likely related to the multidex issues. As the required classes for booting the App must be present in the primary DEX file and they are not being included in the classes.dex. We performed the steps described in https://developer.android.com/studio/build/multidex.html#keep
but the classes we specify in the multidex-config.txt, or even in the multidex-config.pro are not being placed in the primary dex file (classes.dex).
Do you guys have experience using the multiDexKeepFile or the multiDexKeepProguard? Does it really work? Is there any trick to make it work and place the files in the classes.dex?
Try updating your gradle plugin. I've seen that in 2.2.0 the configuration is ignored entirely. When I updated to 2.3.3 it started respecting the rules I set.
Example:
classpath com.android.tools.build:gradle:2.3.3
And in my default config I have this set:
multiDexEnabled true
multiDexKeepProguard file('proguard.multidex.config')
Also you may have to do a clean build before the changes are reflected.
I have the same problem.And i still don't know why.
But i found another solution,and it works.
In your app module's build.gradle add dexOptions:
android {
dexOptions {
additionalParameters = ['--multi-dex',
'--set-max-idx-number=60000',
'--main-dex-list='+projectDir+'/your_multidexconfig.txt',
'--minimal-main-dex'
]
}
}
You should check your minSdkVersion, if your minSdkVersion is >= 21, multiDexKeepProguard is not supported. Because the build tools has do the dex split by default.
More details:
https://developer.android.com/studio/build/multidex
I had used this libraries
1. GestureImageView
2. squarecamera
3. daimajia.slider
Gradle is taking so much time, I had done this to make gradle faster.
http://www.viralandroid.com/2015/08/how-to-make-android-studio-fast.html
Even though I had set in app gradle dexOptions{incremental true
javaMaxHeapSize "4g"
},
Please Corrent me If I am wrong, and please suggest me to get gradle faster.
using local gradle . is Prefernces->build->gralde , select Use local gradle distribution and Offline work. and maybe your android studio version is low,please update. and use JRebel.. some.. You need to upgrade your computer。。
In the official post detailing the features of the stable release of Android Studio 2.1, I came across this:
We are also speeding up build times by using in-process dex, which converts class files to dex files within the Gradle daemon process. This avoids the costly processing operation of creating separate dex processes. To use this feature, you will need to increase the amount of memory available to the Gradle daemon to at least 2GB (1 GB is the default).
Please, how can I increase the memory that's available to Gradle?
In Android Studio 2.1 open your gradle.properties file. Find the line
\# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
Uncomment the line. Gradle was faster after I did this.
In your app's build.gradle file, add the following:
android{
//....
dexOptions {
javaMaxHeapSize "2g"
}
}
I have not try this but it should works:
In graddle.build file:
apply plugin: 'java'
compileJava {
//raise heap
options.fork = 'true'
options.forkOptions.with {
memoryMaximumSize = '2048m'
}
}
If it does not work in Windows try to add it to a new file gradle.properties next to gradle.build
References: http://www.gubatron.com/blog/2014/07/29/solved-gradle-how-to-increase-the-java-compilers-available-heap-memory/
I hope it helps you
My application has a bunch of librarys that are essential that is why I was forced to use multidex support library and it works nicely. But where the problem shows is in the gradle buid speed. It takes on average 2minutes to build and when I am developing and testing this is quite annoying.
Is there a way to speed up my debug builds?
You can speed-up your development builds by specifying the minimum SDK version = 21.
Official documentation includes a whole section about that.
Example (from documentation):
android {
productFlavors {
// Define separate dev and prod product flavors.
dev {
// dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
// to pre-dex each module and produce an APK that can be tested on
// Android Lollipop without time consuming dex merging processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion 14
}
}
...
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Once you added the product flavors, you can use the devDebug task (instead of default debug task) for your development builds:
- from command line: run ./gradlew installDevDebug
- from Android Studio: open Build Variants window and select the devDebug build variant.
You should, of course, work against a device whose SDK >= 21.
There's also a solution for those who don't want to use flavors. As suggested in this gist, dynamically calculate the minSdkVersion value:
int minSdk = hasProperty('devMinSdk') ? devMinSdk.toInteger() : 14
apply plugin: 'com.android.application'
android {
...
defaultConfig {
minSdkVersion minSdk
...
}
}
In this example, we're checking if devMinSdk property defined, and if true - we're using it. Otherwise, we default to 14.
How do we pass devMinSdk value to build script? Two options:
Using command line:
./gradlew installDebug -PdevMinSdk=21
Using Android Studio preferences:
Go to Preferences (Settings on Windows) -> Build, Execution, Deployment -> Compiler -> put -PdevMinSdk=21 in Command-line Options text box.
Recently build cache was introduced by team working on Android Gradle plugin. You can enable it by adding android.enableBuildCache=true to gradle.properties.
More info here
http://tools.android.com/tech-docs/build-cache
For me it increased incremental build times by ~30 seconds.
It doesn't work with legacy multidex (com.android.support:multidex) introduced as part of support library, so it's suitable only if your minSDK >= 21. You can set it only for your your development builds and do release builds with minSDK < 21.
It also works without multidexing enabled.
Android Studio 1.3 (currently in Preview 3) is using a new build system which improved gradle build time (really, like 10-30x faster).
More information in the Live Session at Google I/O 2015
Multidexing uses more memory. As you get closer to your max heap size in Java you'll find Java spends more time doing GC than it does doing any real work, this can slow things down a lot.
I'd strongly recommend increasing the max heap size when using multidex. Add the following to the android closure in your build.gradle file to make the max heap size 4GB (Make it smaller if you wish):
dexOptions {
javaMaxHeapSize "4g"
}
Changing MinSdk to 21 made everything back to normal for me.Now everything compiles in like 6s
This is no longer needed with the latest Android Studio 3.0
Go in setting , search compiler , type "--offline" in Command line options and than compile.
it's been a while that I'm using Android Studio, and up until now I was using 1.0.1,
gradle was a bit slow, around 1.5 minute for assembleDebug (my project is really big!)
but today I updated my AS to 1.2 and now same process takes about 7 to 10 minutes, and sometimes even with no result!
is there any setting I have to change to make it faster ?
honestly taking 10 minute for every debug run is a nightmare !
Also most of the time, my cpu usage is arround 10 percent! (it is actually idle!)
cause before when gradle was working it was on 100% almost all the time
had the same problem.
What I did was to change the global gradle settings to offline work which can be done by going to Preferences => Gradle. This did make a difference.
Another method I have seen people use, but which I have not used yet is to create a gradle.properties in the gradle folder like so:
Just create a file named gradle.properties in the following directory:
/home/<username>/.gradle/ (Linux)
/Users/<username>/.gradle/ (Mac)
C:\Users\<username>\.gradle (Windows)
Add this line to the file:
org.gradle.daemon=true
Please check out this link for more options as well as a detailed explanation on speeding up gradle.
Hope this helps!.
I was testing my app with Google+ log in. So I added release signing to debug version. App compiling in ~ 26 seconds.
build.gradle Module: app file
signingConfigs {
debug {
storeFile file(project.property("MyApp.signing"))
storePassword project.property("MyApp.signing.password")
keyAlias project.property("MyApp.signing.alias")
keyPassword project.property("MyApp.signing.password")
}
}
When I remove that ~ 7.5 seconds.
Next I tested offline grade
File - Settings - Build, Execution... - Build Tools - Gradle - Offline work
Now my app compiling in ~ 4.5 seconds.
Of course I also added turn on
- Compile independent modules in parallel (may require larger heap size)
- Make project automatically (only works while not running / debugging)
File - Settings - Build, Execution... - Compiler
Complete answer for this issue is as below:
Upgrade android studio to version 1.3(stable) or above 1.4(beta at the time of writing this).
Upgrade gradle to 1.3.+(+ can be replaced with some positive number) change it in your build.gradle file.
change your gradle-wrapper.properties files and add distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip in last(you can remove any old entry).
Go to Preference -> Gradle and set it to work offline.
woila!!! I am able to compile and run the code in less then ~5 sec (I really mean it)
The reason could be multiDex,
turn multiDexEnabled to false in your build.gradle file (for debug only, keep it for release).
android {
...
defaultConfig {
...
multiDexEnabled false
...
}
}
In addition you should consider to use the lastest version (2.4 at the moment) by editing the gradle-wrapper.properties file and set gradle-2.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
What is MultiDex : https://developer.android.com/tools/building/multidex.html
From settings go to HTTP connection and disable any proxy and you will find speed you want