为什么 Android Studio 在编辑 xml 文件或更改设计时变慢? [英] Why Android Studio is slowing down when editing xml file or changing the design?

查看:54
本文介绍了为什么 Android Studio 在编辑 xml 文件或更改设计时变慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台配备 Intel i7 和 8gb 内存和 2gb 显卡的 Hp envy 笔记本,当我使用 xml 或设计应用程序时,有时 android studio 仍然卡住.我的笔记本电脑或安卓工作室有问题吗?

解决方案

可能是因为 AS 的堆内存不够.您可能想尝试本博客中提到的第一种技术:

加快 Gradle 构建时间

开发人员仍然对放弃 Eclipse 犹豫不决的原因之一是 Gradle.尽管它确实是一个不错的构建系统并且使用它有很多好处,但即使是最简单的 Gradle 调用也非常缓慢和耗时.因此,我们的工作流程中包含了很多不可避免的等待,有时我们甚至会在 AS 完成其繁琐的构建过程后忘记需要测试什么.我们采取了一些措施来提高 Gradle 的速度.

首先,转到 Settings/Compiler 并检查所有内容,除了第二个选项 Make project automatically.对于 VM 选项,我们使用以下配置:

-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

接下来,将以下行添加到项目目录中的 gradle.properties:

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

通过硬件虚拟化加速模拟器

虽然 Android 模拟器不是 Android Studio 的一部分,但值得一提的是,如果您使用的是支持硬件虚拟化的较新的 Intel CPU 之一,则模拟器的速度会非常快.查看这篇文章,了解如何在您的机器上进行设置.

I have a Hp envy notebook with Intel i7 and 8gb ram and 2gb graphics, still sometimes android studio stucks when I am working with xml or design the app. Is there any problem with my laptop or android studio?

解决方案

It's probably because there's not enough heap memory for AS. You might want to try the first technique mentioned in this blog: Eliminate Lags & Stutters in Android Studio.

Content of link

Increasing Android Studio's Memory Heap:

Android Studio, like other Java applications, is known for hogging an insane amount of memory while running. Unless enough memory is allocated to the IDE at launch, disk swapping will start kicking in and if you're not using a SSD, God bless you.

Open the file [AS Installation Folder]\bin\studio64.exe.vmoptions or studio.exe.vmoptions, depending on which version you're using.

In it you're likely to find these two lines at the top:

-Xms128m
-Xmx750m

Increase the two values to something reasonable, e.g. -Xms256 and -Xmx1024. You can boost the second value to 2048 if you like; my coworker whose computer has 8G of RAM doesn't find any issue with -Xmx2048 either.

After you're done, restart AS and if you've checked Show memory indicator in Settings/Appearance, you'll see something like this at the bottom-right corner:

Speeding up Gradle build time

One of the reasons developers are still hesistant to ditch Eclipse is because of Gradle. Although it's indeed a nice build system and there are many benefits to using it, even the simplest Gradle calls are pretty slow and time-consuming. As a consequence, our workflow includes a lot of unavoidable waiting, and sometimes we even forget what needs to be tested after AS finishes its laborious building processes. There are a few things we do to boost Gradle's speed.

First, go to Settings/Compiler and check everything, except for the 2nd option Make project automatically. For VM Options, we use these configurations:

-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

Next, add the following lines to gradle.properties in your project directory:

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

Accelerating the emulator with hardware virtualization

Although the Android emulator is not part of Android Studio, it's well worth mentioning that if you're using one of the newer Intel CPUs which support hardware virtualization, the emulator can be amazingly fast. Check out this article for how to set it up on your machine.

这篇关于为什么 Android Studio 在编辑 xml 文件或更改设计时变慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆