Android的风格资源编译(AAPT)失败:坏资源表:头大小0xC的资源、大小、风格、Android

2023-09-03 23:06:33 作者:执笔√续写承诺

我只花了几个小时,一个可怕的Andr​​oid资源pre编译问题做款式,想知道谁能解释什么原因造成的。我固定的,但不知道什么问题。并非得益于Android的话说,误差在colors.xml,而不是在另一个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.

第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>

我复制它,赋予它新的机器人:ID

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>

保存和编译说,在ID错误

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

所以我误加了+前的ID

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.

可悲的是我已经加了很多款式等不只是这一个,这样花了年龄回溯查找错误。并非得益于Android的说法误差存在的在colors.xml时,它不是。

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.

从styles.xml取出+

removing the + from styles.xml

在ids.xml放置新的ID

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>

变更     @ + ID / info_container 至     @ ID / info_container

Changed @+id/info_container to @id/info_container

和加入id来ids.xml

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.

不是得益于Android的AAPT编译器说错误是围绕colors.xml造成的。

Not helped by Android aapt compiler saying the error was caused around colors.xml.

是由我编写针对2.1U1这个错误?

Is this error caused by me compiling against 2.1U1?

我有最新的SDK,但有一个AAPT在每个平台文件夹,但迄今为止反对它是4月2011.

I have the latest SDK but there is an aapt in each platform folder but date against it is APR 2011.

而对于未来的参考,因为我发现AAPT资源编译很少的信息。下面有一些技巧的人与资源编译错误,所以你不要失去坏谷歌的错误报告时间:

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生成输出

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

两个问题

第1 - 红色错误可能出现在混乱的位置输出

Issue 1 - error in red may appear in output in confusing location

可能是由异常被扔在一个线程引起,但其他文件仍然编译OK(确定)构建过程完全停止。

probably caused by Exception being throw in a thread but other files still compile ok before build process fully stops.

请注意这里是如何的错误似乎nearest_bus_stops_layout.xml后出现。

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.

提示:如何找到的文件EXACTLY造成问题的原因。

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.

这是

/send_email_activity.xml

问题:send_email_activity.xml心不是有错误的文件

PROBLEM: send_email_activity.xml isnt the file with the error.

send_email_activity.xml编译OK,是输出。

send_email_activity.xml compiled ok and was output.

它在/send_email_activity.xml,我们希望经过一

ITS THE ONE AFTER /send_email_activity.xml that we want

问题:文件名抛出错误遗漏。

Problem: filename that threw the error missing.

如何查找文件/send_email_activity.xml后导致错误

How to Find the file AFTER /send_email_activity.xml that caused the error

滚动控制台输出

Files:

该AAPT编译器列表中的所有文件的发现,并会进行编译。

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

查找最后一个文件汇编(send_email_activity.xml)中的文件:部分

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

我们可以在这里看到,/send_email_activity.xml后跟colors.xml

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

答:colors.xml是导致该文件     AAPT的错误。 pre编译器编译中止。

ANSWER: colors.xml IS THE FILE THAT CAUSED 'aapt' error. Pre Compiler Build aborted.

和还错误:

[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。

Problem 2: the error ISNT in colors.xml.

我在colors.xml改变了颜色值

I had changed a color value in colors.xml

但它已在styles.xml引用

but it had been referenced in styles.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。反之亦然(问谷歌) 因此,报告错误在colors.xml是当快是styles.xml / ids.xml

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

当我看到差异ID之间可能出现的错误是只注意到

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>

 <item name="android:id">@+id/info_container</item>

应该是(无+)

Should be (no +)

 <item name="android:id">@id/info_container</item>

和ID应该是在ids.xml

And id should be in ids.xml

<resources>
     <item type="id" name="title_container" />
     <item type="id" name="info_container"  />

新千年的

XML ..the穿孔卡!

XML ..the punchcards of the new millenium!

推荐答案

我导入库项目(GreenDroid)时,就遇到了这个问题,它原来是@ + 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.

什么似乎是发生的是,只要你没有的 ids.xml 的文件中的Andr​​oid SDK将允许您在申报新的IDS的 styles.xml ,但该文件存在,它的那一刻停止允许这种行为。不幸的是,它不会告诉你,这就是问题所在,只是崩溃的错误在原岗位说明:

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:


 W/ResourceType( 2247): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary