Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 218231
Next
Alex Hales
  • 0
Alex HalesTeacher
Asked: July 14, 20222022-07-14T13:12:11+00:00 2022-07-14T13:12:11+00:00In: Android, android-studio, build.gradle, Gradle

Building and running app via Gradle and Android Studio is slower than via Eclipse

  • 0

[ad_1]

Speed Up Gradle Build In Android Studio 3.2.1

Ever feel like you are waiting for the builds to complete in Android Studio for minutes? Me too. And it’s a pretty annoying.
Fortunately, there are a few ways that you can use to improve this. Android uses Gradle for building. The latest version is 4.6 has a huge performance boost over previous versions (see Release notes for details).

Step 1: Update Gradle version
An easier way to accomplish this is to go to: Open Module Settings (your project) > Project Structure

enter image description here

UPDATE

Change to Gradle version: 4.6
and
Change to Android Plugin Version: 3.2.1

enter image description here

Download Gradle Release distributive from https://services.gradle.org/distributions/gradle-4.6-all.zip
And copy it to the Gradle folder:

enter image description here

Last step is to add your discribution in Settings > Gradle

enter image description here

Don’t forget to click Apply to save changes.

Step 2: Enable Offline mode, Gradle daemon and parallel build for the project
Offline mode tells Gradle to ignore update-to-date checks. Gradle asks for dependencies everytime and having this option makes it just uses what is already on the machine for dependencies.
Go to Gradle from android studio Setting and click in Offline work box.

enter image description here

  1. Go to Compiler from android studio Setting and add “— offline” in command-line box and click Compile independent modules in parallel.

enter image description here

The next step is to enable the Gradle daemon and parallel build for your project. Parallel builds will cause your projects with multiple modules (multi-project builds in Gradle) to be built in parallel, which should make large or modular projects build faster.

enter image description here

These settings could enabled by modifiing a file named gradle.properties in Gradle scripts directory(i.e., ~/.gradle/gradle.properties).Some of these options (e.g. Complie modules in parallel) are available from Android Studio and also enabled there by default, but putting them in the gradle.properties file will enabled them when building from the terminal and also making sure that your colleagues will use the same settings. But if you’re working on a team, sometimes you can’t commit this stuff.

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit org.gradle.parallel=true
# When set to true the Gradle daemon is used to run the build. For local developer builds this is our favorite property.
# The developer environment is optimized for speed and feedback so we nearly always run Gradle jobs with the daemon.
 org.gradle.daemon=true

Using the daemon will make your builds startup faster as it won’t have to start up the entire Gradle application every time. The Gradle Daemon is not enabled by default, but it’s recommend always enabling it for developers’ machines (but leaving it disabled for continuous integration servers). FAQ about this mode could be found here https://docs.gradle.org/current/userguide/gradle_daemon.html.
The parallel builds setting could be unsafe for some projects. The requirement is that all your modules must be decoupled or your build could fail (see http://gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects for details).

Step 3: Enable incremental dexign and tweak memory settings
You can speed up your builds by turning on incremental dexing. In your module’s build file:

enter image description here

Add this option to your android block:

dexOptions {
    incremental true
}

In that dexOptions block you can also specify the heap size for the dex process, for example:

dexOptions {
    incremental true
    javaMaxHeapSize "12g"
}

Where “12g” is 12GB of memory. Additional information about this could be found here google.github.io/android-gradle-dsl/current/
You can also configure Gradle parameters in the settings file, e.g. increase the max heap size in case you have a large project:

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

See all list of parameters here: https://docs.gradle.org/current/userguide/userguide_single.html#sec:gradle_configuration_properties for details.

Step 4: Disable Antivirus
Consider to exclude project and cache files from antivirus scanning. This is obviously a trade off with security. But if you switch between branches a lot, then antivirus will rescan files before allowing gradle process to use it, which slows build time (in particular Android Studio sync project with gradle files and indexing tasks). Measure build time and process CPU with and without antivirus enabled to see if it is related.
I hope this helps. Leave a comment if you have any question or some other tips for improving the build performance.

helpful link

[ad_2]

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 2 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 4 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 3 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.