Android 样式资源编译 (aapt) 失败:资源表错误:标头大小 0xc
我刚刚花了几个小时来解决一个与样式有关的可怕的 Android 资源预编译问题,想知道有人能解释一下是什么原因造成的。我修复了它,但不知道问题是什么。 Android 说错误在colors.xml 中而不是在另一个xml 中,这并没有帮助。
第1步 - 重新创建错误
Given a style
<style name="ActionBarTitleContainer">
<item name="android:id">@id/title_container</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">@dimen/title_height</item>
<item name="android:orientation">horizontal</item>
<item name="android:background">@color/title_color_light</item>
</style>
我复制了它,给了它新的,android:id
<item name="android:id">@id/info_container</item>
<style name="ActionBarTitleContainer">
<item name="android:id">@id/title_container</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">@dimen/title_height</item>
<item name="android:orientation">horizontal</item>
<item name="android:background">@color/title_color_light</item>
</style>
<style name="ActionBarInfoContainer">
<item name="android:id">@id/info_container</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">@dimen/info_height1</item>
<item name="android:orientation">horizontal</item>
<item name="android:background">@color/title_color_light</item>
</style>
保存并编译说id中有错误
<style name="ActionBarInfoContainer">
<item name="android:id">@id/info_container</item>
Description Resource Path Location Type
error: Error: No resource found that matches the given name (at 'android:id' with value '@id/info_container'). styles.xml /MyApp/res/values line 68 Android AAPT Problem
所以我错误地在id之前添加了一个+
<style name="ActionBarInfoContainer">
<item name="android:id">@+id/info_container</item>
然后得到了错误
W/ResourceType( 2202): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
W/ResourceType( 2202): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
ERROR: Unable to parse generated resources, aborting.
'aapt' error. Pre Compiler Build aborted.
遗憾的是我添加了很多样式等而不仅仅是这个所以花了很长时间回溯才找到错误。 Android 说在 color.xml 中发生错误,但事实并非如此,这并没有帮助。
通过
从 styles.xml 中删除 + 并
中放置新 id
<style name="ActionBarTitleContainer">
<item name="android:id">@id/title_container</item>
....
</style>
<style name="ActionBarInfoContainer">
<item name="android:id">@id/info_container</item>
....
</style>
在ids.xml 来修复 @+id/info_container 到 @id/info_container
并将 id 添加到 ids.xml
<resources>
<item type="id" name="title_container" />
<item type="id" name="info_container" />
知道错误意味着什么,因为我花了几个小时的痛苦才找到它。
Android aapt 编译器没有帮助,说错误是由 color.xml 引起的。
这个错误是我针对2.1U1编译造成的吗?
我有最新的 SDK,但每个平台文件夹中都有一个 aapt,但日期是 2011 年 4 月。
And for future reference as I found very little info on aapt resource compiling. Heres some tips for people with Resource compilation errors, so you dont lose hours on bad google error reporting:
提示 1 - 打开详细的 ANDROID 构建输出
Open Eclipse Preferences
Open in the list on the left
Android
Build
Set Build output to
Verbose
Hit OK
Open Console View
Window > View > Console
Do clean build or type a space in and file and hit save if you dont want to do full build
Resources compiler aapt will run first
and throw error
两个问题
问题 1 - 输出中可能会出现红色错误,位置混乱,
可能是由于线程中抛出异常造成的,但在构建过程完全停止之前,其他文件仍然编译正常。
请注意此处错误似乎是如何在nearest_bus_stops_layout.xml 之后发生的。
[2011-05-15 16:22:25 - MyApp] (new resource id filechooser_file_view from /Users/user1/Documents/workspace/MyApp/res/layout/filechooser_file_view.xml)
[2011-05-15 16:22:25 - MyApp] (new resource id listbusmapsactivity_layout from /Users/user1/Documents/workspace/MyApp/res/layout/listbusmapsactivity_layout.xml)
[2011-05-15 16:22:25 - MyApp] (new resource id nearest_bus_maps_layout from /Users/user1/Documents/workspace/MyApp/res/layout/nearest_bus_maps_layout.xml)
[2011-05-15 16:22:25 - MyApp] (new resource id nearest_bus_stops_layout from /Users/user1/Documents/workspace/MyApp/res/layout/nearest_bus_stops_layout.xml)
[2011-05-15 16:22:25 - MyApp] W/ResourceType( 2247): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
[2011-05-15 16:22:25 - MyApp] W/ResourceType( 2247): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
[2011-05-15 16:22:25 - MyApp] ERROR: Unable to parse generated resources, aborting.
[2011-05-15 16:22:25 - MyApp] (new resource id open_web_page_activity from /Users/user1/Documents/workspace/MyApp/res/layout/open_web_page_activity.xml)
[2011-05-15 16:22:25 - MyApp] (new resource id send_email_activity from /Users/user1/Documents/workspace/MyApp/res/layout/send_email_activity.xml)
[2011-05-15 16:22:25 - MyApp] 'aapt' error. Pre Compiler Build aborted.
这不是错误所在的文件。
提示:如何查找确切导致问题的文件
查找错误消息之前提到的最后一个文件:
'aapt' error. Pre Compiler Build aborted.
这是
/send_email_activity.xml
问题:send_email_activity.xml 不是出现错误的文件。
send_email_activity.xml 编译正常并输出。
这是我们想要的 /send_email_activity.xml 之后的一个
问题:引发错误的文件名缺失。
如何在 /send_email_activity.xml 之后查找导致错误的文件
在控制台输出中向上滚动到
Files:
aapt 编译器列出其找到的所有文件并将进行编译。
幸运的是,Files: 中的顺序与下面抛出错误时的顺序相同
在 Files: 部分中查找最后一个要编译的文件 (send_email_activity.xml)
TIP In the Console window find the last file that compiled ok before the error
'send_email_activity.xml'
And do CTRL/CMD(Mac) + F for previous occurrences under the Files: section
我们可以在这里看到 /send_email_activity.xml 后面跟着 color.xml
Files:
drawable/alphabet_bar_bg.xml
Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/res/drawable/alphabet_bar_bg.xml
drawable/alphabet_separator_bg.xml
Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/res/drawable/alphabet_separator_bg.xml
.......
layout/send_email_activity.xml
Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/res/layout/send_email_activity.xml
values/colors.xml
Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/res/values/colors.xml
.......
values/themes.xml
Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/res/values/themes.xml
AndroidManifest.xml
Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/AndroidManifest.xml
答案:colors.xml是导致的文件 “aapt”错误。预编译器构建已中止。
还有错误:
[2011-05-15 16:22:25 - MyApp] W/ResourceType( 2247): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
[2011-05-15 16:22:25 - MyApp] W/ResourceType( 2247): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
[2011-05-15 16:22:25 - MyApp] ERROR: Unable to parse generated resources, aborting.
问题 2:colors.xml 中的错误 ISNT。
我更改了colors.xml中的颜色值
,但它已在styles.xml
styles.xml
<style name="ActionBarInfoContainer">
<item name="android:id">@id/info_container</item>
...
<item name="android:background">@color/title_color_light</item>
</style>
中引用,因此在编译过程中,它可能尝试编译styles.xml,然后看到@color,然后编译colors.xml。反之亦然(询问谷歌) 因此,它报告错误在 color.xml 中,而在 fast 中它是 styles.xml/ids.xml
并且只有当我看到 id 之间的差异时才注意到可能的错误
<style name="ActionBarTitleContainer">
<item name="android:id">@id/title_container</item>
...
</style>
<style name="ActionBarInfoContainer">
<item name="android:id">@+id/info_container</item>
...
</style>
该行
<item name="android:id">@+id/info_container</item>
应该是(无+)
<item name="android:id">@id/info_container</item>
并且id应该在ids.xml
<resources>
<item type="id" name="title_container" />
<item type="id" name="info_container" />
XML中..新千年的打孔卡!
I just spent a few hours with a horrible Android Resource pre compile problem to do with styles and was wondering could anyone explain what caused it. I fixed it but dont know whats the problem. Not helped by Android saying the error was in colors.xml and not in another xml.
Step 1 - to recreate error
Given a style
<style name="ActionBarTitleContainer">
<item name="android:id">@id/title_container</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">@dimen/title_height</item>
<item name="android:orientation">horizontal</item>
<item name="android:background">@color/title_color_light</item>
</style>
I copied it, gave it new, android:id
<item name="android:id">@id/info_container</item>
<style name="ActionBarTitleContainer">
<item name="android:id">@id/title_container</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">@dimen/title_height</item>
<item name="android:orientation">horizontal</item>
<item name="android:background">@color/title_color_light</item>
</style>
<style name="ActionBarInfoContainer">
<item name="android:id">@id/info_container</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">@dimen/info_height1</item>
<item name="android:orientation">horizontal</item>
<item name="android:background">@color/title_color_light</item>
</style>
Saved and Compile said error in id
<style name="ActionBarInfoContainer">
<item name="android:id">@id/info_container</item>
Description Resource Path Location Type
error: Error: No resource found that matches the given name (at 'android:id' with value '@id/info_container'). styles.xml /MyApp/res/values line 68 Android AAPT Problem
So mistakenly I added a + before the id
<style name="ActionBarInfoContainer">
<item name="android:id">@+id/info_container</item>
Then got error
W/ResourceType( 2202): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
W/ResourceType( 2202): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
ERROR: Unable to parse generated resources, aborting.
'aapt' error. Pre Compiler Build aborted.
Sadly I had added a lot of style etc not just this one so spent ages back tracking to find the error. Not helped by Android saying error occuring in colors.xml when it wasnt.
Fixed by
removing the + from styles.xml
placing new id in ids.xml
<style name="ActionBarTitleContainer">
<item name="android:id">@id/title_container</item>
....
</style>
<style name="ActionBarInfoContainer">
<item name="android:id">@id/info_container</item>
....
</style>
Changed
@+id/info_container
to
@id/info_container
And adding id to ids.xml
<resources>
<item type="id" name="title_container" />
<item type="id" name="info_container" />
Any idea what the error means because it took me a few hours of pain to track it down.
Not helped by Android aapt compiler saying the error was caused around colors.xml.
Is this error caused by me compiling against 2.1U1?
I have the latest SDK but there is an aapt in each platform folder but date against it is APR 2011.
And for future reference as I found very little info on aapt resource compiling. Heres some tips for people with Resource compilation errors, so you dont lose hours on bad google error reporting:
TIP 1 - TURN ON VERBOSE ANDROID BUILD OUTPUT
Open Eclipse Preferences
Open in the list on the left
Android
Build
Set Build output to
Verbose
Hit OK
Open Console View
Window > View > Console
Do clean build or type a space in and file and hit save if you dont want to do full build
Resources compiler aapt will run first
and throw error
Two issues
Issue 1 - error in red may appear in output in confusing location
probably caused by Exception being throw in a thread but other files still compile ok before build process fully stops.
Notice here how the error seems to occur after nearest_bus_stops_layout.xml.
[2011-05-15 16:22:25 - MyApp] (new resource id filechooser_file_view from /Users/user1/Documents/workspace/MyApp/res/layout/filechooser_file_view.xml)
[2011-05-15 16:22:25 - MyApp] (new resource id listbusmapsactivity_layout from /Users/user1/Documents/workspace/MyApp/res/layout/listbusmapsactivity_layout.xml)
[2011-05-15 16:22:25 - MyApp] (new resource id nearest_bus_maps_layout from /Users/user1/Documents/workspace/MyApp/res/layout/nearest_bus_maps_layout.xml)
[2011-05-15 16:22:25 - MyApp] (new resource id nearest_bus_stops_layout from /Users/user1/Documents/workspace/MyApp/res/layout/nearest_bus_stops_layout.xml)
[2011-05-15 16:22:25 - MyApp] W/ResourceType( 2247): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
[2011-05-15 16:22:25 - MyApp] W/ResourceType( 2247): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
[2011-05-15 16:22:25 - MyApp] ERROR: Unable to parse generated resources, aborting.
[2011-05-15 16:22:25 - MyApp] (new resource id open_web_page_activity from /Users/user1/Documents/workspace/MyApp/res/layout/open_web_page_activity.xml)
[2011-05-15 16:22:25 - MyApp] (new resource id send_email_activity from /Users/user1/Documents/workspace/MyApp/res/layout/send_email_activity.xml)
[2011-05-15 16:22:25 - MyApp] 'aapt' error. Pre Compiler Build aborted.
THIS IS NOT THE FILE WHERE THE ERROR IS.
TIP: How to FIND WHICH FILE EXACTLY CAUSING THE PROBLEM
Find the last file that's mentioned before the error message:
'aapt' error. Pre Compiler Build aborted.
This is
/send_email_activity.xml
PROBLEM: send_email_activity.xml isnt the file with the error.
send_email_activity.xml compiled ok and was output.
ITS THE ONE AFTER /send_email_activity.xml that we want
Problem: filename that threw the error missing.
How to Find the file AFTER /send_email_activity.xml that caused the error
Scroll UP in console output to
Files:
The aapt compiler lists all files its found and is going to compile.
Luckily the order in Files: is the same as when the error is thrown down below
Look for the last file to compile (send_email_activity.xml) in the Files: section
TIP In the Console window find the last file that compiled ok before the error
'send_email_activity.xml'
And do CTRL/CMD(Mac) + F for previous occurrences under the Files: section
We can see here that /send_email_activity.xml is followed by colors.xml
Files:
drawable/alphabet_bar_bg.xml
Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/res/drawable/alphabet_bar_bg.xml
drawable/alphabet_separator_bg.xml
Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/res/drawable/alphabet_separator_bg.xml
.......
layout/send_email_activity.xml
Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/res/layout/send_email_activity.xml
values/colors.xml
Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/res/values/colors.xml
.......
values/themes.xml
Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/res/values/themes.xml
AndroidManifest.xml
Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/AndroidManifest.xml
ANSWER: colors.xml IS THE FILE THAT CAUSED
'aapt' error. Pre Compiler Build aborted.
And also the error:
[2011-05-15 16:22:25 - MyApp] W/ResourceType( 2247): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
[2011-05-15 16:22:25 - MyApp] W/ResourceType( 2247): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
[2011-05-15 16:22:25 - MyApp] ERROR: Unable to parse generated resources, aborting.
Problem 2: the error ISNT in colors.xml.
I had changed a color value in colors.xml
but it had been referenced in styles.xml
styles.xml
<style name="ActionBarInfoContainer">
<item name="android:id">@id/info_container</item>
...
<item name="android:background">@color/title_color_light</item>
</style>
So in the compile process it probably tried to compile styles.xml then saw @color so then compiled colors.xml. Or visa versa (ask Google)
So it reported the error as being in colors.xml when in fast it was styles.xml/ids.xml
And the possible error was only noticed when I saw the difference in id between the
<style name="ActionBarTitleContainer">
<item name="android:id">@id/title_container</item>
...
</style>
<style name="ActionBarInfoContainer">
<item name="android:id">@+id/info_container</item>
...
</style>
The line
<item name="android:id">@+id/info_container</item>
Should be (no +)
<item name="android:id">@id/info_container</item>
And id should be in ids.xml
<resources>
<item type="id" name="title_container" />
<item type="id" name="info_container" />
XML ..the punchcards of the new millenium!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在导入库项目(GreenDroid)时遇到了这个问题,结果对我来说也是 @+id 问题。
似乎正在发生的事情是,只要您没有 ids.xml 文件,Android SDK 就会允许您在 styles.xml 中声明新的 id,但是该文件存在的那一刻,它就不再允许这种行为。不幸的是,它并没有告诉您这就是问题所在,而只是因原始帖子中指出的错误而崩溃:
I ran into this issue when importing a library project (GreenDroid) and it turned out to be the @+id issue for me as well.
What seems to be happening is that as long as you don't have a ids.xml file the Android SDK will allow you to declare new ids in styles.xml, but the moment that file exists it stops allowing this behavior. Unfortunately, it doesn't tell you that this is the problem and just crashes with the error noted in the original post:
在此页面上,您将找到有关以下含义的文档<代码>+。页面文档布局 XML 文件,但这同样适用于样式(是的,他们应该将此信息放在更好的位置)。
为了您的方便,以下是相关文档:
On this page you'll find documentation on the meaning of
+
. The page documents layout XML files, but the same applies to styles (yeah, they should put this information in a better place).For your convenience, here's the relevant documentation: