2013-08-30 71 views
-1

我已经做了一个android应用程序来定位4.1 API,但是当我使用2.3 API时,我得到了很多错误!2.3 Api android无法工作

所以我想要解决这些错误,以便在Google play上发布只有2.3 API设备的相同应用程序,该怎么做?并且可以修复该错误?

[2013-08-30 13:24:10 - SAMS] Error in an XML file: aborting build. 
    [2013-08-30 13:24:33 - SAMS] W/ResourceType(18388): ResXMLTree_node header size  0x2 is too small. 
    [2013-08-30 13:24:33 - SAMS] W/ResourceType(18388): ResXMLTree_node header size 0x2 is too small. 
    [2013-08-30 13:24:33 - SAMS] W/ResourceType(18388): ResXMLTree_node header size 0x2 is too small. 
    [2013-08-30 13:24:33 - SAMS] W/ResourceType(18388): ResXMLTree_node header size 0x2 is too small. 
    [2013-08-30 13:24:33 - SAMS] W/ResourceType(18388): ResXMLTree_node header size 0x2 is too small. 
    [2013-08-30 13:24:33 - SAMS] W/ResourceType(18388): ResXMLTree_node header size 0x2 is too small. 
    [2013-08-30 13:24:33 - SAMS] W/ResourceType(18388): ResXMLTree_node header size 0x2 is too small. 
    [2013-08-30 13:24:33 - SAMS] W/ResourceType(18388): ResXMLTree_node header size 0x2 is too small. 
    [2013-08-30 13:24:33 - SAMS] W/ResourceType(18388): ResXMLTree_node header size 0x2 is too small. 
    [2013-08-30 13:24:33 - SAMS] W/ResourceType(18388): ResXMLTree_node header size 0x2 is too small. 
    [2013-08-30 13:24:33 - SAMS] W/ResourceType(18388): ResXMLTree_node header size 0x2 is too small. 
    [2013-08-30 13:24:33 - SAMS] W/ResourceType(18388): ResXMLTree_node header size 0x2 is too small. 
    [2013-08-30 13:24:33 - SAMS] W/ResourceType(18388): ResXMLTree_node header size 0x2 is too small. 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\layout-xhdpi\activity_classtable.xml:254: error: Error: No resource found that matches the given name (at 'style' with value '?android:attr/buttonBarButtonStyle'). 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\layout-xhdpi\activity_classtable.xml:261: error: Error: No resource found that matches the given name (at 'style' with value '?android:attr/buttonBarButtonStyle'). 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\layout-xhdpi\activity_classtable.xml:269: error: Error: No resource found that matches the given name (at 'style' with value '?android:attr/buttonBarButtonStyle'). 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\layout-mdpi\activity_contactus.xml:69: error: No resource identifier found for attribute 'spinnerMode' in package 'android' 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\layout-xhdpi\activity_contactus.xml:73: error: Error: No resource found that matches the given name (at 'spinnerStyle' with value '@android:style/Widget.Spinner.DropDown'). 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\layout-mdpi\activity_setting.xml:9: error: Error: No resource found that matches the given name (at 'spinnerStyle' with value '@android:style/Widget.Spinner.DropDown'). 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\layout-xhdpi\rep2.xml:2: error: No resource identifier found for attribute 'columnCount' in package 'android' 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\layout-xhdpi\rep2.xml:9: error: No resource identifier found for attribute 'layout_row' in package 'android' 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\layout-xhdpi\special_spinner_dropdown.xml:1: error: No resource identifier found for attribute 'textIsSelectable' in package 'android' 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\menu\about.xml:3: error: No resource identifier found for attribute 'showAsAction' in package 'android' 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\menu\aboutus.xml:3: error: No resource identifier found for attribute 'showAsAction' in package 'android' 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\menu\admin_login.xml:3: error: No resource identifier found for attribute 'showAsAction' in package 'android' 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\menu\alarm.xml:3: error: No resource identifier found for attribute 'showAsAction' in package 'android' 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\menu\alarm_receiver.xml:3: error: No resource identifier found for attribute 'showAsAction' in package 'android' 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\menu\classtable.xml:3: error: No resource identifier found for attribute 'showAsAction' in package 'android' 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\menu\contactus.xml:3: error: No resource identifier found for attribute 'showAsAction' in package 'android' 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\menu\dash_board.xml:3: error: No resource identifier found for attribute 'showAsAction' in package 'android' 
    [2013-08-30 13:24:33 - SAMS] C:\Users\pc\workspace\SAMS\res\menu\list.xml:3: error: No resource identifier found for attribute 'showAsAction' in package 'android' 
+0

向我们展示错误引发的代码。 – LuigiEdlCarno

+0

所有R中包含内容布局不起作用,一旦将API更改为4.1,每件事情都可以正常 –

+0

发布您的清单 – BRK

回答

4

这可能是由于您使用的资源仅在4.1 API而不在2.3中。

很显然,如果您使用的是新资源或API代码(如buttonBarStyle),则在较早版本中将不可用。我认为最早的buttonBarStyle可用是Honeycomb,它是第3版。

为了使您的应用程序兼容,您需要在代码中进行检查,以便为正在使用的API使用正确的API。

在您的资源不可用的示例中,最简单的方法是根据API版本创建布局。

在标准布局文件夹中,您包含您当前定位的API的布局,但是您在使用不可用的东西的情况下为较旧的API级别创建布局文件夹。

例如,要为Android 2.3创建布局,请创建一个文件夹/ res/layout-v9并创建一个与布局文件夹中名称相同的xml文件,然后重新创建设计以适应旧的API。

v9文件夹内的布局将自动用于2.3设备。它取决于你使用的2.3版本。例如。 2.3-2.3.2是API级别9,2.3.3至2.3.7是您只需确保文件名称匹配的API级别10。

例如,在您的/res/layout文件夹中,您的主要活动叫做main_activity.xml,它将利用Android 4及更高版本(冰淇淋三明治及更高版本)中提供的新资源和设计。

在您的res/layout-v9文件夹中,您设计了主要活动(仍称为main_activity.xml),该活动将使用较旧的API资源。

关于java代码,您需要执行检查以查看您正在运行的是哪个版本,并且如果API级别低于特定值(例如,在版本4之前,运行旧的API代码,否则运行新的API代码。

要获取应用程序运行的当前SDK版本,请使用以下内容。

int apiLevel = android.os.Build.VERSION.SDK_INT 

要获得低于特定机器人版本使用API​​级别作为一个例子

int apiLevelForVersion = android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH 

因此,为了检查要运行的代码,即新的API版本的代码或旧的API代码,你可以不喜欢以下

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) 
{ 
    //Run API code which is in Ice cream sandwich above 
} 
else 
{ 
    //Use older version API code to ensure backward compatibility with older devices running old Android version 
} 

有关各种Android的版本和信息是什么他们的API等级是指http://developer.android.com/about/dashboards/index.html

希望这有助于

+0

不错的答案,但创建V9布局后..如何使它自动运行只与只有api2.3设备? –

+0

我已更新我的答案以提供更多信息。希望这有助于 – Boardy

2

我遇到以下具体问题:

android-apt-compiler:[] W/ResourceType(37145):ResXMLTree_node标头大小0x2太小。

我对我的清单或代码做出的修改都没有改变。我找到的Android Developer Studio没有标记的是strings.xml文件中的错误字符。

在2个字符串定义之间有一个破折号字符(' - ')。这是我这个问题的原因。

在我的清单中,我的最低API级别为14,目标为18。

+0

我的问题是在我的strings.xml文件中的一个和符号'&'。所有&字符应替换为值“&”。 – TheIT