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

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.