我最近从Eclipse升级到Android Studio,但我并不喜欢这种体验。我比较的是Windows 7 64位终极版,16GB内存,英特尔i7 4770运行NVidia Geforce 780,如果重要的话,我运行的是最新的JDK和最新的Android Studio。

Android Studio在构建项目时非常缓慢,我可以接受,但它也非常消耗资源,有时会使PC速度变慢。

每当我在AS中构建或运行任何东西时,我的PC似乎变得极其缓慢。如果我点击“Gradle build running”旋转器,它也会导致屏幕闪烁,偶尔会让我的第二个显示器空白,我觉得这很奇怪。内存的使用也飙升到3GB,我发现什么都不做就过度了(这是在几次构建后空闲的时候)。

此外,AS底部的面板一直在跳来跳去,这是一种糟糕的用户体验(从Android移动到消息到版本控制或其他任何临时的基础上,这取决于正在发生的事情,这是非常非常恼人的)。

我想知道的基本上是:

1)如何让Android Studio运行得更好?我可能做错了什么,或者错过了一些我不知道的更新,我相信其他人也注意到了这些行为,并找到了一些解决方案。

2)我如何“钉”底部面板,使他们不跳,而是让我,用户,导航到他们当我希望而不是自动切换他们?

非常感谢,如果这不是这些问题的正确位置,我再次道歉。

编辑1 更多评论:

我使用的是今天最新的稳定版本。这个版本是Android Studio 1.2.2 build # AI-141.1980579,于2015年6月3日发布 这种行为发生在使用Java 7或Java 8时。它似乎与Java版本无关。 我没有使用演示模式。只是普通的观点。 对构建配置进行更改(感谢@Blackbelt和他的回答)似乎对构建有所帮助,但迟缓和一般用户体验等其他问题仍然存在。


当前回答

增加内存对我有帮助:

单击“帮助” 编辑自定义虚拟机选项

Android Studio 2.1.2编辑自定义虚拟机选项

变化值

像下图:

-Xms512m    
-Xmx2560m   
-XX:MaxPermSize=700m    
-XX:ReservedCodeCacheSize=480m    
-XX:+UseCompressedOops

重启Android Studio

其他回答

这个答案涉及到在你已经把Xmx和Xms内存设置弄清楚之后,Windows 10的Gradle构建速度变慢的问题。

视窗防护

就Windows Defender而言,仅仅通过“文件”或“文件夹”将文件夹/文件添加到Windows Defender排除列表是不够的。

你必须添加属于Android Studio / Gradle / Java(嵌入式JDK或Oracle JDK)的目录作为“进程”排除到Windows Defender:

看一下大卫·罗森的答案 在Gradle构建过程中…监视Windows任务管理器的进程 在Windows Defender中,为包含文件/可执行文件的目录添加“进程”排除,你看到在与Android Studio / Gradle相关的构建过程中使用CPU

这显然会带来安全隐患。

以下描述了有关在Windows Defender中使用“进程”排除(而不是添加简单的“文件”或“文件夹”排除)的更多细节:

A file name with full path causes the particular binary file to be excluded, i.e. any files it touches, regardless of where the file is located, will not be scanned by Windows Defender. A file name without any path causes any binary file with this file name to be excluded regardless of its location. A path followed by a "*" (e.g. c:\my\private\tools*) causes any binaries under this path to be excluded. Any files touched by these processes will be excluded. This is different from a path exclusion, where files touched by any process under the excluded path is excluded.

这里的关键字是....将这些排除作为“进程”类型的排除考虑到“二进制接触的文件”,而不是手动查找并排除由Android Studio / Gradle生成的每个文件/文件夹。

Windows文件索引

Windows文件索引似乎也会降低Gradle构建的速度。关闭Gradle / Android Studio使用的目录的Windows文件索引。

以下是我排除的“Windows文件索引”和“Windows防御程序”:

 C:\Program Files\Android\*
 C:\Users\<yourUserAcct>\.android\*
 C:\Users\<yourUserAcct>\.AndroidStudio3.0\*
 C:\Users\<yourUserAcct>\.gradle\*
 C:<pathToYourAndroidStudioProjectFolder>

单击帮助>编辑自定义属性并添加这一行:

sun.java2d.noddraw=false

... 为我成功地解决了速度问题(Windows 10 64位)。就我而言,这是绝对的巫毒(我没有做过任何研究为什么它应该工作),在这个属性上面有一个警告,它可能会导致闪烁和无法在某些显卡上重新绘制,但你还是去吧。(受LairdPleng的评论启发,进一步信息)

我的Android Studio不仅在一般使用时很慢,在构建时也很慢。

以下是我所做的:

卸载Android Studio(不要删除,卸载它,并检查删除SDK)。然后删除位于C:\Users\\文件夹中的Android文件夹,即:. Android, AndroidStudioX。X 通过SDK管理器卸载SDK,删除所有内容(如果有剩余的SDK文件夹,删除它们) 下载并重新安装Android Studio的最新版本(在撰写本文时为v2.1.2);只安装你需要的SDK/模拟器;

现在快了。


在此之前我的故事:

My laptop sports an Intel Core i7-3612QM and 8gig of ram. When I builded, all the 4 cores/8 threads were on 100% usage. My entire system froze until the ~10 minute wass done. Gradle took me like ~10 unproductive minutes of slow down. This is very annoying. I am using Android Studio since 1.4. There were also tremendous slow down when I copy paste code to and from, selecting menus, right-click context menus, editing manifest, editing gradle files, opening layout files, rendering in the UI Editor, etc. Its was very unusable most of the time.

Due to frustration, I did the above steps. Its fast now. Very usable just as before. I build for only ~20 seconds compare to ~10minutes before that. Also, Android Studio eats about 6gig with emulator and browser with lots of tab open, unlike before its hovering on 98% RAM usage. Not just that, I even saved 45 gigs of space for whatever reason. I only use couple of SDKs and Emulators when I checked the Android SDK folder, it occupies 45gig of space! I think the IDE is having a hard time accessing/IO on my SDK folder.

如果你已经尝试了其他给出的解决方案,仍然遇到同样的问题,可能是时候完全删除Android IDE/ sdk并重新开始了(可能需要一段时间来重新设置,但这是值得的。考虑到我已经被这种懒惰折磨了好几个月了,还让我失去了工作效率)。

我真的认为这可能是由于从那时起所做的累积补丁造成的。或者是我那碎片整理得很差的驱动器上的45g SDK文件夹。我不知道,也许我错了。

谢谢你!HTH

1最常见的慢的原因是使用模拟器

, especially more than one. USB debugging with the external mobile device can be used.

2每个月让缓存失效一次

一个简单的事情,没有人提到的是文件>无效缓存。

建议:

必须说:如果你有任何机会,花一些钱买更好的PC(cpu), 这是最重要的…

调整:

Some people say, that OS (Operating System) might cause much slowness. For example, XP or LINUX (or etc) was mentioned to perform 70% faster (don't know why..). Disable VCS by File > Settings > Plugins and disable the following things : CVS Integration; Git Integration; GitHub; Google Cloud ... things; Subversion Integration; hg4idea; Editor is a resource eating too (especially on Large Monitors) and slow. Make it much much faster: click Help > Edit custom VM options and add these lines : -Dsun.java2d.d3d=false -Dsun.java2d.opengl=true save it and Restart Android Studio. If Android Studio has a proxy server setting and can't reach the server then it takes a long time to build and waiting for a timeout. Removing it helps much. File > Settings > Appearance & Behavior > System settings > HTTP Proxy. Another Useful quote (from article): Modules are expensive… On my current project I had to build some libraries from scratch and had to fork some that almost fitted my needs but not quite! If that modules are not constantly modified, it’s important to have this into consideration: the time needed to compile them from scratch, or even to check if the previous individual module build is up-to-date, can be up to almost 4x greater than to simply load that dependency as a binary .jar/.aar. Hint: run the gradle build -profile for an HTML report showing where the time goes regarding the build process. Note: keep that “unnecessary” modules in your version control system for the eventuallity of a quickfix/improvement in that dependency. In your Gradle build script, use only specific Google Service, like: compile 'com.google.android.gms:play-services-maps:...' Instead of full Google Library: compile 'com.google.android.gms:play-services:...' (Compile time goes from 2 minutes to around 25 seconds). Gradle configures every project before executing tasks, regardless of whether the project is actually needed for the particular build. In global gradle.properties adding this will help much: org.gradle.configureondemand=true Surprisingly, some people say , they solved problem by reducing: 1) heapsizes to -Xmx256m (instead of higher values); 2) Emulator Ram-size (from Edit AVD > Advanced Settings);

每天的建议:

不要同时运行多个项目。 使用一次后不要关闭模拟器(每次都使用相同的模拟器运行应用程序;如果你测试大型应用,最好使用真正的手机而不是模拟器)。 每次在模拟器中运行你的应用程序后都清理你的项目-点击构建>清洁项目(或重建),你可以使用键盘快捷键。