Androidアプリでも作ってみるメモ.
android SDK落としてきてJDKが動く環境は既にあるっていうことで。
やることはおおむね以下のとおりだよーん。
1) android用プロジェクトの作成
$ android create project なんたらかんたら
2) ソース書く
3) ant
とりあえずはant debug。
$ ant debug
4) apkファイルのエミュレータへのインストール
$ adb install なんたらかんたら
では早速。
$ android list target
ってやると
android list target
Available Android targets:
id: 1 or "android-3"
Name: Android 1.5
Type: Platform
API level: 3
Revision: 4
Skins: QVGA-P, QVGA-L, HVGA-L, HVGA (default), HVGA-P
id: 2 or "Google Inc.:Google APIs:3"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 3
Description: Android + Google APIs
Based on Android 1.5 (API level 3)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: QVGA-P, HVGA (default), HVGA-L, QVGA-L, HVGA-P
id: 3 or "android-4"
Name: Android 1.6
Type: Platform
API level: 4
Revision: 3
Skins: WVGA854, WVGA800 (default), QVGA, HVGA
id: 4 or "Google Inc.:Google APIs:4"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 2
Description: Android + Google APIs
Based on Android 1.6 (API level 4)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WVGA854, HVGA, QVGA, WVGA800 (default)
id: 5 or "SHARP Corporation:JN-DK01:4"
Name: JN-DK01
Type: Add-On
Vendor: SHARP Corporation
Revision: 1
Description: SHARP JN-DK01 Add-on
Based on Android 1.6 (API level 4)
Libraries:
* jp.co.sharp.android.hardware (hardware.jar)
* jp.co.sharp.android.io.obex (obex.jar)
Skins: WVGA854, HVGA, QVGA, WVGA800, JNDK01 (default)
Adds USB support for devices (Vendor: 0x04DD)
id: 6 or "android-7"
Name: Android 2.1-update1
Type: Platform
API level: 7
Revision: 2
Skins: WQVGA432, WVGA854, WVGA800 (default), WQVGA400, QVGA, HVGA
id: 7 or "Google Inc.:Google APIs:7"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 1
Description: Android + Google APIs
Based on Android 2.1-update1 (API level 7)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WQVGA400, WVGA854, HVGA, WQVGA432, QVGA, WVGA800 (default)
id: 8 or "android-8"
Name: Android 2.2
Type: Platform
API level: 8
Revision: 2
Skins: WQVGA432, WVGA854, WVGA800 (default), WQVGA400, QVGA, HVGA
id: 9 or "Google Inc.:Google APIs:8"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 2
Description: Android + Google APIs
Based on Android 2.2 (API level 8)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WQVGA400, WVGA854, HVGA, WQVGA432, QVGA, WVGA800 (default)
id: 10 or "Samsung Electronics Co., Ltd.:GALAXY Tab Addon:8"
Name: GALAXY Tab Addon
Type: Add-On
Vendor: Samsung Electronics Co., Ltd.
Revision: 1
Based on Android 2.2 (API level 8)
Skins: WQVGA400, WVGA854, GALAXY Tab (default), HVGA, WQVGA432, QVGA, WVGA800
id: 11 or "android-9"
Name: Android 2.3.1
Type: Platform
API level: 9
Revision: 2
Skins: WQVGA432, WVGA854, WVGA800 (default), WQVGA400, QVGA, HVGA
id: 12 or "Google Inc.:Google APIs:9"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 2
Description: Android + Google APIs
Based on Android 2.3.1 (API level 9)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WQVGA400, WVGA854, HVGA, WQVGA432, QVGA, WVGA800 (default)
id: 13 or "Sony Ericsson Mobile Communications AB:EDK:9"
Name: EDK
Type: Add-On
Vendor: Sony Ericsson Mobile Communications AB
Revision: 1
Description: XPERIA Device
Based on Android 2.3.1 (API level 9)
Libraries:
* com.sonyericsson.eventstream_1 (com.sonyericsson.eventstream_1.jar)
Library for Android Market filtering
Skins: WQVGA400, WVGA854, Xperia (default), HVGA, WQVGA432, QVGA, WVGA800
id: 14 or "android-10"
Name: Android 2.3.3
Type: Platform
API level: 10
Revision: 1
Skins: WQVGA432, WVGA854, WVGA800 (default), WQVGA400, QVGA, HVGA
id: 15 or "Google Inc.:Google APIs:10"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 1
Description: Android + Google APIs
Based on Android 2.3.3 (API level 10)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WQVGA400, WVGA854, HVGA, WQVGA432, QVGA, WVGA800 (default)
id: 16 or "android-11"
Name: Android 3.0
Type: Platform
API level: 11
Revision: 1
Skins: WXGA (default)
id: 17 or "Google Inc.:Google APIs:11"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 1
Description: Android + Google APIs
Based on Android 3.0 (API level 11)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WXGA (default)
ってなってる.
さて、このlistの中からターゲットとなる
id: 5 or "SHARP Corporation:JN-DK01:4"
を何となく選び、android用プロジェクトを作成するよ.
プロジェクト作成のためにはandroidコマンドを叩いちゃう.
android --helpでチェック.
Valid actions are composed of a verb and an optional direct object:
- list : Lists existing targets or virtual devices.
- list avd : Lists existing Android Virtual Devices.
- list target : Lists existing targets.
- create avd : Creates a new Android Virtual Device.
- move avd : Moves or renames an Android Virtual Device.
- delete avd : Deletes an Android Virtual Device.
- update avd : Updates an Android Virtual Device to match the folders of a new SDK.
- create project : Creates a new Android project.
- update project : Updates an Android project (must already have an AndroidManifest.xml).
- create test-project : Creates a new Android project for a test package.
- update test-project : Updates the Android project for a test package (must already have an AndroidManifest.xml).
- create lib-project : Creates a new Android library project.
- update lib-project : Updates an Android library project (must already have an AndroidManifest.xml).
- update adb : Updates adb to support the USB devices declared in the SDK add-ons.
- update sdk : Updates the SDK by suggesting new platforms to install if available.
と出るんで、必要なのは"create project".
で、で、
のりで"android --help create project"と叩いてみる.
create projectに絞られたhelpが表示された.
$ android --help create project
Usage:
android [global options] create project [action options]
Global options:
-v --verbose Verbose mode: errors, warnings and informational messages are printed.
-h --help Help on a specific command.
-s --silent Silent mode: only errors are printed out.
Action "create project":
Creates a new Android project.
Options:
-n --name Project name
-t --target Target ID of the new project [required]
-p --path The new project's directory [required]
-k --package Android package name for the application [required]
-a --activity Name of the default Activity that is created [required]
ん。おっけー。
ということで
$ android create project -n Ncha -t 5 -p /home/konno/work/t/ncha -k jp.co.qsdn.android -a Ncha
と入力してベーン!
その結果指定したディレクトリに色々できるよ!
Created directory /home/konno/work/t/ncha/src/jp/co/qsdn/android
Added file /home/konno/work/t/ncha/src/jp/co/qsdn/android/Ncha.java
Created directory /home/konno/work/t/ncha/res
Created directory /home/konno/work/t/ncha/bin
Created directory /home/konno/work/t/ncha/libs
Created directory /home/konno/work/t/ncha/res/values
Added file /home/konno/work/t/ncha/res/values/strings.xml
Created directory /home/konno/work/t/ncha/res/layout
Added file /home/konno/work/t/ncha/res/layout/main.xml
Added file /home/konno/work/t/ncha/AndroidManifest.xml
Added file /home/konno/work/t/ncha/build.xml
Added file /home/konno/work/t/ncha/proguard.cfg
と、こんな感じぃ.
プロジェクトのホームは
/home/konno/work/t/ncha
なので、
$ cd /home/konno/work/t/ncha
すると、カレントにbuild.xmlファイルがあるんで
$ ant help
Buildfile: /home/konno/work/t/ncha/build.xml
[setup] Android SDK Tools Revision 10
[setup] Project Target: JN-DK01
[setup] Vendor: SHARP Corporation
[setup] Platform Version: 1.6
[setup] API level: 4
[setup]
[setup] ------------------
[setup] Resolving library dependencies:
[setup] No library dependencies.
[setup]
[setup] ------------------
[setup]
[setup] WARNING: No minSdkVersion value set. Application will install on all Android versions.
[setup]
[setup] Importing rules file: tools/ant/main_rules.xml
help:
[echo] Android Ant Build. Available targets:
[echo] help: Displays this help.
[echo] clean: Removes output files created by other targets.
[echo] compile: Compiles project's .java files into .class files.
[echo] debug: Builds the application and signs it with a debug key.
[echo] release: Builds the application. The generated apk file must be
[echo] signed before it is published.
[echo] install: Installs/reinstalls the debug package onto a running
[echo] emulator or device.
[echo] If the application was previously installed, the
[echo] signatures must match.
[echo] uninstall: Uninstalls the application from a running emulator or
[echo] device.
BUILD SUCCESSFUL
Total time: 1 second
とすれば大体分かるはず.
とりあえずは、ant debugでapkファイルを作ってみっペ。
せっかくだからソースもちょっとだけいじるよ.
$ vi /home/konno/work/t/ncha/src/jp/co/qsdn/android/Ncha.java
として
package jp.co.qsdn.android;
import android.app.Activity;
import android.os.Bundle;
public class Ncha extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
を
package jp.co.qsdn.android;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Ncha extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
textView.setText("んちゃ!");
setContentView(textView);
}
}
と変更。
http://developer.android.com/reference/packages.html
に行けばいつものjavadocは見れると。
で、ant debug。
$ ant debug
Buildfile: /home/konno/work/t/ncha/build.xml
[setup] Android SDK Tools Revision 10
[setup] Project Target: JN-DK01
[setup] Vendor: SHARP Corporation
[setup] Platform Version: 1.6
[setup] API level: 4
[setup]
[setup] ------------------
[setup] Resolving library dependencies:
[setup] No library dependencies.
[setup]
[setup] ------------------
[setup]
[setup] WARNING: No minSdkVersion value set. Application will install on all Android versions.
[setup]
[setup] Importing rules file: tools/ant/main_rules.xml
-debug-obfuscation-check:
-set-debug-mode:
-compile-tested-if-test:
-pre-build:
-dirs:
[echo] Creating output directories if needed...
-aidl:
[echo] Compiling aidl files into Java classes...
-renderscript:
[echo] Compiling RenderScript files into Java classes and RenderScript bytecode...
-resource-src:
[echo] Generating R.java / Manifest.java from the resources...
-pre-compile:
compile:
[javac] /home/konno/android-sdk-linux_x86/tools/ant/main_rules.xml:384: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 2 source files to /home/konno/work/t/ncha/bin/classes
-post-compile:
-obfuscate:
-dex:
[echo] Converting compiled files and external libraries into /home/konno/work/t/ncha/bin/classes.dex...
-package-resources:
[echo] Packaging resources
[aapt] Creating full resource package...
-package-debug-sign:
[apkbuilder] Creating Ncha-debug-unaligned.apk and signing it with a debug key...
debug:
[echo] Running zip align on final apk...
[echo] Debug Package: /home/konno/work/t/ncha/bin/Ncha-debug.apk
BUILD SUCCESSFUL
Total time: 4 seconds
できたー。
したらエミュレータ動かすよ。
AVDは作っといてね。
$ emulator -avd JNDK01
あ、JNDK01は先に作っておいたAVDね。
で、で、いよいよ先に作ったNchaをインストールするよ。
インストールにはadbを使う。
apkファイルは/home/konno/work/t/ncha/bin/Ncha-debug.apkにあるので
$ adb install /home/konno/work/t/ncha/bin/Ncha-debug.apk
90 KB/s (4546 bytes in 0.049s)
pkg: /data/local/tmp/Ncha-debug.apk
Success
でインストール完了。
virtual端末に行って、メインメニューを出すと、あら不思議。
Nchaアプリがあるよ。
で、実行してみると、、、、んちゃ!
そんだけー
.
0 コメント:
コメントを投稿