Android Studio 2020.3.1 - Run very slow, always re-build - android-studio

I'm using latest AS, version 2020.3.1. Every time I change the code and run it again, AS run very slow, always re-build project (take about 10 minutes). My project is also quite large, using many libraries.
How to make AS run faster?
Please help me. Thanks.

It all depends on your system configurations. It does not matter which android studio version you are using. Try upgrading your machine or prevent using inbuilt AVD of android studio rather use your own mobile for testing. This could make Your AS run a bit faster.
Here is the link to know how it is done
https://developer.android.com/studio/run/device

Related

Android Studio 3.0 VERY VERY VERY slow on run

I have a very big problem using Android Studio.
Every time I make a code changing, I have to check if all has gone well launching my app; but as soon as I click the "Run app" or the "Apply changes", it's the end: it starts the Gradle build process, which take even 30 minutes to complete, and furthermore Android Studio take the full control of my computer, not allowing to do nothing anymore (like open the browser, open notepad++, and so on...).
Can anyone help me?
Thanks
If you use Eclipse you won't have this problem anymore. but if you want to stick with android studio and gradle you can run your emulator and gradle once and whenever you want to compile your code run it on the already built gradle. this means that do not close the emulator and run your program on it again and again. this way you will not have to spent alot of time on loading the emulator and gradle
Android Studio is not a very light software.It uses a lot of your system RAM and CPU power.So if you are using an old system then it is obvious that android studio will run slow.If possible then upgrade your system.
And one more thing it's better to use actual device rather than Virtual Emulator for our application working test.

Why starting project (Run) in Android Studio triggers APK rebuild even if no changes were made?

I mean, we are in 2016 and this is not a Borland compiler.
The point of Run operation is to start the package on device. If no changes are made since last run, just run the APK, but this Gradle thing cannot manage it and runs in whole project compile each time (2-3 minutes). Components are not recompiled, but the whole package construction takes that time.
I wonder how the whole world of Android developers tolerates this (and other quirks of gradle). I searched in Google and found no solution. Any hints to make it better?
You can't do anything about it; Android Studio just has to rebuild every time. But in the newer versions of Android Studio, you can use Instant Run. This runs/debugs your applications by using a simpler Gradle build in a very fast matter.
Also, take a look at this , which previously helped me to reduce my Gradle build from 45 to 7 seconds.

Does Intellij Idea have instant run?

It is some time now since I first heard about instant run in Android Studio 2.0. Is it ever coming to IntelliJ Idea? I have 2016.1.2 and still nothing. I can imagine it can speed up development. I am still tearing my hair every time I press run...
Couldn't find any valuable information about this online. All what google finds is just "IntelliJ and Android Studio is made on the same code base" I guess it is more complicated than that.
Seems like it's going to be released in Intellij 2016.2
Quoting 2016.2 EAP Release Notes:
Android
Android Studio 2.0 features.
Edit:
Looks like it was eventually released and made production ready in Intellij 2017.1
Quoting the What's New page:
Instant run
This release adds many stability and reliability improvements to
Instant Run. If you have previously disabled Instant Run, the Android
team encourages you to re-enable it.
No. From IntelliJ IDEA 2016.2 Notes:
Android
The update includes the Android Studio 2.0 features: faster Emulator, experiment GPU Debugger, faster full builds, and code generation and testing for App Indexing. Note, Instant Run is not fully-merged yet.

Android Studio avoid "make" while running

When you press the run button in Android Studio the project is buit again, and as you know this always take long, if e.g. I select Build -> Make Project and then "Run" the make process runs again, I don't understand why? I would expect that it only installs the APK that is already generated. Is there a way I can achieve this, is my expectation funded or am I thinking wrong?
I've used the approach described here to speedup my build.
Building and running app via Gradle and Android Studio is slower than via Eclipse
At the same time i've disabled "make project automatically" because sometime it produces old code.

Does Android studio need internet connection to build project

I am using Android studio version 0.4.2 and gradle version 1.9. I have successfully installed Studio and have created multiple projects. Today when I launched Studio without internet connection,
I got this error message:
"Gradle project sync failed. Basic functionality (e.g. editing,
debugging) will not work properly" and the Event Log window shows
"Failed to refresh Gradle project < Project Name >. Connection timed
out: connect. If you are behind an HTTP proxy, please configure the
proxy settings either in IDE or Gradle."
I need to know if internet connection is mandatory for building projects using gradle.
I think gradle checks for latest version on internet and throws Connection time out error. If so, is there any workaround to disable that.
Currently Android Studio's Gradle implementation requires a fast stable network connection. For whatever reason, the developers have decided to force this requirement on users at this time. There is a setting that you should be able to use to utilize a local gradle installation, but it doesn't hold. The developers know about both the network requirement and the broken switch, but are currently prioritizing other functionality. They may remove that requirement in the 1.0 or post 1.0 time frame.
[see: https://plus.google.com/u/0/115692564989237473252/posts/LGSbniYqj3Q ]
Gradle's offline mode, isn't. It should be properly named cached mode. All that switch does is tell gradle to not try to go online and instead utilize cached copies of the various networked resources. Unfortunately that assumes that you have had (and will have again) a network connection, preferably a fast stable one. Using Android Studio (last version tested 0.5.9) with a slow/unstable network results in watching Android Studio process Gradle ( and Maven ) processes usually for 2-5 minutes, sometimes for 10 minutes or more. Also at seemingly random times when coding the IDE will lock up and the cause usually involves one or more Gradle processes that have spun up.
As a comparison, using IntelliJ IDEA 13.1 Community edition (the IDE that Android Studio is based on) I compared a default "Hello Android" IDE generated program using the Android Gradle wizard (substantially similar to the only one in Android Studio) and the Ant based Android wizard. The results were as expected. The gradle based project experienced the same painful lock up and lag that projects in Android Studio exhibited. The ant based Android project was near instantaneous. No appreciable delay once the project was created and opened. Coding caused no random lockups. Testing was done on a Windows 8.1 update1 Pro machine with a dual Athlon x2 processor, 6GB RAM, and a 6Mb/0.75Mb DSL connection. I believe that last part is most likely the issue.
Unfortunately until Android Studio removes the network requirement I feel it will be unusable to a large number of developers. That's a shame because otherwise it looks to be a marked improvement over the existing Eclipse based development environment.
For me, I had to check and then uncheck the box in
Preferences->Gradle->Offline work.
Then I got back online.
You can download the gradle distribution locally and build the project again.
To do this, edit your gradle-wrapper.properties under gradle-> wrapper in your Android project.
Edit the
distributionUrl=https://services.gradle.org/distributions/gradle-2.2.1-all.zip
to
distributionUrl=file:///home/foo/downloads/gradle-2.2.1-all.zip
So just download the file from here as mentioned in your gradle-wrapper.properties.
There's an offline mode preference in Preferences > Compiler > Gradle. If you already have your dependencies downloaded, this will generally work for you.
In Android studio version 1.5.1 I could solve this error by following steps :
1) Go to file -> Settings -> HTTP Proxy -> & select Auto detect proxy settings.
2) After that you may get Dialog to accept or reject certificate
3) Select Accept.
That's it.

Resources