Android风格资源编译(aapt)失败:错误的资源表:标头大小0xc

bri*_*ear 14 xml resources android aapt

我花了几个小时与一个可怕的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>
Run Code Online (Sandbox Code Playgroud)

我复制了它,给了它新的,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>
Run Code Online (Sandbox Code Playgroud)

保存并编译表示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
Run Code Online (Sandbox Code Playgroud)

所以我错误地在id之前加了一个+

<style name="ActionBarInfoContainer">
    <item name="android:id">@+id/info_container</item>
Run Code Online (Sandbox Code Playgroud)

然后得到了错误

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.
Run Code Online (Sandbox Code Playgroud)

可悲的是,我添加了很多风格,而不仅仅是这个,所以花了很长时间回溯跟踪找到错误.Android没有帮助说在colors.xml中出现错误.

固定的

从styles.xml中删除+

将新id放在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>
Run Code Online (Sandbox Code Playgroud)

将@ + id/info_container更改为@ id/info_container

并将id添加到ids.xml

<resources>
    <item type="id" name="title_container" />
    <item type="id" name="info_container" />
Run Code Online (Sandbox Code Playgroud)

知道这个错误意味着什么,因为它花了我几个小时的痛苦来追踪它.

Android aapt编译器没有帮助说错误是由colors.xml引起的.

这是我编译2.1U1引起的错误吗?

我有最新的SDK但每个平台文件夹都有一个aapt,但是它的日期是APR 2011.


并且为了将来的参考,因为我发现很少有关于aapt资源编译的信息.以下是有关资源编译错误的人的一些提示,因此您不会因糟糕的谷歌错误报告而浪费时间:

提示1 - 开启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
Run Code Online (Sandbox Code Playgroud)

两个问题

问题1 - 在混乱的位置输出中可能会出现红色错误

可能是因为Exception被抛入一个线程但其他文件在构建过程完全停止之前仍然编译好.

请注意在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.
Run Code Online (Sandbox Code Playgroud)

这不是错误所在的文件.

提示:如何找到导致问题的文件

找到错误消息之前提到的最后一个文件:

'aapt' error. Pre Compiler Build aborted.
Run Code Online (Sandbox Code Playgroud)

这是

/send_email_activity.xml
Run Code Online (Sandbox Code Playgroud)

问题:send_email_activity.xml不是包含错误的文件.

send_email_activity.xml编译好并输出.

它是我们想要的/send_email_activity.xml之后的一个

问题:丢失错误的文件名.

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

在控制台输出中向上滚动到

Files:
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

我们在这里可以看到/send_email_activity.xml之后是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
Run Code Online (Sandbox Code Playgroud)

答案: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.
Run Code Online (Sandbox Code Playgroud)

问题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>
Run Code Online (Sandbox Code Playgroud)

所以在编译过程中它可能尝试编译styles.xml然后看到@color,然后编译colors.xml.或者反之亦然(问Google)所以它报告错误是在colors.xml中,当它快速时是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>
Run Code Online (Sandbox Code Playgroud)

这条线

 <item name="android:id">@+id/info_container</item>
Run Code Online (Sandbox Code Playgroud)

应该是(不+)

 <item name="android:id">@id/info_container</item>
Run Code Online (Sandbox Code Playgroud)

id应该在ids.xml中

<resources>
     <item type="id" name="title_container" />
     <item type="id" name="info_container"  />
Run Code Online (Sandbox Code Playgroud)

XML ..新千年的标语牌!

Tra*_*llo 7

我在导入库项目(GreenDroid)时遇到了这个问题,结果证明这也是我的@ + id问题.

似乎正在发生的事情是,只要你没有ids.xml文件,Android SDK就会允许你在styles.xml中声明新的id ,但是当文件存在时它就会停止允许这种行为.不幸的是,它没有告诉你这是问题,只是崩溃了原始帖子中提到的错误:

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


Klo*_*lox 1

在此页面上,您将找到有关 的含义的文档+。页面文档布局 XML 文件,但这同样适用于样式(是的,他们应该将此信息放在更好的位置)。

为了您的方便,以下是相关文档:

对于ID值,通常应该使用这种语法形式:“@+id/name”。加号 + 表示这是一个新的资源 ID,aapt 工具将在 R.java 类中创建一个新的资源整数(如果它尚不存在)。

...

但是,如果您已经定义了 ID 资源(并且尚未使用),则可以通过排除 android:id 值中的加号来将该 ID 应用于 View 元素。