执行aapt时突然出错
我知道周围有很多这样的主题,但似乎没有一个对我的情况有帮助,也没有准确地描述它。最好的类似的是在正确的路径下找不到aapt。
我的问题是,我可以使用 Eclipse 进行整个晚上的编程、编译和使用我的设备,然后突然我在当前项目中遇到“执行 aapt 时出错”的情况,当然 R.java 不再(正确)生成了。然后我重新启动 Eclipse,一切都会消失。然而,我平均每天看到一次。
我最近切换到 amd64 并安装了最新的 Android-2.3 SDK 和匹配工具。我知道现在有一个 platform-tools 文件夹,其中有一个 aapt 版本,应该独立工作 SDK 版本。起初,我按照 SDK 网站上的说明将此目录添加到我的 PATH 中。我还尝试不将其添加到我的路径中并创建链接platforms/android-9/tools,以便每个SDK版本都可以使用它自己的旧副本。不用说,platform-tools/aapt 就在那里并且拥有正确的权限,我已经能够随时在命令行上执行它。
当我编写错误的 xml 文件或排序并适当地收到错误时,我会看到一条额外的行,上面写着“aapt:/lib32/libz.so.1:没有可用的版本信息”。我正在运行最新的 Gentoo Linux 系统。我已经安装了所有东西来支持 amd64 上的 x86,但为了确定起见,我重新出现了 emul-linux-x86-baselibs 和 zlib。问题仍然存在。我确实看到一些 页面 对某些 zlib bug 感到恐惧,但我不确定这是否相关。我意识到我不在参考 Ubuntu 平台上,但差别肯定不会那么大吧?
这很可能是 aapt 或工具本身的错误。为什么会突然停止工作?我还发现 R.java 中的 ids 不正确,即简单的 findViewById() 代码会因为混合 ids 一次而给出 ClassCastExceptions,然后在没有任何更改的情况下完美工作,而只是一个“干净的项目”,之后一个失败的公寓。
最后,我在 aapt 上运行了一些命令,这些命令似乎没有添加任何额外的信息:
#ldd aapt
./aapt: /lib32/libz.so.1: no version information available (required by ./aapt)
linux-gate.so.1 => (0xffffe000)
librt.so.1 => /lib32/librt.so.1 (0x4f864000)
libpthread.so.0 => /lib32/libpthread.so.0 (0x4f849000)
libz.so.1 => /lib32/libz.so.1 (0xf7707000)
libstdc++.so.6 => /usr/lib/gcc/x86_64-pc-linux-gnu/4.4.4/32/libstdc++.so.6 (0x415e9000)
libm.so.6 => /lib32/libm.so.6 (0x4f876000)
libgcc_s.so.1 => /lib32/libgcc_s.so.1 (0x4fac6000)
libc.so.6 => /lib32/libc.so.6 (0x4f5ed000)
/lib/ld-linux.so.2 (0x4f5ca000)
#file aapt
aapt: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
有人能告诉我我的配置有什么问题吗?也许它闻起来像一个错误(否则让我们(再次)报告它)?
更新2010-01-06:
我获得了更多知识。当我最近尝试导出签名的 apk 时,我遇到了另一条关于我以前从未见过的 aapt 的错误消息(来自 Eclipse 错误视图的完整详细信息)。这里还要注意,我可以重新启动 Eclipse,并且可以毫无问题地再次导出 apk,至少在一段时间内是这样。
我开始认为这与我的系统内存不足有关。消息“onvoldoende geheugen beschikbaar”的意思是“可用内存不足”。
当我转储 HPROF 文件时,我还在 DDMS 中看到内存不足的错误。
这是错误日志(缩短):
!ENTRY com.android.ide.eclipse.adt 4 0 2011-01-05 23:11:16.097
!MESSAGE Export Wizard Error
!STACK 1
org.eclipse.core.runtime.CoreException: Failed to export application
at com.android.ide.eclipse.adt.internal.project.ExportHelper.exportReleaseApk(Unknown Source)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.doExport(Unknown Source)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.access$0(Unknown Source)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard$1.run(Unknown Source)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: com.android.ide.eclipse.adt.internal.build.AaptExecException: Error executing aapt. Please check aapt is present at /opt/android-sdk/android-sdk-linux_x86-1.6_r1/platform-tools/aapt
at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeAapt(Unknown Source)
at com.android.ide.eclipse.adt.internal.build.BuildHelper.packageResources(Unknown Source)
... 5 more
Caused by: java.io.IOException: Cannot run program "/opt/android-sdk/android-sdk-linux_x86-1.6_r1/platform-tools/aapt": java.io.IOException: error=12, Onvoldoende geheugen beschikbaar
...
Caused by: java.io.IOException: java.io.IOException: error=12, Onvoldoende geheugen beschikbaar
...
!SUBENTRY 1 com.android.ide.eclipse.adt 4 0 2011-01-05 23:11:16.098
!MESSAGE Failed to export application
!STACK 0
com.android.ide.eclipse.adt.internal.build.AaptExecException: Error executing aapt. Please check aapt is present at /opt/android-sdk/android-sdk-linux_x86-1.6_r1/platform-tools/aapt
at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeAapt(Unknown Source)
at com.android.ide.eclipse.adt.internal.build.BuildHelper.packageResources(Unknown Source)
at com.android.ide.eclipse.adt.internal.project.ExportHelper.exportReleaseApk(Unknown Source)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.doExport(Unknown Source)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.access$0(Unknown Source)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard$1.run(Unknown Source)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: java.io.IOException: Cannot run program "/opt/android-sdk/android-sdk-linux_x86-1.6_r1/platform-tools/aapt": java.io.IOException: error=12, Onvoldoende geheugen beschikbaar
...
Caused by: java.io.IOException: java.io.IOException: error=12, Onvoldoende geheugen beschikbaar
I know there are a lot of these topics around but none seem to help in my case, nor describe it exactly. The best similar one is aapt not found under the right path.
My problem is that I can be using Eclipse for a whole evening programming, compiling and using my device, and then suddenly I get "error executing aapt" for my current project and ofcourse R.java isn't (properly) generated anymore. I then restart Eclipse and everything goes away. I'm seeing this once a day on average however.
I've recently switched to amd64 and installed the latest Android-2.3 SDK and matching tools. I know that there is now a platform-tools folder that has an aapt version that should work SDK version independently. At first I had added this directory to my PATH, as instructed on the SDK website. I've also tried not adding it to my path and making a link platforms/android-9/tools so that every SDK version might use it's own old copy. Needless to say, platform-tools/aapt is there and has the right permissions, and I have been able to execute it on the command-line at any time.
When I do write a faulty xml file or sorts, and appropriately get an error, I see an extra line that says "aapt: /lib32/libz.so.1: no version information available". I'm running a recent Gentoo linux system. I have everything installed to support x86 on amd64, but have re-emerged emul-linux-x86-baselibs and zlib just to be sure. The problem persists. I do see some pages that spell horror over some zlib bugs, but I'm not sure if that's related. I realize I'm not on the reference Ubuntu platform, but surely the difference cannot be that great?
It might very well be a bug in aapt or the tools itself. Why would it suddenly stop working? I also experience that the ids in R.java were incorrect, namely that simple findViewById() code would give ClassCastExceptions because of mixed ids the one time, and then work perfectly without any changes bu only a "clean project", in the aftermath of a failing aapt.
Finally, I've run a few commands on aapt, that don't seem to add any extra information:
#ldd aapt
./aapt: /lib32/libz.so.1: no version information available (required by ./aapt)
linux-gate.so.1 => (0xffffe000)
librt.so.1 => /lib32/librt.so.1 (0x4f864000)
libpthread.so.0 => /lib32/libpthread.so.0 (0x4f849000)
libz.so.1 => /lib32/libz.so.1 (0xf7707000)
libstdc++.so.6 => /usr/lib/gcc/x86_64-pc-linux-gnu/4.4.4/32/libstdc++.so.6 (0x415e9000)
libm.so.6 => /lib32/libm.so.6 (0x4f876000)
libgcc_s.so.1 => /lib32/libgcc_s.so.1 (0x4fac6000)
libc.so.6 => /lib32/libc.so.6 (0x4f5ed000)
/lib/ld-linux.so.2 (0x4f5ca000)
#file aapt
aapt: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
Can anybody tell anything wrong with my configuration? Does it smell like a bug perhaps (otherwise let's report it (again))?
Update 2010-01-06:
I've gained some more knowledge. When I recently was trying to export a signed apk, I ran into another error message (full details from the Eclipse error view) regarding aapt I hadn't seen before. Note here too, that I can just restart Eclipse and can export apks again without problems, at least for a little while.
I'm starting to think it is related to lack of memory on my system. The message "onvoldoende geheugen beschikbaar" means "insufficient memory available".
I have also been seeing insufficient memory errors in DDMS when I'm dumping HPROF files.
Here is the error log (shortened):
!ENTRY com.android.ide.eclipse.adt 4 0 2011-01-05 23:11:16.097
!MESSAGE Export Wizard Error
!STACK 1
org.eclipse.core.runtime.CoreException: Failed to export application
at com.android.ide.eclipse.adt.internal.project.ExportHelper.exportReleaseApk(Unknown Source)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.doExport(Unknown Source)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.access$0(Unknown Source)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard$1.run(Unknown Source)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: com.android.ide.eclipse.adt.internal.build.AaptExecException: Error executing aapt. Please check aapt is present at /opt/android-sdk/android-sdk-linux_x86-1.6_r1/platform-tools/aapt
at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeAapt(Unknown Source)
at com.android.ide.eclipse.adt.internal.build.BuildHelper.packageResources(Unknown Source)
... 5 more
Caused by: java.io.IOException: Cannot run program "/opt/android-sdk/android-sdk-linux_x86-1.6_r1/platform-tools/aapt": java.io.IOException: error=12, Onvoldoende geheugen beschikbaar
...
Caused by: java.io.IOException: java.io.IOException: error=12, Onvoldoende geheugen beschikbaar
...
!SUBENTRY 1 com.android.ide.eclipse.adt 4 0 2011-01-05 23:11:16.098
!MESSAGE Failed to export application
!STACK 0
com.android.ide.eclipse.adt.internal.build.AaptExecException: Error executing aapt. Please check aapt is present at /opt/android-sdk/android-sdk-linux_x86-1.6_r1/platform-tools/aapt
at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeAapt(Unknown Source)
at com.android.ide.eclipse.adt.internal.build.BuildHelper.packageResources(Unknown Source)
at com.android.ide.eclipse.adt.internal.project.ExportHelper.exportReleaseApk(Unknown Source)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.doExport(Unknown Source)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.access$0(Unknown Source)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard$1.run(Unknown Source)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: java.io.IOException: Cannot run program "/opt/android-sdk/android-sdk-linux_x86-1.6_r1/platform-tools/aapt": java.io.IOException: error=12, Onvoldoende geheugen beschikbaar
...
Caused by: java.io.IOException: java.io.IOException: error=12, Onvoldoende geheugen beschikbaar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
该错误确实存在于 emul-linux 的 32 位 libz.so.1.2.3 中!
我刚刚自己构建了一个 32 位 libz 版本,它可以工作 - aapt 不会抛出上述错误。如果您使用 gentoo - emul-linux-x86-baselibs 的所有 libz 版本都有此问题(当前为 20100915-r1 和 20110129),
在 emul-linux-baselibs 的更新版本发布之前,您需要执行以下步骤:
问题是,虽然您自己编译的 64 位版本在 ELF 标头中具有以下字段:
当前 emul- 提供的 32 位版本linux-x86-baselibs 缺少 VERDEF 字段,它只包含
您可以检查自己的 32 位 lib 的自定义构建是否具有 VERDEF 字段 - 我的有,我想知道为什么它在 emul-linux 发行版中丢失..
问候,
cmuelle8
ps:有时计算机程序打印的错误信息是正确的..
the bug is indeed in emul-linux's 32bit libz.so.1.2.3 !!
i just built a 32bit libz version myself and it works - aapt does not throw the above error. if you are using gentoo - all libz versions of emul-linux-x86-baselibs have this problem (currently 20100915-r1 and 20110129)
here are the steps you need until an updated version of emul-linux-baselibs is out:
The Problem is, that while the 64bit version you compile yourself has the following fields in the ELF header:
the 32bit version provided by current emul-linux-x86-baselibs lacks the VERDEF field, it contains only
you can check yourself whether your custom build of 32bit lib has the VERDEF field - mine does and I wonder why it is missing in the emul-linux distribution..
regards,
cmuelle8
ps: sometimes the error messages printed by computer programs is right..
实际问题似乎是 aapt 进程请求了不合理的内存量。我的系统配备 SSD HD 并且(因此)没有交换(但 4GB RAM),在已经很大的 Eclipse 进程旁边没有内存。
解决方案是设置:
阅读下面的文章,但我的理解是linux内核有一个缺陷,并且在预测新进程将需要多少内存方面不完善。该标志允许系统启动任何进程,具体取决于它需要多少内存。请注意,实际上 aapt 永远不会使用这么多内存。似乎 eclipse 进程的大小(在我的例子中为 2GB)是估计值,并且将其添加到正在使用的任何 RAM(2GB eclipse + 0.5GB 其他)中,这超出了我的 4GB RAM。 Aapt 只会使用 2GB 的一小部分,但计算失败。
允许这种过度使用的缺点显然是,当内存不足时,内核没有干净的解决方案,并且只会杀死进程。
另一个解决方案是使用交换,在我的例子中是交换文件,因为我没有预见到交换分区,然后最好使用非常低的交换性。你的 Linux 手册应该告诉你如何操作,但总而言之(这只是为了快速测试,你应该设置 /etc/fstab):
将 swappiness 设置得如此之低,使得交换实际上从未被使用过。这也是该解决方案最大的缺点。你的硬盘上会有一个 2GB 的文件,除了满足内核的计算之外,你永远不会使用它(可能是罕见的极低内存,不确定 0 交换是如何工作的?)。据说在 SSD 上使用交换并不是一个好主意,因为多次写入会缩短 SSD 的使用寿命。
以下文章引导我找到了解决方案。
如何解决“java.lang.Error”问题io.IOException:错误=12,无法分配内存”调用 Runtime#exec()?
http://webcache.googleusercontent.com/search?q=cache:2NSdg-wIVsAJ:wiki.apache.org/cassandra/Operations+java.io.IOException+insufficient+system+resources+no+swap&cd =4&hl=nl&ct=clnk&gl=be&lr=lang_en|lang_nl
请注意,这里的问题不是 aapt,也不是 Android 开发工具。我可以在任何地方看到这个问题。然而,我确实认为,由于 eclipse 工具包的巨大(并且不断增加)的大小,再加上一些实现细节,例如 fork()? 的使用,这个问题很可能在这里出现,也适用于其他问题拥有 SSD 的人。
The actual problem seems to be that the aapt process is asking for an unreasonable amount of memory. Memory that my system with an SSD HD and (thus) no swap (but 4GB of RAM) does not have, next to the already big eclipse process.
The solution is to set:
Read the articles below, but my understanding is that the linux kernel has a flaw, and is imperfect in predicting how much memory a new process will need. This flag allows the system to start any process, regarding how much memory it is asking. Note that in practice aapt will never use this much memory. It seems the size of the eclipse process (in my case for example 2GB) is the estimate and this is added to whatever RAM is in use (2GB eclipse + 0.5GB other), which exceeds my 4GB RAM. Aapt would only use a fraction of the 2GB but the calculation fails.
The downside of allowing this overcommit apparently is that the kernel has no clean solution when you are running low on memory, and will just kill processes.
Another solution is to use a swap, in my case a swap file as I did not foresee a swap partition, and then preferably with a very low swappiness. Your linux manual should tell you how, but in summary (this is only for a quick test, you should set up your /etc/fstab instead):
Setting the swappiness so low makes it so that the swap is in reality never used. This is also the biggest downside of this solution. You'll have a 2GB file on your harddisk that you'll never use, except to satisfy the kernel's calculations (and maybe a rare extreme low memory, not sure how 0 swappiness works?). It is said to be a bad idea to use a swap on an SSD as the many writes will shorten the lifetime of the SSD.
The following articles led me to the solution.
How to solve "java.io.IOException: error=12, Cannot allocate memory" calling Runtime#exec()?
http://webcache.googleusercontent.com/search?q=cache:2NSdg-wIVsAJ:wiki.apache.org/cassandra/Operations+java.io.IOException+insufficient+system+resources+no+swap&cd=4&hl=nl&ct=clnk&gl=be&lr=lang_en|lang_nl
Note that it is not aapt that is at fault here, nor are the Android dev tools. I could have seen this problem anywhere. I do think however that due to the gigantic (and increasing) size of the eclipse toolkit, coupled maybe with some implementation details, such as the use of fork()?, this problem has a very high likelihood of surfacing here, also for other people with SSDs.
相应地增加 studio64.vmoptions 或 studio.vmoptions 上的内存,它对我有用,我只是将其增加到所有内容的两倍,几乎是 3 倍,例如 Xms 512, Xmx 4096, -XX:MaxPermSize=720m, XX:ReservedCodeCacheSize=128m 。
希望对未来的人有用。
Increase the memory on studio64.vmoptions or studio.vmoptions accordingly it worked for me, i just increased it to double everything, almost 3 times for example Xms 512, Xmx 4096, -XX:MaxPermSize=720m, XX:ReservedCodeCacheSize=128m .
Hope is useful for someone in the future.
顺便说一下,如果您使用的是 Windows,您的病毒扫描程序可能会删除 aapt.exe(这就是 Avast Antivirus 在我的例子中所做的)
By the way if you are using Windows it can happen that your virus scanner deletes the aapt.exe (thats what Avast Antivirus did in my case)