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

查看:510
本文介绍了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. 这可能是由于我的jar或文件大小所致吗?
  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,因此我找到了以下解决方案:

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中,我将始终执行Rebuild,然后使用播放按钮启动应用程序.现在,在Android Studio中,我只是执行清理",然后使用播放"按钮启动应用程序.而且,清理后,Android Studio中的运行"按钮并非每次都起作用.由于什么都没有发生,这导致了似乎是延迟的情况.因此,现在我将Gradle Console保持打开状态,以确保运行按钮可以正常工作;如果没有运行,我将再次点击它.

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天全站免登陆