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
- A framework (Window Manager, Telephony Manager, etc.),
- The Android Runtime (DVM + Core Libraries), extra libraries written
in C/C++ (Media Framework, SQLite, libc, etc.), and finally,
- The Linux kernel.
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
- Install Java
SE Development Kit 7
- Install the Android
SDK for your platform (Use a directory name with no space in it): Default
options are...
- Tools > Android SDK Tools
- Android 4.0.3 (API 15) > (all options)
- Extras > Google USB Driver
- Basic4android requires .Net Framework 2.0 or above. Download
if necessary
- 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:
- Connecting to a real device in USB
debugging mode (recommended)
- Connecting to a real device with B4A-Bridge
(Ethernet or wifi/Bluetooth; required if device doesn't support USB debugging)
- Using the Android emulator (Android Virtual Device/AVD; very slow compared
to a real device)
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...
- Use a USB cable to connect the device to the PC where B4A is installed
- 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"
- Launch the B4A IDE, and build an "Hello, world!" application
thusly:
- Edit the Activity_Create event:
Log("Hello world!")
Msgbox("Hello
world?", "First program")
- Press F5, name the package "anywheresoftware.b4a.helloworld",
and use "My Label" (the application name that the user will
see)
- "No device found", OK, "Tools - Restart ADB Server"
- You should now see the application running in the emulator.
Connecting
your device to the IDE
The way it works:
- The device and Windows are connected through the USB driver
- 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
- The daemon sends the APK file to the device, and the application is
ran
- 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)
- Launch B4A, and choose Tools > Run AVD Manager
- 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.)
- Once the AVD is up and running, go back to the B4A IDE and save the
file on disk
- Edit the Activity_Create event thusly:
Log("Hello world!")
Msgbox("Hello
world?", "First program")
- Press F5, name the package "anywheresoftware.b4a.helloworld",
and use "My Label" (the application name that the user will see)
- 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
- http://droiddraw.org/
- Java
- Adequate
- "AnDroidDraw
is an Android application which integrates with DroidDraw to allow you to
download your GUIs from the DroidDraw application and preview your GUIs
on an Android device."
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
- http://andrdev.blogspot.de/2012/04/simpleui-v2.html
- "SimpleUI is a small library to generate out of the box usable
and good looking UIs for Android. It follows the model view controller principle
and you create a controller which can generate a working connected view
for your model"
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