AndroidManifest.xml 詳解 (六) 之uses-sdk—— 譯自《Beginning Android Games》

   我們要寫入manifest文件的最後一個元素就是<uses-sdk>。它是<manifest>的子元素。在第二章創建Hello World項目的時候,在New Android Project對話框中,通過指定Android SDK 的最小版本,我們已經使用了<uses-sdk>元素。

 

   但是我們怎麼在<manifest>中指定它呢?這有個例子:

 

   <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="9"/>

 

   和我們在第二章中討論的一樣,每一個Android SDK 版本號都對應一個整形數字。<uses-sdk>指定了我們應用所支持的最低Android SDK版本號,和我們應用所使用的版本號。

 

    <uses-sdk> 元素允許配置我們的應用,一個低版本的android sdk開發,而能夠在最新的android系統上運行(向上兼容)。一個突出的例子就是多點觸控APIs,多點觸控在SDK 5(Android 2.0)或以上版本才能夠被支持。當我們在Eclipse中設置Android 項目的時候,我們使用build target來選擇支持多點觸控的Android 版本——舉個例子,SDK 5或更高(我通常設置成最新的版本,在我寫這本書的時候是SDK 9)。如果我們想讓我們的遊戲在安裝有SDK 3(Android 1.5)的系統的設備上運行,我們就可以和剛纔的例子一樣,在manifest文件中指定minSdkVersion屬性。當然,使用高版本開發時,我們必須小心別去使用那些在低版本中不可用的API,比如說高版本SDK兼容安裝了1.5系統的設備。如果設備安裝了高版本的系統,那麼我們就可以很好的使用更新的APIs了。

 

    前面的配置說明已經可以適用於大多數的遊戲開發(除非你不能爲一個更高版本的APIs提供獨立的代碼路徑,而在這種情況下你會希望設置minSdkVersion爲你實際支持的最低的SDK版本)

 

終於完結了。

最近看到第7章 OpenGL ES的內容。~所以接下來翻譯會和第七章有關。

書中有一個最簡單的Android遊戲框架。。。雖然小但是能學到很多東西..感覺是libgdx的迷你版本(此書作者是libgdx框架的開發者之一~)

我會把源碼上傳。

 

 

最後附上原文:

The <uses-sdk> Element


The last element we’ll put in our manifest file is the <uses-sdk> element. It is a child of
the <manifest> element. We implicitly defined this element when we created our Hello
World project in Chapter 2 when we specified the minimum SDK version in the New
Android Project dialog. So what does this element do? Here’s an example:


<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="9"/>


As we discussed in Chapter 2, each Android version has an integer assigned, also
known as an SDK version. The <uses-sdk> element specifies what minimum version our
application supports and what the target version of our application is. 


This element allows us to deploy an application that uses APIs that are only available in
newer versions to devices that have a lower version installed. One prominent example
would be the multitouch APIs, which are supported from SDK version 5 (Android 2.0)
onward. When we set up our Android project in Eclipse, we use a build target that
supports that API—for example, SDK version 5 or higher (I usually set it to the latest
SDK version, which is 9 at the time of writing). If we want our game to run on devices
with SDK version 3 (Android 1.5) as well, we specify the minSdkVersion as before in the
manifest file. Of course we must be careful not to use any APIs that are not available on
the lower version, at least on a 1.5 device. On a device with a higher version, we can use
the newer APIs as well.


The preceding configuration is usually fine for most games (unless you can’t provide a
separate fallback code path for the higher-version APIs, in which case you will want to
set the minSdkVersion attribute to the minimum SDK version you actually support).

發佈了22 篇原創文章 · 獲贊 5 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章