Skip to content

Instantly share code, notes, and snippets.

@poutyface
Created June 1, 2011 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poutyface/1001817 to your computer and use it in GitHub Desktop.
Save poutyface/1001817 to your computer and use it in GitHub Desktop.
Android
AVDの作成
=========
android create avd -n <仮想デバイス名> -t <ターゲットID> [-<option> <value>] ...
example:
android create avd -n avd_t8 -t 8
AVDの削除
========
android delete avd -n <仮想デバイス名>
AVDターゲット一覧
===============
android list targets
AVD一覧
=======
android list avds
エミュレータの起動
================
emulator -avd <仮想デバイス名> [-<option> [<value>]] ... [-<qemu args>]
emulator @<仮想デバイス名> [-<option> [<value>]] ... [-<qemu args>]
example:
emulator -kernel mydroid/kernel/common/arch/arm/boot/zImage -shell -show-kernel -avd my_avd -qemu -cpu cortex-a8
cat /proc/cpuinfo
adb
====
adb push [ローカルファイル] [デバイスファイル]
adb pull [デバイスファイル] [ローカルファイル] 
adb shell [command]
Application
==============
SDKとAntが必要
http://developer.android.com/resources/tutorials/hello-world.html
android create project \
--package com.example.helloandroid \
--activity HelloAndroid \
--target 15 \
--path ./HelloAndroid
android create --help
–name プロジェクトの名称
–target APIレベル
–path プロジェクトを作成するディレクトリ
–activity アクティビティを継承したクラス(アプリ実行後最初に実行するクラス)
–package アプリのパッケージ名
├── AndroidManifest.xml
├── bin
├── build.properties
├── build.xml
├── default.properties
├── libs
├── local.properties
├── proguard.cfg
├── res
│   ├── drawable-hdpi
│   │   └── icon.png
│   ├── drawable-ldpi
│   │   └── icon.png
│   ├── drawable-mdpi
│   │   └── icon.png
│   ├── layout
│   │   └── main.xml
│   └── values
│   └── strings.xml
└── src
└── com
└── example
└── helloandroid
└── HelloAndroid.java
ビルド
--------
ant debug
.
├── AndroidManifest.xml
├── bin
│   ├── HelloAndroid-debug-unaligned.apk
│   ├── HelloAndroid-debug.apk
│   ├── HelloAndroid.ap_
│   ├── classes
│   │   └── com
│   │   └── example
│   │   └── helloandroid
│   │   ├── HelloAndroid.class
│   │   ├── R$attr.class
│   │   ├── R$drawable.class
│   │   ├── R$layout.class
│   │   ├── R$string.class
│   │   └── R.class
│   └── classes.dex
├── build.properties
├── build.xml
├── default.properties
├── gen
│   └── com
│   └── example
│   └── helloandroid
│   └── R.java
├── libs
├── local.properties
├── proguard.cfg
├── res
│   ├── drawable-hdpi
│   │   └── icon.png
│   ├── drawable-ldpi
│   │   └── icon.png
│   ├── drawable-mdpi
│   │   └── icon.png
│   ├── layout
│   │   └── main.xml
│   └── values
│   └── strings.xml
└── src
└── com
└── example
└── helloandroid
└── HelloAndroid.java
インストール
------------
adb install アプリケーション名
adb install -r bin/HelloAndroid-debug.apk
adb uninstall パッケージ名
adb uninstall com.example.helloandroid
Native application with JNI
============================
src/com/example/helloandroid/HelloAndroid.java
----------------------------------------------
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroid extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// call native program
welcome();
}
// Add for native program
public native void welcome();
static{
System.loadLibrary("welcome");
}
}
jni ディレクトリを作成
---------------------
mkdir jni
jni/welcom.c
-------------
void Java_+ パッケージ名 + Javaのクラス名 + メソッド名(JNIEnv* env, jobject this)
#include <jni.h>
#include <android/log.h>
void Java_com_example_helloandroid_HelloAndroid_welcome(JNIEnv* env, jobject this)
{
__android_log_print(ANDROID_LOG_INFO, "NATIVE", "welcome!\n");
}
jni/Android.mk
----------------
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := welcome
LOCAL_SRC_FILES := welcome.c
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
jni/Application.mk
-------------------
APP_PROJECT_PATH := $(call my-dir)/../
APP_MODULES := welcome
build and install
------------------
./ndk-build -B
./ant debug
./adb install -r bin/HelloAndroid-debug.apk
Logのみかた
-------------
adb logcat -s [LOG_TAG]
adb logcat -s NATIVE
Console Application
=====================
create jni/Android.mk
create jni/hello.c
That's it!
$ ndk-build -B
$ adb push libs/armeabi/hello /data/local/tmp
$ adb shell
$ cd /data/local/tmp
$ chmod 755 hello
$ ./hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment