我最近从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和他的回答)似乎对构建有所帮助,但迟缓和一般用户体验等其他问题仍然存在。


当前回答

我通过升级gradle很快解决了这个问题(Android Studio似乎使用旧版本)。

1)下载最新版本(https://gradle.org/gradle-download/),然后在某处解压。 2) Android Studio的更新路径:File > Settings > Build, Ex../Gradle

其他回答

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

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

我尝试在相同的硬件上测试Android Studio 3.1.4的速度:Macbook Pro 2011, RAM 4Gb, SSD 240GB三星,Core i5 2.4Ghz。我在这台机器上安装了3个不同的操作系统:Windows 10, MacOS high Sierra 10.13, Ubuntu 18.04。MacOS/Ubuntu上的平均构建时间(运行命令:gradlew clean build, gradlew clean assemblerrelease)比Windows快30%左右。

On my another working machine: Core i5 3.0 Ghz 7400, RAM 16Gb, SSD 250Gb. Build time takes 4.34min on Windows 10 machine. The same project on a little bit slower processor, but with the same RAM and SSD and it is running Ubuntu 16.04 build time takes two times faster!! Well I was shocked with results, but still I choose Windows as development machine, because it's much more comfortable for me to use comfortable and usable keyboard and sotfware than on Unix like systems. And even if I had to choose between MacOS and Ubuntu - mac is really much easier to setup everything, and Ubuntu is too complex to use for usual people. Choise is up to you.

我遵循了这个帖子,它对我很有效。

编辑:

以下技巧已经在上面的帖子中提到。

在它。属性,这样写:

org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.configureondemand=true

在构建中。gradle,把这个(注意这将禁用lint检查):

tasks.whenTaskAdded { task ->
    if (task.name.equals("lint")) {
        task.enabled = false
    }
}

总结一下

1)在AndroidStudio的设置> compile启用名为compile独立模块并行的复选框。

2)在帮助>编辑自定义虚拟机选项我有:

-Xms1024m 
-Xmx4096m # <------ increase this to most of your RAM 
-XX:MaxPermSize=1024m 
-XX:ReservedCodeCacheSize=440m 
-XX:+UseCompressedOops 
-XX:-HeapDumpOnOutOfMemoryError 
-Dfile.encoding=UTF-8

附注:有些人说注意,而不是虚拟机选项,它是更好的组合可以通过组合成一行命令在gradle覆盖这些行。属性,像这样:

org.gradle。jvmargs=-Xms1024m -Xmx4096m…

3)我有一个老的双核4GB内存,运行ubuntu。Qs命令行选项我只有——offline(它指定构建应该在不访问网络资源的情况下运行)。我还启用了其余的复选框,现在它运行正常:

自动制作项目 使用进程内构建按需配置 检查AndroidStudio的设置,在compile下的复选框“并行编译独立模块”已启用。

在Vmoptions下,我有

-Xmx2048m -XX:MaxPermSize=1024

我有一个老的双核4GB内存,运行ubuntu。Qs命令行选项我只有——offline,它指定构建应该在不访问网络资源的情况下运行。我还启用了其余的复选框:

自动制作项目 使用过程中构建 按需配置 运行正常

Edit

可以通过工作室提供额外的选项。vmoptions位于(只需将X.X替换为version):

Windows:转到%USERPROFILE%\. androidstudix . x \studio.exe。Vmoptions(或studio64.exe.vmoptions) 麦克:~ /图书馆/ / .AndroidStudioX.X / studio.vmoptions偏好 Linux: ~ / .AndroidStudioX.X /工作室。Vmoptions(和/或studio64.vmoptions)

增加-Xmx的值应该会有很大帮助。如

-Xms1024m
-Xmx4096m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=256m
-XX:+UseCompressedOops

将分配4G作为最大堆,初始值为1G

编辑:

在windows上,默认值存储在C:\Program Files\Android\Android Studio\bin\*.vmoptions中。IDE允许您通过Help->编辑自定义虚拟机选项来调整这些值(感谢@Code-Read指出这一点)。

编辑2:

Android studio 3.5更容易更改这些值。请访问:

Preferences > Appearance & Behavior > System Settings > Memory Settings