Android Studio 在 i7 处理器上使用 100% CPU 进行项目重建 [英] Android Studio using 100% CPU on an i7 processor for project Rebuild

查看:51
本文介绍了Android Studio 在 i7 处理器上使用 100% CPU 进行项目重建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Windows 7 机器有一个四核 i7 处理器.当我重建我的项目时,平均需要 25 秒.当我启动应用程序时,平均需要 36 秒(在应用程序上传到设备之前).

My Windows 7 machine has a quad core i7 processor. When I Rebuild my project, it takes on average 25 seconds. And when I launch the app, it takes on average 36 seconds (before the app is uploaded to the device).

我的项目的/src 文件夹中有 588 个文件,其中包括我所有的 java 和 xml 代码.我的/libs 文件夹中有两个 .so 库,每个 5MB 和 7 个 jar.

I have 588 files in my project's /src folder, which includes all of my java and xml code. I've got two .so libs each 5MB and 7 jars in my /libs folder.

请看我附上的截图.如您所见,我的 CPU 一直处于 100% 的最大值.我的 iTunes 音乐暂停,我在 Windows 任务栏的右下角看到一个性能不佳"的弹出窗口.那是多么糟糕.

See my attached screenshot. As you can see my CPU is maxed out at 100% the entire time. My iTunes music pauses, and I get a "Poor Performance" pop-up in the lower right hand corner of my windows taskbar. That's how bad it is.

我使用的是 Android Studio 1.2.1.1

I'm using Android Studio 1.2.1.1

大部分时间都花在 preDex 和 dex 操作上.

Most of the time is spent during the preDex and dex operations.

这是我迄今为止尝试过的(单独的,我还没有一起尝试过):

Here's what I've tried so far (separately, I haven't tried them all together):

  1. 添加 gradle.properties -> "org.gradle.daemon=true"
  2. 省电
  3. 模式使缓存无效/
  4. 重新启动全局 Gradle 设置 -> 离线
  5. 工作编译器 -> 自动制作项目

还没有任何效果.我无法想象这是一个普遍的问题,对吗?我是不是太不适应了,因为这真的比 Eclipse 慢得多?

Nothing has worked yet. I can't imagine that this is a common problem, am I right? Am I being too imaptient because this really is that much slower than Eclipse?

我想我的问题是:

  1. 这可能是因为我的 jars 或 so 文件的大小吗?
  2. 我接手了一个在 XML 文件中有许多嵌套视图的项目.这会导致问题吗?

我真的很想得到稻草,所以如果有人有任何信息,特别是为什么 dex 操作占用这么多 CPU,那就太棒了.

I'm really reaching for straws so if anyone has any information, esepecially why the dex operation is taking up so much CPU, that would be awesome.

我想不用说,如果我编辑 XML 文件,进行重建,然后启动应用程序,就会发生这种情况.如果没有什么可以清理和重建...当我只是做一个 Make Project 时……平均构建时间是 3 秒.

I guess it goes without saying that this is happening if I edit an XML file, do a rebuild, and then launch the app. If there's nothing to clean and rebuild... when I just do a Make Project... the average build time is 3 seconds.

推荐答案

以下是我能够做出的三项改进:

Here are the three improvements I was able to make:

我在每次构建项目时都对 JAR 进行了预Dexing,所以我找到了这个解决方案:

I was preDexing my JARs every time I built the project, so I found this solution:

dexOptions {
    preDexLibraries = false
}

我使用了整个 Google Play 服务库:

I was using the entire Google Play Services library:

compile('com.google.android.gms:play-services:+') {
    exclude module: 'support-v4'
}

当我只需要 Google Cloud Messenger 时:

When all I needed was Google Cloud Messenger:

compile('com.google.android.gms:play-services-gcm:+') {
    exclude module: 'support-v4'
}

在 Eclipse 中,我总是会进行重建,然后使用播放按钮启动应用程序.在 Android Studio 中,现在我只是在执行 Clean,然后使用播放按钮启动应用程序.此外,Android Studio 中的运行按钮并非每次都在 Clean 之后立即工作.这导致了似乎是延误,因为什么都没有发生.所以现在我让 Gradle 控制台保持打开状态,以确保运行按钮正常工作,如果没有,我就第二次点击它.

In Eclipse, I would always do a Rebuild and then launch app with the play button. In Android Studio, now I am just doing a Clean and then launch app with the play button. Also the Run button in Android Studio does NOT work every time right after the Clean. This was causing what seemed to be delays because nothing was happening. So now I leave the Gradle Console open to make sure that the run button is working, and when it doesn't I just hit it a second time.

我曾经拥有的:

Rebuild: 26 seconds
Launch:  36 seconds
Install: 15 seconds

现在:

Clean:    8 seconds
Launch:  22 seconds
Install: 15 seconds

这是一个重大改进!希望这对其他人有帮助.

which is a major improvement! Hopefully this helps someone else.

这篇关于Android Studio 在 i7 处理器上使用 100% CPU 进行项目重建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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