Writing Android applications

Introduction

Android is a Linux-based operating system originally built by a company that Google bought in 2005.

Applications can either be compiled as native applications (compiled into bytecode by the Java compiler as an Android package .apk, which the virtual machine (Dalvik Virtual Machine) converts into a Dalvik Executables (.dex) run by the DVM), or as non-native applications (web applications that run through the WebView control).

Although Java is a popular language to write Android applications, other languages such as Basic or Python can be used and compiled into bytecode. Note that it's possible to bypass the DVM and write native applications in C++ and the Android NDK, although the applications may have problems on certain devices that may use different hardware, such as the upcoming Intel-based Android devices.

The whole Android stack includes

Writing apps with Basic4Android

Basic4Android, a.k.a. B4A, is a language very similar to VisualBasic that can be compiled into bytecode by the Java compiler.

Setup

  1. Install Java SE Development Kit 7
  2. Install the Android SDK for your platform (Use a directory name with no space in it): Default options are...
    1. Tools > Android SDK Tools
    2. Android 4.0.3 (API 15) > (all options)
    3. Extras > Google USB Driver
  3. Basic4android requires .Net Framework 2.0 or above. Download if necessary
  4. Install Basic4android, run the IDE, and choose Tools > Configure Paths to tell B4A where to find javac and android.jar

Hello, world!

How to install applications

To install applications, there are three options:

Installing the USB driver

That's the ideal solution, but not all devices support USB debugging, a.k.a. Android Debug Bridge (ADB).

Google provides drivers for the following devices: ADP1 / T-Mobile G1, ADP2 / Google Ion / T-Mobile myTouch 3G, Verizon Droid, Nexus One, and Nexus S. Also check this page for the links to major manufacturers. If you still can't find a USB debugging driver for your device, google for "<mydevice> android debug bridge adb driver". Not all devices implement the USB Android ADB interfaces.

Provided you did find the device's ADB USB driver...

  1. Use a USB cable to connect the device to the PC where B4A is installed
  2. As explained here and here, on the device, go to Settings > Applications > Development and enable USB debugging. This runs the adb daemon on the device which communicates with adb.exe on the desktop

    Turning on USB debugging adds an "Other Device" item in Windows' Device Manager. Right-click on it > Properties > Update Driver, and point to where you unzipped the ADB USB driver. You should now have an Android Phone > Android Composite ADB Interface

    Important: Some devices might require editing "%USERPROFILE%\.android\adb_usb.ini"
     
  3. Launch the B4A IDE, and build an "Hello, world!" application thusly:
    1. Edit the Activity_Create event:

      Log("Hello world!")
      Msgbox("Hello world?", "First program")
       
    2. Press F5, name the package "anywheresoftware.b4a.helloworld", and use "My Label" (the application name that the user will see)
    3. "No device found", OK, "Tools - Restart ADB Server"
  4. You should now see the application running in the emulator.

Connecting your device to the IDE

The way it works:

  1. The device and Windows are connected through the USB driver
  2. B4A connects to Android SDK's ADB daemon running on the PC to upload the application to the device. You can also connect manually using the command-line adb.exe provided by the SDK
  3. The daemon sends the APK file to the device, and the application is ran
  4. The file is saved in the ???? directory

Installing the B4A-Bridge

B4A-Bridge a new way to connect to your device

Anywhere Software Introduces New Tool to Enable Faster, Universal Testing of Android Applications

Create an AVD (emulator)

  1. Launch B4A, and choose Tools > Run AVD Manager
  2. In the Android SDK Manager, choose Tools > Manage AVDs or click on the New button (which displays the "Create new Android Virtual Device" and requires to choose a Target (Android 4.0.3 or Google API level 15) and an SD card), followed by Start. Wait for several minutes until you see the final screen (with the Google search toolbar, the phone icons, etc.)
  3. Once the AVD is up and running, go back to the B4A IDE and save the file on disk
  4. Edit the Activity_Create event thusly:

    Log("Hello world!")
    Msgbox("Hello world?", "First program")
     
  5. Press F5, name the package "anywheresoftware.b4a.helloworld", and use "My Label" (the application name that the user will see)
  6. You should now see the application running in the emulator.

Q&A

Is it possible to only compile/build without uploading to the device?
When/why should we sign applications?

What is the difference between "Compile & Run" and "Compile (without signing)"?

When should I run Tools > Restart ADB Server?
Does B4A upload an APK file or a DEX file?

I guess it's an APK that is then compiled and ran on the fly by the DVM.

Where does B4A/ADB upload APK files on the device?

Click on the 4x4 icon: The app should be somewhere on the screen.

Does the ADB daemon run on the PC or on the device?

"adb can connect a device to the desktop by two different means, Wi-Fi and USB. In both cases for adb to recognise the device Settings -> Applications -> Development -> USB debugging must be checked. This runs the adb daemon on the device which communicates with adb on the desktop."

http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/6484-connecting-your-device-ide.html
When should I use "adb connect 192.168.0.10"?
What are the main, useful commands to run with adb.exe?

adb devices

Resources

Wireframing (GUI builders)

Balsamiq

https://mockupstogo.mybalsamiq.com/projects/android/grid

Pencil

Wireframe Sketcher

DroidDraw

Android GUI PSD

Android Mock Up

Android GUI Designer

Android GUI Prototyping tool

ADT plugin for the Eclipse IDE

http://developer.android.com/guide/developing/projects/projects-eclipse.html

SimpleUI

Basic4android

For iPhone/Mac

iPhone Mockup

Toolkit for Adobe Fireworks to build iPhone UI mockups

http://blog.metaspark.com/2009/02/fireworks-toolkit-for-creating-iphone-ui-mockups/

Keynotopia

iPhone Stencil Kit

iPhonePrototype

Agnostic GUI

iPlotz

MIT App Inventor

Resources