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

倖福魔咒の 提交于 2020-01-01 04:59:05

问题


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

来源:https://stackoverflow.com/questions/43850112/android-studio-2-3-1-editing-build-gradle-file-causes-ide-to-freeze-for-20-sec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!