Solution of Slow Android Studio
Speed Up Your Gradle Build Process
The Gradle build is the most crucial part of developing an android application. Sometimes it takes much more time than it should then it becomes a painful process. These are the few best tips to reduce the Gradle Build time.
Step 1: Enable Offline Work
Many times we don’t need to go with the online build process of the Gradle we can do it offline. Why not do it in offline mode? It will save our time and escape unnecessary checks for dependencies. We can always enable the online build process when we require this. We can turn it off for now. Go to View >> Tool Windows >> Gradle and then click on the icon Toggle Offline Mode. Again clicking on the icon will turn off Offline Mode.
Step 2: Enable Gradle Daemon and Parallel Build
Enabling Parallel Build will reduce Gradle build timings cause it will build modules parallelly. Enabling the Gradle Daemon will also help to speed up the build process. Go to Gradle Scripts >> gradle.properties and add these two lines of code.
org.gradle.parallel=true
org.gradle.daemon=true
Step 3: Enable Incremental Dexing
Turning on Incremental Dexing will also speed up the build process of the application. Go to build.gradle(module:app) and add this block.
dexOptions {
incremental true
}
Note: From Android Gradle Plugin 8.0 onward, there is no need to use dexOptions as the AndroidGradle plugin optimizes dexing automatically. Therefore using it has no effect.
Step 4: Disable Antivirus
In the Gradle build process, the android studio needs to access multiple files repeatedly. An antivirus by default doesn’t give direct access to the android studio to those files it will check the file and then gives access. The procedure of checking files first and then giving access to android studio slows down the process of Gradle build. So if you are confident enough that on your pc you haven’t downloaded any malware files from unauthorized websites or locations then you can turn the antivirus off. It will also help in speeding up the process of the Gradle Build. I think there’s no need to tell you how can you turn off the antivirus on your pc you would be knowing that.
Step 5: Disable the Proxy Server of Android Studio
By default proxy server is off in the android studio, but in some cases, your proxy server may be on. Disabling it will help to run a smoother build process. For disable it, Go to File >> Settings >> Appearance and Behaviour >> System Settings >> HTTP Proxy and Select No Proxy.
Faster Android Studio
We have done some factful settings for speeding up the Gradle Build process. Now let’s do some settings which can help us to make our Android Studio Faster.
Step 1: Disable Useless Plugins
There may be many plugins in Android Studio that you are not using it. Disabling it will free up some space and reduce complex processes. To do so, Open Preferences >> Plugins and Disable the plugins you are not using.
Step 2: Use SSD
A solid-state drive is a great product in which you can invest. It will not only fast up your android studio it will also fast your PC 2 to 3 times. SSD has really faster than Hard disk drives.
Step 3: Adjust the memory setting
Go to Appearance & Behavior >> System Settings >> Memory Settings. Tweak these settings according to your preference. Increasing a little bit of heap size can help. Too much heap allocation is also not a good thing.
Step 4: Ignore Thumbs.db
Go to File>> Settings>> Editor>> File Types>> and in Field of Ignore files and Folders add Thumbs.db. It also can speed up your Android Studio.
Step 5: Free Up Space and Cache
For clearing the Gradle Cache:
On Windows:
%USERPROFILE%\.gradle\caches
On Mac:
/ UNIX: ~/.gradle/caches/
For Clearing the cache of the whole android studio:
File >> Invalidate Cache and Restart.
Step 6: Delete Unused and Unwanted Projects
In our android studio projects folder, many junk apps can also exist which we have created somehow but we have not done any work on those apps. The apps that exist are not needed for you then you can delete these unwanted apps it will free up space and remove a little unwanted load from android studio. For doing so, check the following path:
C:\Users\%USER%\AndroidStudioProjects
and delete those junk apps.
Step 7: Try to use a single project at a time
We have talked before on the topic that how heavy software is the android studio and how heavy the process is the gradle build of the application. If we are not having a high configuration PC then we should not work on many apps at the same time and also should not do the gradle build for two applications at a time. If we are doing so then it may cause our pc can be hanged. We should work on a single project at a time.
Step 8: Try to run the application on a physical device instead of an emulator
Android Studio provides the emulators for running our application for development purposes. Emulators provided by them will also be putting an extra load and make android studio bulky which can be a cause for the hanging of android studio. We should run our application on a physical device instead of that emulator it will lead to a smooth development process. You can refer to the article How to Run the Android App on a Real Device?
Step 9: Update android studio
Google is also trying to make smoother and faster IDE for Development. He is trying to update its algorithms and make the android studio as fast as it can be. So updating to the latest version is a useful step for you if you are running on the older versions. So you should keep your Android Studio Updated.