-1

我已经完成了一个针对 4.1 API 的 android 应用程序,但是当我将它用于 2.3 API 时,我遇到了很多错误!

所以我想解决这些错误,以便在 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'
4

2 回答 2

4

Its likely due to you using resources that are only in the 4.1 API and not in 2.3.

Obviously if you are using new resources or API code, such as the buttonBarStyle, this won't be available in earlier versions. I think the earliest buttonBarStyle was available was Honeycomb which was version 3.

In order to make your app compatible, you would need to do checks within your code so that it uses the right API for the API that is being used.

In your example of the resources not being available, the easiest thing to do would be to create layouts based on the API versions.

In your standard layout folder you contain the layouts for the API that you are currently targeting, but you create layout folder for the older API levels where you are using stuff that isn't available.

For example, to create your layout for Android 2.3, create a folder /res/layout-v9 and create an xml file, of the same name as in your layout folder and recreate the design to suit the older API.

The layout within the v9 folder will automatically be used for 2.3 devices. It does depend on what 2.3 version you are using. E.g. 2.3-2.3.2 is API level 9 and 2.3.3 to 2.3.7 is API level 10 you just need to ensure the file name matches.

For example, in your /res/layout folder you have the design of your main activity called main_activity.xml which will make use of the new resources and designs available in version Android 4 and above (Ice Cream Sandwich and above).

In your res/layout-v9 folder you have the design of your main activity, still called, main_activity.xml which will make use of the older API resources.

Regarding java code, you would need to do checks to see which version you are running, and if the API level is below a certain value, e.g. before version 4, run the old API code, otherwise run the new API code.

To get the current SDK version that your app is running on use the following.

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

To get the API level for a specific android version use below as an example

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

Therefore in order to check which code to run, i.e. the new API version code or the old API code you could do something like the following

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
}

For information about the various android versions and what their API level is refer to http://developer.android.com/about/dashboards/index.html

Hope this helps

于 2013-08-30T12:09:05.723 回答
2

我遇到了以下具体问题:

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

我对清单或一般代码所做的任何更改都没有任何区别。我找到的,Android Developer Studio 没有标记的是 strings.xml 文件中的错误字符。

在两个字符串定义之间有一个破折号('-')。在我的情况下,这就是导致该问题的原因。

在我的清单中,我的最低 API 级别为 14,目标为 18。不支持低于 14 的任何内容。

于 2014-01-13T19:01:09.473 回答