我們要寫入manifest文件的最后一個元素就是<uses-sdk>。它是<manifest>的子元素。在第二章創(chuàng)建Hello World項目的時候,在New Android Project對話框中,通過指定Android SDK 的最小版本,我們已經(jīng)使用了<uses-sdk>元素。
但是我們怎么在<manifest>中指定它呢?這有個例子:
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="9"/>
和我們在第二章中討論的一樣,每一個Android SDK 版本號都對應(yīng)一個整形數(shù)字。<uses-sdk>指定了我們應(yīng)用所支持的最低Android SDK版本號,和我們應(yīng)用所使用的版本號。
<uses-sdk> 元素允許配置我們的應(yīng)用,一個低版本的android sdk開發(fā),而能夠在最新的android系統(tǒng)上運行(向上兼容)。一個突出的例子就是多點觸控APIs,多點觸控在SDK 5(Android 2.0)或以上版本才能夠被支持。當我們在Eclipse中設(shè)置Android 項目的時候,我們使用build target來選擇支持多點觸控的Android 版本——舉個例子,SDK 5或更高(我通常設(shè)置成最新的版本,在我寫這本書的時候是SDK 9)。如果我們想讓我們的游戲在安裝有SDK 3(Android 1.5)的系統(tǒng)的設(shè)備上運行,我們就可以和剛才的例子一樣,在manifest文件中指定minSdkVersion屬性。當然,使用高版本開發(fā)時,我們必須小心別去使用那些在低版本中不可用的API,比如說高版本SDK兼容安裝了1.5系統(tǒng)的設(shè)備。如果設(shè)備安裝了高版本的系統(tǒng),那么我們就可以很好的使用更新的APIs了。
前面的配置說明已經(jīng)可以適用于大多數(shù)的游戲開發(fā)(除非你不能為一個更高版本的APIs提供獨立的代碼路徑,而在這種情況下你會希望設(shè)置minSdkVersion為你實際支持的最低的SDK版本)
終于完結(jié)了。
最近看到第7章 OpenGL ES的內(nèi)容。~所以接下來翻譯會和第七章有關(guān)。
書中有一個最簡單的Android游戲框架。。。雖然小但是能學到很多東西..感覺是libgdx的迷你版本(此書作者是libgdx框架的開發(fā)者之一~)
我會把源碼上傳。
最后附上原文:
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).
|