2013-08-30 73 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