Android Studio 2.3.1 - editing build.gradle file causes IDE to freeze for 20 seconds (or more)
Asked Answered
D

0

9

The past few days, I've experienced some unusual problems in Android Studio 2.3.1; the IDE freezes whenever I edit the build.gradle (module) file.

  • My Project-level gradle settings are Use default gradle wrapper (recommended)

  • gradle-wrapper.properties is as follows:

    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
    
  • My local Gradle version (defined by GRADLE_USER_HOME) is Gradle 3.5

  • Android Studio does not have a proxy server setting enabled as described in this post Android Studio gradle takes too long to build

  • my gradle.properties file is as follows

    org.gradle.daemon=true
    org.gradle.parallel=true
    
  • my build.gradle file is as follows

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.3"
        defaultConfig {
            applicationId "app.com.eventfull.waterjam"
            minSdkVersion 16
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    
        dataBinding.enabled=true
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',         {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
    
        compile 'com.android.support:appcompat-v7:25.3.1'
    
        compile 'com.google.firebase:firebase-auth:10.0.1'
        compile 'com.firebaseui:firebase-ui-database:1.0.0'
        compile 'com.google.firebase:firebase-database:10.0.1'
    
        compile 'com.android.support:design:25.3.1'
        compile 'com.android.support:support-v4:25.3.1'
        testCompile 'junit:junit:4.12'
    }
    
    apply plugin: 'com.google.gms.google-services'
    

I tried toggling the offline work option in Global Gradle Settings (Settings > Preferences > Build, Execution, Deployment > Gradle), but this has no effect; IDE still hangs up when editing the build.gradle file. Thoughts?


EDITS:

Here are my custom VM OPTIONS.

-Xms512m
-Xmx2g
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=240m
-XX:+UseCompressedOops

A complete un-install & re-install seems to have fixed this issue.
I dislike resorting to such measures - I'd rather know the why - but it was nonetheless effective.


UPDATES on 6.25.2017

Despite uninstalling & reinstalling Android Studio, Gradle, rebooting my system, cleaning various system caches a few times...Android Studio still freezes for ~30s to 60secs upon editing a gradle file. I've taken to editing the gradle files in an external text editor & Sync Project with Gradle Files. It helps, but Android Studio still seems to freeze intermittently for ~20secs or longer after doing this. Toggling the "offline mode" in gradle settings does nothing.

I'm using...

  • Android Studio 2.3.3 (for production apps)

  • Android Studio 3.0 canary 4 (for experimenting & ideas).

  • 'com.android.tools.build:gradle:2.3.3' is the gradle android build tools in Android 2.3.3

  • Macbook Pro (Mid 2015), Core-i7, 16GB RAM, Sierra 10.12.5

Let me know if someone has any suggestions...


UPDATE 4/02/2018

The problem has disappeared since Google added a special repository for Android Studio users, that is, the embedded Maven repository for Android Studio 3+.

Android Studio 2.3.3 and lower doesn't have this.

INSTRUCTIONS

  1. Open Android Studio's Preferences - ⌘, (mac) or CTRL ALT S (win)
  2. search for 'embedded'
  3. click Enable embedded Maven repository

embedded maven repository

Discourage answered 8/5, 2017 at 14:21 Comment(12)
For me the freeze lasts about a minute and then it unfreezes. Edit a little more and it freezes again for about a minute. Was that your experience?Halsy
yup. successive edits (either back-to-back or not) still cause Android Studio to freeze for ~ a minute. It's not a one-time thing. Moreover, all my edits are rather minor; I'm not appending/editing huge amts of info in the gradle files. See my edits above for things I've tried since I posted about this problem. I plan to ask a guru about this at AnDevCon later in July.Discourage
You can have a try : when you editing your build.gradle, turn off the computer network.Soandso
I also have the problem. Mac sierra system. Do you solve it?Strother
When I edit this file android studio will send request to search.maven.org then frozen. So I add 127.0.0.1 search.maven.org to hosts then restart android studio it will not frozen again, but sometimes we need visit search.maven.org too.Handmade
Same here. Any update?Bloodhound
@Bloodhound Same here too :(Leguminous
I've got the exact same issue on Ubuntu 17.10, Android Studio 3.1.1 and I tried all the suggested solutions, including yours, but I still have this annoying problem.Onagraceous
I'm working on a Mac & Windows, and ever since the 'embedded maven repository' option in Android Studio, the freezing/slowness hasn't been a problem. I'll try it out on Ubuntu in a few days & report back.Discourage
That'd be very helpful. Thank you.Onagraceous
I've got the same issue on Windows 10, suggested solution didn't work. :(Hannahhannan
Good news. Last night I got notified of Android Studio 3.1.2 update and after update, the problem was solved. After a day of using it, I don't see the issue anymore. :)Onagraceous

© 2022 - 2024 — McMap. All rights reserved.