In continuation of our previous journal entry on How to Configure Android Studio? – Part 1, we will be looking into some details on how to configure Android Studio by maximizing the Heap memory, and play around with the idea.properties
file.
Configure Android Studio
Maximize Heap Memory
Android Studio by default has a maximum heap size of 1280MB.If your system has a lot of RAM and the project that you are working is large then you can improve the performance by increasing the maximum heap size. The maximum heap size for Android Studio can be updated in the VM options. However, if your system has memory-constrained, then you can decrease the maximum heap memory size.
Follow these simple steps to change the maximum heap size:
- Click Help > Edit Custom VM Options to open your
studio.vmoptions
file. - Add a line to the
studio.vmoptions
file to set maximum heap size using the syntax-XmxheapSize
. The size you choose should be based on the size of your project and the available RAM on your machine. As a baseline, if you have more than 4GB of RAM and a medium-sized project, you should set the maximum heap size to 2GB or more. The following line sets the maximum heap size to 2GB:-Xmx2g
- Save your changes to the
studio.vmoptions
file, and restart Android Studio for your changes to take effect. - To confirm your new maximum heap size, open the command line, and type the following command:
jps -lvm
You will see a list of the instrumented JVMs running on your machine, including the full package name for each and the arguments passed in. You should see two arguments beginning with -Xmx
for this JVM, one with the default value of 1280mb, and one with your new value.
Customize your IDE properties
Looking to customize Android Studio IDE, idea.properties
file can help you with this. The idea.properties
file allows you to specify the path to your installed plugins and the maximum file size supported by the IDE. The contents of this file gets merged with the default properties for the IDE so we can specify just the override properties.
To create a new idea.properties
file or to open your existing file, use the following steps:
- Click Help > Edit Custom Properties. If you have never edited the IDE properties before, Android Studio prompts you to create a new
idea.properties
file. Click Yes to create the file. - The
idea.properties
file opens in the editor window of Android Studio. Edit the file to add your own customized IDE properties.
For a complete list of properties, read about the idea.properties
file for IntelliJ IDEA.
Configure the IDE for low-memory machines
If you are using Android Studio on the machines which are less than the recommended specification, you can still go ahead and customize the IDE to improve the performance on your machine. Follow these simple steps to customize your IDE:
- Reduce the maximum heap size available to Android Studio: Reduce the maximum heap size for Android Studio to 512Mb. For more information on changing maximum heap size, see Maximum heap size.
- Update Gradle and the Android plugin for Gradle: Update to the latest versions of Gradle and the Android plugin for Gradle to ensure you are taking advantage of the latest improvements for performance. For more information about updating Gradle and the Android plugin for Gradle, see the Android plugin for Gradle Release Notes.
- Enable Power Save Mode: Enabling Power Save Mode turns off a number of memory- and battery-intensive background operations, including error highlighting and on-the-fly inspections, autopopup code completion, and automatic incremental background compilation. To turn on Power Save Mode, click File > Power Save Mode.
- Disable unnecessary lint checks: To change which lint checks Android Studio runs on your code, proceed as follows:
- Click File > Settings (on a Mac, Android Studio > Preferences) to open the Settings dialog.
- In the left pane, expand the Editor section and click Inspections.
- Click the checkboxes to select or deselect lint checks as appropriate for your project.
- Click Apply or OK to save your changes.
- Debug on a physical device: Debugging on an emulator uses more memory than debugging on a physical device, so you can improve overall performance for Android Studio by debugging on a physical device.
- Include only necessary Google Play services as dependencies: Including Google Play Services as dependencies in your project increases the amount of memory necessary. Only include necessary dependencies to improve memory usage and performance. For more information, see Add Google Play Services to Your Project.
- Turn on Offline Mode for Gradle: If you have limited bandwitch, turn on Offline Mode to prevent Gradle from attempting to download missing dependencies during your build. When Offline Mode is on, Gradle will issue a build failure if you are missing any dependencies, instead of attempting to download them. To turn on Offline Mode, proceed as follows:
- Click File > Settings (on a Mac, Android Studio > Preferences) to open the Settings dialog.
- In the left pane, expand Build, Execution, Deployment and then click Gradle.
- Under Global Gradle settings, check the Offline work checkbox.
- Click Apply or OK for your changes to take effect.
- Reduce the maximum heap size available for Gradle: Gradle’s default maximium heap size is 1,536 MB. Reduce the value by overriding the
org.gradle.jvmargs
property in thegradle.properties
file, as shown below:# Make sure to gradually decrease this value and note # changes in performance. Allocating too lttle memory may # also decrease performance. org.gradle.jvmargs = -Xmx1536m
- Do not enable parallel compilation: Android Studio can compile independent modules in parallel, but if you have a low-memory system you should not turn on this feature. To check this setting, proceed as follows:
- Click File > Settings (on a Mac, Android Studio > Preferences) to open the Settings dialog.
- In the left pane, expand Build, Execution, Deployment and then click Compiler.
- Ensure that the Compile independent modules in parallel option is unchecked.
- If you have made a change, click Apply or OK for your change to take effect.
Configure your project for Instant Run
Android Studio 2.3 and above has a feature called Instant Run which significantly reduces the time taken to update your app with code and resource changes. Once the app is deployed to a target device which is running Android 5.0 (API level 21) or higher, all you have to do is click on the button which says Apply Changes . This will push certain code and resource changes to your running app without building a new APK—and, in some cases, without even restarting the current activity.
Whenever, you want to push the changes and force your app to restart, the Run and Debug buttons are always there for you.
For more information about configuring your project for Instant Run, read Configure and optimize your project for Instant Run.