I recently started to use Android Studio and while I like it a lot, there is one thing that annoys me a lot:
Gradle - it's nice tool and all, but damn it's such a resource hog, also it's just so painfully slow. No matter if I use my 5 years old laptop or my gaming PC, when it's running, other applications go to a full stop (well almost)...
Is there really a reason for a build tool to be so demanding??? I understand compilation can be a slow process but from my experience javac always seemed to be blazingly fast, so it cannot be source of a problem (also building Android apps with ADT was many times faster too)...
So is there something wrong with my configuration? Can I make Gradle run faster?
Create a gradle.properties file either in your project root directory or your ~/.gradle directory with the following line:
org.gradle.daemon=true
From the Gradle manual:
The Daemon is a long-lived process, so not only are we able to avoid the cost of JVM startup for every build, but we are able to cache information about project structure, files, tasks, and more in memory
Also, you can go to File > Power Save Mode if you want to turn off continuous building in Android Studio.
Related
I'm doing a project in my office in Android Studio, it was working fine there.
But when I open the same project in my personal laptop in Android Studio it's taking a lot of time to build gradle.
Please, does anyone have a solution?
I have also face same problem, actually your personal laptop not compatible to run android studio, in the documentation of android they mentioned that 4 GB RAM is sufficient but my personal experience said that RAM should be 8 GB, its also depend on your operating system in MAC os android studios running smoothly then in Linux its also give good performance but in Windows its creating a problem, i think you need to upgrade your RAM.
Add this line to the file:
org.gradle.daemon=true
From now on Gradle will use a daemon to build, whether you are using Gradle from command line or building in Android Studio. You could also place the gradle.properties file to the root directory of your project and commit it to your SCM system. But you would have to do this, for every project (if you want to use the daemon in every project).
Note: If you don’t build anything with Gradle for some time (currently 3 hours), it will stop the daemon, so that you will experience a long start-up time at the next build.
Note: Performance improvements are one of the great tasks in the Gradle roadmap for 2014 (and reaching into 2015). So I hope, we’ll see the general performance increasing within these years.
Note: This does only affect console builds. Android Studio always uses a Gradle daemon (and depending on your settings some other optimizations).
Found the reason!! If Android Studio has a proxy server setting and can't reach the server then it takes a long time to build, probably its trying to reach the proxy server and waiting for a timeout. When I removed the proxy server setting its working fine.
On Windows File > Settings > Appearance & Behavior > System settings > HTTP Proxy
There are two options available to run unit tests in Android Studio:
Right click on the file with your unit tests (which is Gradle-Aware Make).
testAppDebugUnitTest task is from the list of available Gradle tasks.
The first one actually consists of two tasks:
- :app:assembleAppDebug and :app:assembleAppDebugUnitTest
The second one is just testAppDebugUnitTest itself.
The first one is a recommended way by Google Tools Team, but it takes as twice as much time compared to the second one.
There is no visible difference how to run unit tests except the duration. You might think your code won't be compiled without assembleAppDebug, but this is not true - changes you introduce to either class under a test or a test itself compiled and executed as expected.
So, what's the difference and why is it the recommended way if it takes as twice as much time to prepare everything before actual unit tests run?
I don't have much work experience with Gradle, But off course it is always better to use Google Team recommended tools instead of others.
it takes as twice as much time compared to the second one.
If you use the new Gradle build system with Android (or Android Studio) you might have realized, that even the simplest Gradle call (e.g. gradle project or grade tasks) is pretty slow.
To avoid this time taking processes in android studio you need to Speed up Gradle build time. It will definitely makes a difference
Here is few steps to speed up the Gradle build time >>
In compiler settings (Android Studio -> Preferences -> Project
settings[your project] -> Compiler (Gradle-based Android Projects)),
type --offline in the "Command-line options" box.
from ~4 minutes to ~20 seconds.
In another way, You can decrease this startup time of Gradle (on my computer down to two seconds), if you tell Gradle to use a daemon to build. 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
From now on Gradle will use a daemon to build, whether you are using Gradle from command line or building in Android Studio. You could also place the gradle.properties file to the root directory of your project and commit it to your SCM system. But you would have to do this, for every project (if you want to use the daemon in every project).
Note: If you don’t build anything with Gradle for some time (currently 3 hours), it will stop the daemon, so that you will experience a long start-up time at the next build.
For more details please refer this Building and running app via Gradle and Android Studio is slower than via Eclipse
Performance improvements are one of the great tasks in the Gradle roadmap for 2015 (and reaching into 2016). So hope, we’ll see the general performance increasing within these years.
n g+ there is a discussion with the developers about it.
Hope this information will helps you.
The reason your option 1 takes twice as time is because most of the time is wasted on spinning up Gradle and checking if tasks are up to date. So running an no-op assemble will make it twice as long. You can verify this by running it yourself and check the time wasted by doing an no-op.
With gradle, running with "--offline --daemon --parallel" can get you somewhere (offline is helpful when you have slow internet access to Maven/JCenter repos, daemon is helpful to keep files cached, and parallel is particularly helpful if you have MultiDex on and have split your app into small modules)
If you are just asking about "What's the fastest way to run unit tests in Android?" without considering the change you would need, I would recommend switching to Buck (https://buckbuild.com/), which is 10x faster than Gradle on dex-xing and spinning up tests but has limited AS support.
I have Eclipse with Android set up. The problem is when ever I run a project from eclipse to test it, the application never launches and the emulator never shows up. Even though the launching progress bar shows 100%.
Make sure the AVD's memory is set to 512, if it's higher the emulator will get a memory heap error and fail. Also try to enable verbose output when building, this can be set from within the properties.
Do you have a device attached? Eclipse switches to mobile devices automatically
I had once or twice had such problem. Restart of eclipse worked for me. And Yes also check the Run configuration, make sure your project is linked with emulator.
Go to Window->Preferences->Android->Build and select verbose build output
Now run your project and check Android console. In my case there were thousands of
"Dx processing %classname%..." which took several minutes to finish.
Just to make it clear: dx.bat is an ADT utility program, it converts multiple Java class-files to single "classes.dex" file(Dalvik executable file).
I had a project which used several libraries with lot of classes and the compilation was very fast(several seconds), but the launching was quite slow(2-4 minutes).
Then I found out that the most time consuming part was converting class files from my project and from all third-party libraries to *.dex file(the resulting size of dex-file was about 4 Mb). As far as I know, it's impossible to attach libraries to android project without dexing their class-files, so you have to be patient during launching your project.
UPD: It's possible to strip all unused code from your application.
Please check this link: Always running proguard before Android dex'ing in Eclipse
My application has a bunch of external .jars, android libraries, and a plenty of code. Bulding the project (I am using eclipse) is terrible. It takes few minutes to do clean/build. And after each rebuild I have to restart eclipse, otherwise it just hangs on second build. I am afraid that soon I'll not be able to build it at all!! Giving more memory to Eclipse has no effect.
On the other side, there is absolutely no problems building small android applications.
I am on Windows Vista, eclipse-java-galileo-SR2, Android SDK Tools (revision8), Core 2 Duo 2GHz.
Q: It would be great to hear from other developers having pretty big projects, if you have same issues, and how you solve them?
An other issue that I see, is that compilation hangs some times since it can't communicate with emulator. If I close emulator, it may complete.
I added more physical memory. Running eclipse with such parameters:
eclipse.exe -vmargs -Xmx700M
Now I have more than enought of memory. It is ~1Gb of extra free RAM available.
Project rebuild takes ~1m 10s, that is about twice faster than it used to be, but on the other side this is still not ideal.
An other positive effect - I don't have to restart eclipse after each rebuild any more.
The following situation will surely be familiar to any Android developer using Eclipse and ADT.
I'm tired of this endless cycle of switching Build Automatically on and off, running Clean, building and running. I'm constantly doing all of these operations when I'm fine tuning UI (i.e., editing XML files and needing to see the results live), and any time I save, an Eclipse window telling me I have these pending operations shows up. When that happens, I turn off Build Automatically. I do my alterations and then run. Sometimes Eclipse decides the changes in the XML file weren't enough, and it won't reinstall the app in the emulator or device, so I force a build and install.
All of this is just wasted time. I've already done an AppleScript to build & run my app into all the emulators and devices I have connected at once, described in this SO question, but my workflow could be much improved if I found a way to save and build silently and fast.
Does anyone have any tips or alternatives?
IntelliJIdea Community Edition now supports Android
Have you tried the bundle for Textmate? It's pretty cool. It's basic but its got all the features you need. Building, Deployment and integration with AVD and Logcat.
I use this for all my Android Dev now as I found Eclipse painfully slow.