Skip to content

Instantly share code, notes, and snippets.

@bellbind
Created January 26, 2011 08:40
Show Gist options
  • Save bellbind/796429 to your computer and use it in GitHub Desktop.
Save bellbind/796429 to your computer and use it in GitHub Desktop.
[doc][android] How to use Android SDK on Windows with cygwin

How to use Android SDK (on Windows with cygwin)

Requires

Install

  • Install cygwin
  • Install JDK6 x86
  • Install Android SDK: use all-in-one exe installer
    • At least select latest API version
  • Extract apache-ant zip

Make AVD emulator devices

On android GUI

  • Select "Virtual devices"
  • Push "New..." button
  • Put entiries the push "Create AVD" e.g.
    • "Name" as "android2.3-camera"
    • "Target" as "Android 2.3 - API Level 9"
    • SD Card "Size" as "32" "MiB"
    • Skin "Built-in" as "WVGA854"
    • Push Hardware "New..." then select "Camera support" and push "OK" then change value as "yes"

Run AVD

On GUI

  • select "android2.3-camera" and press "Start.."

On CUI:

emulator -avd android2.3-camera

avd names will be listed by android list avd command

Create Project

run adnroid command as:

android create project -t android-9  \
  -p HelloWorld -k net.bellbind.helloworld -a HelloActivity
  • -t or --target: target api level (listed by android list target command)
  • -p or --path: created project path
  • -k or --package: project package name (at least 3 levels name required)
  • -a or --activity: init point Activity class name

Debug build and play on emulator

(at first, emulator launched):

ant debug
ant install

then the package appeared on emulator app list.

To remove from app list

ant uninstall

Release signed apk

Use JDK's keytool for creating a sign key. The key is common for all apk projects. e.g.:

mkdir key
cd key
keytool -genkey -v -keyalg RSA -keysize 2048 -validity 365 \
  -keystore apk-release-key.keystore -storepass forstorepass \
  -alias forapk -keypass foraliaspass

Input info: name, country (e.g. JP) and more

then files are

  • ./key/apk-release-key.keystore
  • ./HelloWorld/build.xml
  • ./HelloWorld/build.properties
  • ...

Add its info to "build.properties"

key.store=../key/apk-release-key.keystore
key.alias=forapk
# option
key.store.password=forstorepass
key.alias.password=foraliaspass

Build release apk:

ant release

then "bin/HelloActivity-release.apk" will be generated

APPENDIX: Setup for cygwin

Add commands to ~/.bashrc

function aapt {
    TOP=/cygdrive/c/Program\ Files\ \(x86\)/Android/android-sdk-windows
    "$TOP"/platform-tools/aapt.exe "$@"
}
function adb {
    TOP=/cygdrive/c/Program\ Files\ \(x86\)/Android/android-sdk-windows
    "$TOP"/platform-tools/aapt.exe "$@"
}
function aidl {
    TOP=/cygdrive/c/Program\ Files\ \(x86\)/Android/android-sdk-windows
    "$TOP"/platform-tools/aapt.exe "$@"
}
function dx {
    TOP=/cygdrive/c/Program\ Files\ \(x86\)/Android/android-sdk-windows
    "$TOP"/platform-tools/dx.bat "$@"
}
function android {
    TOP=/cygdrive/c/Program\ Files\ \(x86\)/Android/android-sdk-windows
    "$TOP"/tools/android.bat "$@"
}
function emulator {
    TOP=/cygdrive/c/Program\ Files\ \(x86\)/Android/android-sdk-windows
    "$TOP"/tools/emulator.exe "$@"
}
function hierarchyviewer {
    TOP=/cygdrive/c/Program\ Files\ \(x86\)/Android/android-sdk-windows
    "$TOP"/tools/hierarchyviewer.bat "$@"
}
function layoutopt {
    TOP=/cygdrive/c/Program\ Files\ \(x86\)/Android/android-sdk-windows
    "$TOP"/tools/layoutopt.bat "$@"
}
function mksdcard {
    TOP=/cygdrive/c/Program\ Files\ \(x86\)/Android/android-sdk-windows
    "$TOP"/tools/mksdcard.exe "$@"
}
function monkeyrunner {
    TOP=/cygdrive/c/Program\ Files\ \(x86\)/Android/android-sdk-windows
    "$TOP"/tools/monkeyrunner.bat "$@"
}
function retrace {
    TOP=/cygdrive/c/Program\ Files\ \(x86\)/Android/android-sdk-windows
    "$TOP"/tools/proguard/bin/retrace.bat "$@"
}
function traceview {
    TOP=/cygdrive/c/Program\ Files\ \(x86\)/Android/android-sdk-windows
    "$TOP"/tools/traceview.bat "$@"
}
function zipalign {
    TOP=/cygdrive/c/Program\ Files\ \(x86\)/Android/android-sdk-windows
    "$TOP"/tools/zipalign.exe "$@"
}
function ant {
    export JAVA_HOME=c:/Program\ Files\ \(x86\)/Java/jdk1.6.0_23/
    TOP=/cygdrive/d/opt/apache-ant-1.8.2
    "$TOP"/bin/ant.bat "$@"
}

How to use Android NDK (on Windows with cygwin)

Requires

and Android SDK

Install

  • Install as Android SDK
  • Install cygwin with "make" and "gcc" packages at least
  • Extract android-ndk zip

Play with ndk-samples

  • copy samples/hello-jni to other dir)

  • edit "target" version in "default.properties" and "tests/default-properties"

  • run "android update project" command:

    cd hello-jni android update project -p . -s

  • build with two steps

    nkd-build ant debug

generated "bin/HelloJni-debug.apk" contains "lib/armeabi/libhello-jni.so".

to clean the project:

ant clean
ndk-build clean
rm -r libs/ obj/

Brief guide for ndk project

  • prepare "jni" directory and "Android.mk"
  • set module name as "LOCAL_MODULE"
  • list up ".c" files as "LOCAL_SRC_FILES"
  • set native methods on java source codes
  • call System.loadLibrary(MODULE_NAME) at somewhere before using native methods

using samples and docs setting is easy.

darvik jni is same interface of jdk jni. jdk's javah generated header files is also available.

Brief guide for native activity (java-less) project

see samples/native-activity

  • Addtional descriptions required in "AndroidManifest.xml"
  • different "Android.mk" and "Application.mk" required
  • entry point is "android_main()" function

Hints for building OpenSource libraries

see: $NDK_HOME/docs/STANDALONE-TOOLCHAIN.html

"androideabi" of "arm-linux-androideabi" is supported on newer libtool. "arm-eabi" for old one.

current cygwin packaged libtool is old not-supported one. see: "timestamp" text in /usr/share/libtool/config/config.guess and config.sub "androideabi" is supported after "2010-05-20" version

for confgure script options, usually "--host" is prefix for gcc commands (e.g. arm-linux-androideabi-gcc). some configure script will pass with CFLAGS=-nostdlib LIBS=-lc

e.g.

export PATH=$TOOLCHAIN/bin:"$PATH"
./configure --host=arm-linux-androideabi \
   CPPFLAGS=-I$TOOLCHAIN/sysroot/usr/include \
   LDFLAGS=-L$TOOLCHAIN/sysroot/usr/lib \
   CFLAGS=-nostdlib LIBS=-lc

APPENDIX: Setup for cygwin

Add commands to ~/.bashrc

function ndk-build {
    TOP=/cygdrive/d/opt/android-ndk-r5
    "$TOP"/ndk-build "$@"
}
function ndk-gdb {
    TOP=/cygdrive/d/opt/android-ndk-r5
    "$TOP"/ndk-gdb "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment