Java Android Studio变得非常缓慢并且不断“更新索引”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41022764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Studio got very slow and constantly "updating indices"
提问by daneejela
There are more similar question on the SO, but I haven't found my answer on any of them so I am opening new one.
SO上还有更多类似的问题,但我还没有找到任何答案,所以我正在打开新的问题。
I am using:
我在用:
Android Studio 2.2.3 (but was same with the 2.2.2) Gradle 2.14.1 JRE 1.8.0
Android Studio 2.2.3(但与 2.2.2 相同)Gradle 2.14.1 JRE 1.8.0
I am using it on the mac, OS X El Capitan (2.5 GHz, i5, 8GB RAM).
我在 Mac OS X El Capitan(2.5 GHz、i5、8GB RAM)上使用它。
It has been working great until few weeks ago, and now it is so painfully slow. Most of the time it is "indexing/updating indices".
直到几周前它一直运行良好,现在它非常缓慢。大多数时候它是“索引/更新索引”。
I am not that concerned about build time (it takes about 30-40sec, but I can live with that) as much as that constant indexing that makes coding almost impossible (overall responsiveness is pretty poor).
我不太关心构建时间(大约需要 30 到 40 秒,但我可以忍受)以及使编码几乎不可能的常量索引(整体响应能力非常差)。
Is there anything in my gradle files that could cause this?
我的 gradle 文件中是否有任何可能导致这种情况的内容?
I do have some dependencies, but the app itself is relatively simple.
我确实有一些依赖项,但应用程序本身相对简单。
build.gradle //app
build.gradle //应用程序
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
dataBinding {
enabled = true
}
defaultConfig {
applicationId "com.example.myproduct"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.+'
compile 'com.android.support:support-v4:23.2.+'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:design:23.2.+'
compile 'com.jakewharton.threetenabp:threetenabp:1.0.4'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'io.reactivex:rxjava:1.0.10'
compile 'io.reactivex:rxandroid:1.1.0'
compile 'com.google.android.gms:play-services-auth:8.3.0'
compile 'com.facebook.android:facebook-android-sdk:4.16.1'
}
build.gradle//project
build.gradle//项目
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:1.5.0-beta2'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
P.S. I have enabled - offline work, parallel and daemon. I have increased VM heap size. I have uploaded to latest Android Studio. I have replaces maven with jcenter(). Is there anything I am missing?
PS 我已启用 - 离线工作、并行和守护进程。我增加了 VM 堆大小。我已上传到最新的 Android Studio。我用 jcenter() 替换了 maven。有什么我想念的吗?
采纳答案by daneejela
For the others having the same problem:
对于其他有同样问题的人:
My android studio returned back to its original performance (which was ok). It is hard to me to say what made an improvement because I have done lots of changes at once, here are few I recall:
我的 android studio 恢复了原来的性能(没关系)。我很难说是什么改进了,因为我一次做了很多改变,以下是我记得的几个:
- replaced maven with -> jcenter()
- set flag in properties to use default gradle wrapper
- updated android studio to latest version (at the moment 2.2.3)
- enabled gradle daemon - Configuration On Demand
- invalidate cache and restart(few times)
- 用 -> jcenter() 替换 maven
- 在属性中设置标志以使用默认的 gradle 包装器
- 将 android studio 更新到最新版本(目前为 2.2.3)
- 启用 gradle 守护进程 - 按需配置
- 使缓存无效并重新启动(几次)
some of it I have tried before asking this question, but I think all came back to normal when I did last update to Android studio 2.2.3
其中一些我在问这个问题之前已经尝试过,但我认为当我最后一次更新到 Android studio 2.2.3 时,一切都恢复了正常
回答by Pratik Mohanrao Gondil
Try to store Sdk on other drive and also try to invalidate cache and restart. Hope this helps
尝试将 Sdk 存储在其他驱动器上,并尝试使缓存无效并重新启动。希望这可以帮助
回答by Abhishek Sengupta
It also happened to me,I just Sync 'app'and it was solved...
它也发生在我身上,我只是同步“应用程序”并解决了...
Or use this
或者用这个
Invalidate Caches / Restart under "File Menu"
在“文件菜单”下使缓存无效/重新启动
回答by Samm
I've had the same problem, but only when having multiple 'packages' under 'app/java/com.example.projectname'If you have multiple packages within your java folder, try this. It worked instantly for me.
我遇到了同样的问题,但只有在“app/java/com.example.projectname”下有多个“包”时, 如果你的 java 文件夹中有多个包,试试这个。它立即对我有用。
In Android Studio's 'Project Window,' right click on 'app/java/com.example.android.projectname'then click 'Show in Explorer.' Move all of your '.java' files out of their sub-folder and place them all in the 'app/java/com.example.android.projectname' folder.
在 Android Studio 的“项目窗口”中,右键单击“app/java/com.example.android.projectname”,然后单击“在资源管理器中显示”。将所有“.java”文件移出其子文件夹,并将它们全部放在“app/java/com.example.android.projectname”文件夹中。
Next, go back into Android Studio and open up all of your '.java' files. At the top of your code you should see package com.example.android.projectname.subfolder;
Because you've removed the 'packages' and relocated the '.java' files, you need to change every '.java' file's package to read package com.example.android.projectname;
接下来,返回 Android Studio 并打开所有“.java”文件。在您的代码顶部,您应该看到package com.example.android.projectname.subfolder;
因为您已经删除了“包”并重新定位了“.java”文件,因此您需要更改每个“.java”文件的包以读取package com.example.android.projectname;
You'll also need to go into the manifest and change 'activity android:name=...'
您还需要进入清单并更改“activity android:name=...”
Hopefully that works.
希望这有效。
回答by laalto
I got rid of constant "updating indices" issues by increasing the max heap size of Android Studio process.
我通过增加 Android Studio 进程的最大堆大小摆脱了不断的“更新索引”问题。
To do so, change Studio's JVM options(Help -> Edit Custom VM Options...) to include -Xmx2g
where 2g
is the amount of memory enough to keep Studio happy with your project complexity.
要做到这一点,改变Studio的JVM选项(帮助- >编辑自定义虚拟机选项...),包括-Xmx2g
其中2g
的内存足够让工作室快乐着你的项目的复杂量。
回答by MeLine
回答by Rafael Baptista
Also, you can try:
另外,您可以尝试:
Files -> Invalidate Caches / Restart...
文件 -> 使缓存无效/重新启动...
This worked for me.
这对我有用。
回答by Sanjay Kushwah
Just go to File -> Invalidate Caches / Restart
只需转到 File -> Invalidate Caches / Restart
Then on the dialog that opens select "Invalidate and Restart"
然后在打开的对话框中选择“无效并重新启动”
That's it.
就是这样。
回答by Dalvinder Singh
Invalidate Caches / Restart solved my problem.
使缓存无效/重新启动解决了我的问题。
Thank you.
谢谢你。