I've been using android studio for a few weeks now and noticed that it's been getting slower when restarted every time. The actual problem is that it seems to be stuck with the initial "Gradle Build Running" and started taking a few minutes to complete but now takes about 30+ minutes before it lets me actually use it. When this initial build is done it builds/cleans the project in about 4-7 seconds so it's only a recurring issue when I restart it.
One thing it could be is that the internet is awful (has a ping of about 500 ms), could that be related?
Hope someone can help!
Edit: Tried gradle offline mode, no luck there. After a further restart it even takes a long to stop the build too, it's been trying to stop the gradle build for about 10 minutes now...
Yes it can be related to your slow internet connection. Gradle re-downloads its dependencies at first run. It will be faster if you enable offline mode. To enable offline mode, Go to Preferences > Gradle and check "Offline work".
If you need to download any new dependency, disable offline work and sync project and disable it again.
Related
I am traveling in China for a few month and the network connectivity is weak due to the great fire wall. I have found enabling Offline work in Gradle setting super helpful. It reduced my compile time from a few minutes to a few seconds when I make a minor change in the build.gradle file.
However, I still need to manually turn it on and off if I introduce a new library to my project. So here comes my question:
Is there a way to default to Offline work and still download new library when needed?
you can use following build command from android studio terminal.
gradlew --offline assembleDebug
I am sorry if this question is repeat but gradle is taking much longer time then before. It is running since 57 min as you can see in screenshot and in previous attemp it took only one or half minute and usually it builds app in 2-3 minutes maximum. But from 2,3 days it behaving strangely. Running forever without any reason. Any help?
In Android Studio go to File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle
Check 'Offline work' under 'Global Gradle settings'
It will reduce 90% gradle build time.
While offline builds and reinstall may be a solution, we still need to get down to the exact reason.
Is it possible for you to run the gradle command with a stacktrace or a debug info? Even if the build hangs sporadically, you lose nothing by putting out a debug log. At best, there will some information which can be analyzed further.
Android Studio 2.2.2. Did a build of my project and after several minutes I noticed that it still hadn't completed and at the bottom of my screen Android Studio said I had a process running. When I clicked on it it said it was the Gradle Build so I clicked to stop it. The display changed to
Stopping - Gradle Build Running
But it never seems to stop. If I restart the build that whole sequence repeats itself so now I have TWO
Stopping - Gradle Build Running
dialogs. But they never actually stop, even after 15+ minutes! If I try to shut down Android Studio it puts up an "Are You Sure?" dialog warning me I have background tasks running.
What's the right way to shut these down cleanly and how do I prevent this from happening?
Run the following in a terminal:
./gradlew --stop
It kills all the gradle processes.
Sometime it happens, Due to many reasons like your system Ram or memory. Just try to close everything and restart it again. It happened with me somedays back. I did the same process and after this, it works fine in my system.
On Mac, it returned to normal only after restarting the machine.
Some of the cached temporary files seem to have caused the problem.
My Gradle build time is usually around 12 seconds, but after around 10 - 20 builds it starts to increase at once, exponentially: 30 seconds, 50 seconds, 2 minutes, 5 minutes, etc. up to out of memory.
Healthy build:
:app:compileDev21DebugJavaWithJavac 4.783s
:app:transformClassesWithRealmTransformerForDev21Debug 3.011s
:app:transformClassesWithDexForDev21Debug 2.133s
:app:compileRetrolambdaDev21Debug 1.325s
:app:packageDev21Debug 0.997s
:app:processDev21DebugResources 0.703s
After 10 - 20 of those, it starts increasing:
:app:transformClassesWithDexForDev21Debug 39.172s
:app:compileDev21DebugJavaWithJavac 34.221s
:app:packageDev21Debug 9.922s
:app:transformClassesWithRealmTransformerForDev21Debug 8.353s
:app:compileRetrolambdaDev21Debug 3.120s
:app:fabricGenerateResourcesDev21Debug 1.376s
As you can see, every task increases in time.
I use Android Studio 2.2.2, but I had the problem since the last 3 versions or so. Gradle 2.14.1. Probably it’s related to our project. I use Mac, my colleague on Windows has the same on the same project. If I stop AS, kill Java and start AS again, that solves it for a while.
I am not using the Jack compiler (yet).
To be clear: my build time is NOT generally slow: 13 seconds is fine. This is not a duplicate of all the "slow build time" questions. Only after 10 - 20 builds the build time increases exponentially with every build.
Update: Make Gradle build "offline" didn't help. Using "gradle-3.1-all.zip" (distributionUrl in grade-wrapper.properties) also did not help.
Anyone had this problem and knows a solution?
I experienced(and somehow still facing) the same issue. There are some fixes that you can try.
1- Make Gradle build Offline.
2- Install Gradle on machine and use local installation alongside Offline work checked in Android Studio instead of Using wrapper which connects to proxy and takes more time with building cache of Studio.
I followed this and this article and it helped me not substantially but enough to get me nearly 6,7 hours of continuous development on 8GB memory system then i have to Invalidate and Restart.
It is fixed since the day that I removed Fabric (CrashLytics) and replaced it with FireBase Crashes. Fabric was most probably causing it, but I'm not 100% sure.
When I install my application in debug mode, and open it for the first time it takes a lot of time (nearly 20-30 seconds). I guess it is due to multi dex enabled. It is happening after updating my Android Studio to version 2.0 and upgrding the android gradle plugin to version '2.0.0'. What is the reason for this behaviour? Is somebody else also facing similar issues?
I have been testing on Moto G3 with android marshmallow.
This happens most of the time because of the prolonged time needed to build the solution. The time needed to build a solution is mostly dependent on the number of libraries you are referencing, and the complexity of your code.
Remember that it is the first time you are building the app, so Android Studio has no record of the solution in its cache, hence it has to build everything from scratch.
Android Studio 2.0 also has the instant run feature, so it takes longer to run the first time, so that you can then debug instantly in the subsequent runs.
Hope this helps :)
I think is because of the new Instant Run feature. The first time takes a lot of time, but after that new changes are visible almost at the same time in your device.
In any case you can disable Instant Run in: File->Settings->Build,Execution,Deployment->Instant Run
There is an issue with multidex and API level 21+, relative to Instant Run. The documentation only mentions it without explanation though.
Instant Run
Settings/Preferences(Mac) → Build, Execution, Deployment → Instant Run and uncheck Instant Run
I was also facing the same problem and finally i fixed this.
note: 1) before generating an apk file unchecked all these option to resolve delay issue from your production build.
2) while you are developing or adding new features then keep it as default setting(instant run) to make development faster.
I hope this will resolve your issue.