docs:android:starting_an_android_project

starting an android project

  1. obtain the android sdk, install it on your computer
    • you probably want to add the tools subdirectory to your path as well (such as <path to sdk>/android-sdk-mac_86/tools)
  2. open your terminal
  3. run 'android list targets' to see available target id's for the various android platform versions
  4. run this to create a new project:
    android create project \
    --target 4 \
    --name MyProject \
    --path /path/to/MyProject \
    --activity MyProject \
    --package com.example.myproject
  1. modify source code as desired
  2. build the app in debug mode: ant debug
    • note that the first attempt of 'ant debug' failed saying the debug certificate was expired; online search said to delete ~/.android/debug.keystore; the build then succeeded
    • if you get the error taskdef class com.android.ant.SetupTask cannot be found, you have probably changed the install location of the android sdk
      • update the local.properties file in the root of your project to have the correct path to the android sdk

R.java is necessary for the app to run, and is referenced in some tutorials. This file may not exist at first, but will be created the first time you build the project. It may be possible to create the file with the right ant target but I couldn't get it to work with recent sdk's that way.

  1. enable usb debugging on your phone
    • press Menu → Settings → Applications
    • check Unknown sources, Allow installation of non-Market applications
    • select Development
    • check to enable USB debugging
  2. connect your device to your computer with the supplied charging cable (disconnect the power plug from the cord first, and you'll have a usb connector)
  3. install the package:
    adb install -r /path/to/MyProject/bin/MyProject-debug.apk
  4. once you are working, building, installing, etc… you probably want to automate:
    • build.sh
      #!/bin/sh
       
      ant debug \
      && adb install -r /path/to/MyProject/bin/MyProject-debug.apk
    • debug.sh
      #!/bin/sh
       
      adb logcat -v time MyProject:V *:S
    • then run
      ./build.sh && ./debug.sh
      
      - or -
      
      (start a full or custom adb logcat session, keep it running by pressing ctrl-z)
      ./build.sh && fg
      (the fg will bring the logcat session back up)
      
      # if you want to also see ActivityManager messages, you can add this filter:
      # && adb logcat -v time ActivityManager:I MyProject:V *:S
  1. create an android virtual device to test your programs on
    • run android with no switches to get the Android SDK and AVD Manager GUI
  2. launch your android virtual device (AVD) from the GUI
  3. install your app on the virtual device
    • from the SDK tools directory, run 'adb install <path_to_your_bin>.apk' (such as adb install /path/to/MyProject/bin/MyProject-debug.apk)
    • note that the above didn't work for me at first. I had to identify the running emulators with 'adb devices', then use this command to install the package:
      adb -s emulator-5554 install /path/to/MyProject/bin/MyProject-debug.apk
  • docs/android/starting_an_android_project.txt
  • Last modified: 2012/02/14 20:49
  • by billh