Android 應用程式 開發概論 中華民國九十九年十二月二日星期四
開發工具 使用 Android SDK 建立應用程式 使用 Java 語言 Java Platform, Standard Edition (Java SE)
系統需求 項目版本要求說明 作業系統 Windows XP/Vista MacOS X 10.4.8+ Ubuntu (Drapper) 開發套件 JDK + Android SDK 選擇適用於目標平台的 SDK 版本 IDE 工具 Eclipse + ADT 至少為 Eclipse 3.4 (Ganymede) 或 Eclipse 3.5 (Galileo) 下載 Eclipse 時選擇 Java Developer 或 Java EE Developers 的版本 其它 Apache Ant 在 Linux 和 MacOS 則使用 Apache Ant 1.6.5+; 在 Windows 則使用 1.7+ 版本
在 Linux 安裝開發工具 選用的發行版本為 Ubuntu 9.04, 安裝 JDK 6 Android SDK Eclipse 及 ADT 需要的項目 : Java SE Development Kit (JDK) 6 Android SDK Eclipse Galileo (for Java Developer) Android Development Tools (ADT)
Step 1: 安裝 JDK 自套件庫安裝 sunjava6-jdk
Step 2: 安裝 Android SDK 自 developer.android.com 下載 Android SDK, 解開後複製到 /opt/android 目錄內 執行 SDK 裡的 tools/android 由線上取得 SDK 的完整檔案
接著編輯 ~/.bashrc, 並在 PATH 變數加入 SDK 的 tools 路徑 # Add Android SDK to PATH if [ -d "/opt/android/android-sdk-linux" ] ; then PATH="$PATH:/opt/android/android-sdk-linux/tools" fi
Step 3: 安裝 Eclipse 自 www.eclipse.org 下載 Eclipse Galileo (for Java Developer), 解開後安裝到 /opt/eclipse 目錄
Step 4: 安裝 ADT 方法一 : 自 developer.android.com 下載 ADT 的壓縮檔進行安裝 方法二 : 點擊 Eclipse 的選單 Help Install New Software 加入 https://dlssl.google.com/android/eclipse/ 這個安裝來源
Step 5: 設定 ADT 的 Android SDK 路 徑 重新啟動 Eclipse, 由選單 Windows Preferences 設定 Android SDK 的路徑
Step 6:Setting encoding to UTF-8
Step 7: 建立 AVD Eclipse 的選單 Windows Android SDK and AVD Manager
在 Windows 安裝開發工具 選用的系統為 Windows XP 及 Vista, 安裝 JDK 6 Android SDK Eclipse 及 ADT 需要的項目 : Java SE Development Kit (JDK) 6 Android SDK Eclipse Galileo (for Java Developer) Android Development Tools (ADT)
由於繁體中文的 Windows XP/Vista 預設仍採用 MS950 編碼 (Big5), 更改為 UTF-8 尤其重要
Example 1: HelloAndroid
Android 裡每一個應用程式都擁有各自獨立的 Package name 慣用的命名規則 : 公司的 reverse url. 部門. 團隊. 專案名稱. 子計畫名稱
Setting up the Manifest
Activity: Do Something!
R.java
Dalvik Debug Monitor Server (DDMS)
List of Sample Applications Sample Apps API Demos Bluetooth Chat Contact Manager Note Pad Snake Desciption A variety of small applications that demonstrate an extensive collection of framework topics. An application for two-way text messaging over Bluetooth. An application that demonstrates how to query the system contacts provider using the ContactsContract API, as well as insert contacts into a specific account. An application for saving notes. Similar (but not identical) to the Notepad tutorial. An implementation of the classic game "Snake." http://developer.android.com/resources/samples/index.html
What is NDK? The Android NDK is a toolset that lets you embed components that make use of native code in your Android applications. Android applications run in the Dalvik virtual machine. The NDK allows you to implement parts of your applications using native-code languages such as C and C++. This release of the NDK supports the ARMv5TE machine instruction set and provides stable headers for libc (the C library), libm (the Math library), OpenGL ES (3D graphics library), the JNI interface, etc. The NDK does not enable you to develop native-only applications. From: http://developer.android.com/sdk/ndk/index.html#overview
The NDK includes: libc (C library) headers libm (math library) headers JNI interface headers libz (Zlib compression) headers liblog (Android logging) header OpenGL ES 1.1 and OpenGL ES 2.0 (3D graphics libraries) headers libjnigraphics (Pixel buffer access) header (for Android 2.2 and above). A Minimal set of headers for C++ support
系統需求 項目版本要求說明 作業系統 Windows XP/Vista MacOS X 10.4.8+ Ubuntu (Drapper) 開發套件 JDK + Android SDK 至少具備 Android 1.5 SDK 或較新 的版本, 且必須完整安裝 其它 GNU Make 3.81+ Cygwin 在 Linux 必須安裝 GNU Make; 在 Windows 必須搭配使用 Cygwin
在 Linux 安裝 NDK 選用的發行版本為 Ubuntu 9.04, 安裝 JDK 6 Android SDK
NDK r4b (or NDK r4) Google 在 2010 年 6 月發表 Android NDK, Revision 4b 假設將 android-ndk-r4b-linux-x86.zip 解壓縮至 /opt/android 目錄內 設定 PATH 變數 使用 ndk-build 腳本編譯
編輯 ~/.bashrc, 並在 PATH 變數加入 NDK 的路徑 # Add Android NDK to PATH if [ -d "/opt/android/android-ndk-r4b" ] ; then PATH="$PATH:/opt/android/android-ndk-r4b" fi
android:minsdkversion To ensure compatibility, an application using a native library produced with the NDK must declare a <uses-sdk> element in its manifest file, with an android:minsdkversion attribute value of "3" or higher.
If you use this NDK to create a native library that uses the API to access Android Bitmap pixel buffers, the application containing the library can be deployed only to devices running Android 2.2 (API level 8) or higher. To ensure compatibility, make sure that your application declares <uses-sdk android:minsdkversion="8" /> attribute value in its manifest
OpenGL ES APIs OpenGL ES Version Used Compatible Android Platform(s) Required uses-sdk Attribute OpenGL ES 1.1 Android 1.6 and higher android:minsdkversion="4" OpenGL ES 2.0 Android 2.0 and higher android:minsdkversion="5"
Build Application with NDK 1. 將 native sources 放在 <project>/jni 路徑下 2. 建立 <project>/jni/android.mk 描述如何編譯 必要時也需要建立 <project>/jni/application.mk 3. 在路徑 <project> 執行 ndk-build 編譯 native code 4. 使用 SDK 編譯, 生成最終的 APK 檔
Example: Hello JNI A simple application that loads a string from a native method implemented in a shared library and then displays it in the application UI.
HelloJni.java
hello-jni.c
Android.mk
使用 ndk-build 編譯後, 生成 libs/armeabi/libhellojni.so
Example: HelloNeon A simple application that shows how to use the cpufeatures library to check CPU capabilities at runtime, then use NEON intrinsics if supported by the CPU. Specifically, the application implements two versions of a tiny benchmark for a FIR filter loop, a C version and a NEON-optimized version for devices that support it.
HelloNeon.java
helloneon.c
Android.mk
Application.mk
Thank you~~~