Android编译慢(使用Eclipse) [英] Android compilation is slow (using Eclipse)

查看:20
本文介绍了Android编译慢(使用Eclipse)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我更改任何 .java 文件并构建时,编译需要 16 秒.我不明白为什么要这么慢!?

When I change any .java file and build, the compilation takes 16 seconds. I don't understand why it should be so slow!?

我为 Andoroid 启用了详细输出.

I enabled verbose output for Andoroid.

Window > Preferences > Android > Build output > Verbose.

结果输出(Console > Android)是:

The result output (Console > Android) is:

[19:46:10] Refreshing resource folders.
[19:46:10] Starting incremental Pre Compiler: Checking resource changes.
[19:46:10] Nothing to pre compile!
[19:46:10] Starting incremental Package build: Checking resource changes.
[19:46:10] ignored resource ...in.classes.dex
[19:46:10] processing ...A.class
[19:46:10] processing ...B.class
    ...
[19:46:21] processing com/google/inject/util/Providers.class...
[19:46:21] processing com/google/inject/util/Types.class...
[19:46:24] Using default debug key to sign package
[19:46:24] Packaging ...in
esources.ap_
[19:46:24] Packaging classes.dex
    ...
[19:46:25] Packaging ...annotations.jar
[19:46:25] Build Success!
[19:46:25] Refreshing resource folders.
[19:46:25] Starting incremental Pre Compiler: Checking resource changes.
[19:46:26] Nothing to pre compile!

.class 文件的处理"耗时 14 秒.它处理"了所有文件,甚至来自所有链接的 .jar 文件.我认为这里出了点问题,因为只更改了一个 .java 文件.

The "processing" of .class files took 14 seconds. And it "processed" all files, even from all .jar files linked. I think some thing wrong goes here, as only one .java file was changed.

如何提高编译速度?

推荐答案

我认为这里有一个误解.如您所说,仅重新编译修改后的类(由 Eclipse 在几毫秒内重新编译);然而,在那之后,ADT 插件获取每个已编译的类,并通过 dx 工具将其转换为 Dalvik 的字节码格式.此过程的输出是单个文件 classes.dex,其中包含应用程序中的所有类,包括来自引用库的类.最后一个翻译"步骤需要更长的时间,因为它的优化确实很差:ADT 插件不缓存任何东西,它只是在每次构建时重新翻译每个类(而且速度非常慢).对于大中型项目,这真的很令人沮丧……我希望 Google 在未来的 ADT/SDK 版本中改进这一点.

I think there's a misunderstanding here. As you say, only the modified classes are recompiled (by Eclipse in a matter of milliseconds); after that, however, the ADT plugin takes every compiled class and translates it into Dalvik's bytecode format via the dx tool. The output of this process is a single file, classes.dex, which contains all the classes in your application, including the ones coming from referenced libraries. This last "translation" step is the one that takes longer because it's really poorly optimized: the ADT plugin doesn't cache anything, it just retranslates every class at every build (and it's painfully slow). For medium to big projects this gets really frustrating... I hope Google will improve that in a future ADT/SDK release.

这篇关于Android编译慢(使用Eclipse)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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