Presentation is loading. Please wait.

Presentation is loading. Please wait.

Android 專案建立、編譯與執行.

Similar presentations


Presentation on theme: "Android 專案建立、編譯與執行."— Presentation transcript:

1 Android 專案建立、編譯與執行

2 開啟Android App專案 [File]→[New]→[Project]

3 開啟Android App專案 Enter the app name.
Enter the SDK for building the project Minimum Required SDK, setting to API 8 is more general

4 開啟Android App專案 Configure Launcher Icon

5 開啟Android App專案 Create Activity

6 開啟Android App專案 New Activity

7 開啟Android App專案 Install Dependencies

8 開啟Android App專案 Finish and create an Android App project

9 執行第一個Android App Right Click

10 執行第一個Android App 可能會有的問題 為什麼有這個錯誤??
src/com/example/myfirstandroidapp/MainActiv ity.java發生了Error:r cannot be resolved to a variable 為什麼有這個錯誤?? R.java 在新增 Android 專案時正常情況會自動產 生 ,其功能是定義 Android 所使用到的任何資源。 但在某些作業環境時,此檔案在新增專案時不會產 生,故會發生此錯誤。

11 執行第一個Android App 解決方法 將[Project]中的[Build Automatically]關掉
進行[Project]→[Clean]動作,之後將”Start a build immediately”的勾選消除。 進行[Project]→[Build Project]動作,R.java應該就 會產生在gen裡面,錯誤得以解決。 若還是無法解決的話,請到專案所在的資料夾中, 將gen資料夾刪掉然後在次進行上面的步驟。 (R.java會生成到此資料夾中,這樣做是為了接下來 重新編譯時,系統會偵測到gen資料夾不見了,並 把gen資料夾中的內容補回來)

12 執行方式一 Android Virtual Device(AVD)

13 執行方式一 Android Virtual Device(AVD)

14 執行方式一 Android Virtual Device(AVD)
The AVD’s OS, you can choose all the level that you’ve installed from Android SDK manager. If you want to run OpenGL ES programs using emulator, you should add a property.

15 執行方式一 Android Virtual Device(AVD)
Choose “GPU emulation”

16 執行方式一 Android Virtual Device(AVD)
GPU Emulation Set the Value to “yes”

17 執行方式一 Android Virtual Device(AVD)
The Android Simulator is running now. ( need to wait 3-5 minute for launching )

18 執行方式一 Android Virtual Device(AVD)
After launching, here is your first app.

19 執行方式二 Real Android Phone
Connect your Android phone with USB Please ensure that the USB driver is properly installed, or the connection may not be detected. [Run]→[Run Configurations]→[Target] Select “Always prompt to pick device”, and click “Run” You can choose a running Android device, and run the program on your Android Phone.

20 程式說明 – MainActivity.java
package 名稱 package com.example.myfirstandroidapp; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.MenuItem; import android.support.v4.app.NavUtils; public class MainActivity extends Activity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; Imported librarys 覆寫 base class的method

21 程式說明– MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } onCreate: 每個 Activity 類別初始化時都會去呼叫的方法。 Bundle : 處理記憶體相關事宜之元素的型別 savedInstanceState: 負責處理記憶體相關事宜 執行 Activity 類別中 onCreate 方法的內容 將顯示元素(R.layout.activity_main)轉換顯示到螢幕上


Download ppt "Android 專案建立、編譯與執行."

Similar presentations


Ads by Google