我們要寫入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).