天天看點

【菜鳥翻譯】Creating an Android Project Creating an Android Project

previousnext

create a project with eclipse

create a project with command line tools

installing the sdk

managing projects

an android project contains all the files that comprise the source code for your android app. the android sdk tools make it easy to start a new android project with a set of default project directories and files.

this lesson shows how to create a new project either using eclipse (with the adt plugin) or using the sdk tools from a command line.

note: you should already have the android sdk installed, and if you're using eclipse, you should also have the adt

plugininstalled (version 21.0.0 or higher). if you don't have these, follow the guide to installing the android sdk before

you start this lesson.

click new  in

the toolbar.

in the window that appears, open the android folder, select android application project, and click next.

figure 1. the new android app project wizard in eclipse.

fill in the form that appears:

click next.

application name is the app name that appears to users. for this project, use "my first app."

project name is the name of your project directory and the name visible in eclipse.

on the next screen to configure the project, leave the default selections and click next.

the next screen can help you create a launcher icon for your app.

you can customize an icon in several ways and the tool generates an icon for all screen densities. before you publish your app, you should be sure your icon meets the specifications defined in the iconography design

guide.

now you can select an activity template from which to begin building your app.

for this project, select blankactivity and click next.

leave all the details for the activity in their default state and click finish.

your android project is now set up with some default files and you’re ready to begin building the app. continue to the next

lesson.

if you're not using the eclipse ide with the adt plugin, you can instead create your project using the sdk tools from a command line:

change directories into the android sdk’s <code>tools/</code> path.

execute:

this prints a list of the available android platforms that you’ve downloaded for your sdk. find the platform against which you want to compile your app. make a note of the target id. we recommend that you select

the highest version possible. you can still build your app to support older versions, but setting the build target to the latest version allows you to optimize your app for the latest devices.

if you don't see any targets listed, you need to install some using the android sdk manager tool. see adding

platforms and packages.

replace <code>&lt;target-id&gt;</code> with an id from the list of targets (from the previous step) and replace <code>&lt;path-to-workspace&gt;</code> with

the location in which you want to save your android projects.

your android project is now set up with several default configurations and you’re ready to begin building the app. continue to the next

tip: add the <code>platform-tools/</code> as well as the <code>tools/</code> directory to your <code>path</code> environment

variable.

http://developer.android.com/training/basics/firstapp/creating-project.html

建立一個android項目

一個anroid項目包含的所有檔案,包括你項目的源代碼檔案。android的sdk工具能夠更容易的啟動一個新的項目設定項目預設的目錄和檔案。

這節課程展示怎樣建立一個新的項目,使用eclipse(帶有adt插件)或使用sdk工具指令行。

注意:你已經安裝了android的sdk,并且如果你使用eclipse,你也已經安裝了adt插件(21.0.0或以上版本)。如果你沒有完成這些,你在開始這節課之前,先參照

安裝sdk  。

使用eclipse建立一個項目。

1.點選工具條的 建立圖示。

2.在出現的window視窗中,打開android檔案夾,選擇android應用項目,點選下一步。

3.填寫出現的表格:

   應用名:是一個展示給使用者的app名字,如這個項目,使用“my first app”;

   項目名字:是一個你項目在eclipse中可見的名字。

   包名:是你的app的命名空間(在java項目中使用同樣的規則)。在你 安裝的所有android系統應用中,

              你的包名必須是唯一的。對于這個原因,它通常最好的方式是使用你公司或公共組織實體的反向域名。

              對于這個項目,你能使用一個像“com.example.myfirstapp”.然而,你是不能向google play中送出

              "com.example"命名空間的app.

   最小需要的sdk:是你的app支援的最低android版本。表明使用的api level.如果你要支援更多裝置,你應該

            盡可能的支援更低的版本,讓你的應用使用它的核心功能。如果你的應用使用了新的android

            版本上的功能,你需要指出它可支援的版本(如前所述 支援不同的平台版本)。

    目标sdk:表明你支援的的程式支援android最高版本(也使用api level)

            當一個新版本出來,你應該測試你的應用在新版本上使用這些的api,更好的比對最新的api,更好的适應

            新平台特性。

   編譯:是你app編譯的支援平台版本。預設,是你sdk的最新版本。(它可能是android4.1或更高,如果你沒有

            這些版本,你就必須使用sdk manager去安裝)。你能建構你的app支援最老的版本,但設定建構目标到

            最新版本允許你啟用新特性和優化你的應用程式在使用者最新的裝置上。

   主題:你可以特别指定你的ui樣式。你也可以不用設定。

 點選下一步。

4.在下一個頁面上配置項目,不用預設選項,點選下一步。

5.下一個頁面能幫你建立一個應用桌面圖示。

      你能夠定制一個圖示,用幾種方法和工具生成一個适合所有螢幕密度的圖示。在你釋出你的應用之前,

       你應用要確定你的圖示是遵循規範中定義的圖示規格。

    點選下一步。

6.現在你能選擇一個activity模闆,做為你建構的應用的開始頁。

   對于這個項目,選擇blackactivity,點選下一步。

7.其它的activity資訊使用預設狀态,點選完成。

你能使用一些預設的檔案,設定你的項目,就可以開始你的項目了。

使用指令行工具建立一個項目

如果你不使用帶有adt插件的eclipse ide建立項目,你也可以使用sdk指令行登陸你的項目:

1.改變目錄進入android sdk's /tools/路徑

2.執行:android list targets

   它将打列出你下載下傳的sdk可用 android平台版本。找到你要編譯的平台版本。記下目标id。

    我們推薦你盡可能的選擇最高版本。你能建構你的app支援的最低版本,但是設定建構目标到最新

   版本,能優化你的app在最新的裝置上。

   如果你沒有看到任何目标清單,你需要使用你安裝的android sdk管理工具。

3.執行:android create project --target &lt;target-id&gt; --name myfirstapp \

替換&lt;target-id&gt;從這個清單中選擇的id(從之前的步驟)和替換&lt;path-to-workspace&gt;用你

想儲存你項目的位置。

你的android項目現在使用一些預設配置設定完成。

tip:添加platform-tools作為tools/目錄放到你的path環境變量中。

                                                                                                                  2013-10-29 21:12

繼續閱讀