Tips and Tricks

From CS 160 Fall 2010

Jump to: navigation, search

Contents


Android Quickstart

For Android Development, you'll need in this order:

A recent (1.6) Java development system (JDK) - there is a problem with Eclipse and jdk 1.6_u21 (b6). If you have this one, download the latest (b7 or greater). If not you should be fine.

Eclipse 3.4 or 3.5. There is a problem between the Android environment and Eclipse 3.6, so get one of the earlier ones. On Windows, you may need to add the JDK bin directory to your path before Eclipse will run.

Download the Android SDK tools. Save to a high-level directory, and run "SDK setup". You will want to install at least the Android 1.6 SDK and tools in order to be able to develop for the Archos 5. If you have a 64-bit version of Windows (XP, Vista or 7), you should select the usb driver and install it. Supposedly it just works on a Mac without a driver (not tested).

Install the ADT plugin for Eclipse. Follow the instructions there to point the ADT plugin at the Android SDK. Create a virtual device based on the 1.6 SDK to use as an emulator. There are tips on how to create an AVD for the Archos 5 here. You may want to include the keyboard instead of disabling it for certain projects, even though the Archos 5 doesn't have one, as it makes debugging easier (no keyboard in the profile means that you can't use your keyboard for testing).

Now try building one of the SDK examples. From the Eclipse Java perspective, click File→New→Project→Android→Android Project→Create Project from Existing Sample. You will need to check the 1.6 SDK box. If you're lucky, it may build right away. If not, check the build path in Project→Properties→Java Build Path→Order and Export. For some reason, it often starts with the Android SDK unchecked. Check it and try building again.

To run your code you need to define a run configuration. Select Run→Run Configurations→Android Application. Give your run configuration a name (e.g. the program to be run _Archos5). Go to the target tab and select "manual" so you can choose between emulator and device when you have an Archos connected. When you run an error-free program, the emulator will start automatically. Its not smart about screen size however, and may be too large for some monitors. If you have this problem, start the emulator instead using "SDK setup" program from the main Android SDK directory before you run a program. It will give you a dialog to set the size or scale. Setting the height to 8" works well on 768-pixel high monitors.

Mac Specific

You don't have to install the JDK, because Apple manages its own updates. As long as you have the machine updated, you should have the latest version of Java. Also make sure you download the correct version of Eclipse depending on your machine (32bit vs 64bit). Rest of the steps should work, the way they are.

To connect your device to your MAC (OSX): Earlier versions of Mac OS should recognize the device by default, however newer versions might not do so. Here is a fix to that: Assuming you have the android SDK installed, you need to follow the steps mentioned here: connect to archos 5

This should make your device visible to you.

Windows Specific

If you have a 32-bit version of windows, you can use Archos' driver to talk to the Archos. Download it here under "ADB for Android Developers". You'll have to copy the driver files by hand and create a "driver" subdirectory. Make sure that the .inf file doesnt get a .txt extension during download. Plug in the device and force windows to install from the directory where you put the driver when prompted. On Vista or Win7, you will need to go into device manager and do "update driver" on the Archos.

If you have 64-bit Windows, life is a little harder. Assuming you got through that, you are ready to plug in the Archos. Wait for a moment for Windows to look for a driver and fail, and either ask you (XP) or give up (Vista/Win7). For Vista/Win7 to device manager, find the Archos (probably under "other devices"), and do "update driver". Point it at the Android SDK/USB driver directory, click "Next", and see what happens (don't forget to breathe!). If all goes well, you will get a "driver installed successfully" message.

Go to a command prompt (i.e. windows cmd or cygwin), cd to the Android SDK/tools directory, and type ./adb devices. The ADB server should start, and detect and list the Archos device. If that works, try ./adb -d shell. You will now be "logged in" to a unix-like shell on the Archos. Congratulations! Go back to eclipse and try running your program again. It should prompt you for a machine (emulator or Archos) to run on.

Emulator Problems

If you're having problems with Eclipse losing it's connection to the emulator (which happens more often on certain 32-bit machines), this is one way to get the connection back. Restarting Eclipse doesn't always work. Restarting the Emulator is slow and it also doesn't always work.

First open the device view. Go to:

Window -> Show View -> Other... -> Android -> Devices

If the emulator is running, it should show up on the list with an "Online" status.

If the emulator says "Offline" or doesn't appear at all, but it is running in the background, this is how to fix it:

There's an arrow next to the "Screen Capture" icon on the devices panel that will show more options.

The bottom "Reset adb" option will attempt to reconnect the emulator to eclipse. It usually works.

Linux Specific

(based on http://developer.android.com/sdk/index.html, with additions)

Step 1. Prepare your development computer

1a. Java

If you already have a satisfactory Java setup, feel free to skip this.

Ubuntu (and many other popular Linux distributions) come by default with OpenJDK. It's open source, which is nice, but it's quite frankly an awful runtime - things will run, but they'll run slowly, and when running a heavyweight application like Eclipse can overwhelm even a fairly high-end machine. Switch to Sun's Java implementation. In Ubuntu, the command is as follows:

user@host:~$ sudo apt-get install sun-java6-jdk sun-java6-jre

Then, make sure that your computer is actually using sun-java6 by running

user@host:~$ sudo update-alternatives --display java

Check that the directories used are called java-6-sun or something along those lines.

If you are running Ubuntu 10.10 Maverick development, the Sun java packages are not yet in the partner repositories. Temporarily change the partner repos to lucid, install java, then change back to maverick.

1b. Android SDK on 64-bit machines

The Android SDK for Linux only exists in a 32-bit version. In order to get the 32-bit SDK running on a 64-bit machine, you'll have to install 32-bit libraries. For example, in Ubuntu you can either look up ia32-libs in the Software Center or enter this command:

user@host:~$ sudo apt-get install ia32-libs
1c. Eclipse

Eclipse is in the Ubuntu repositories; just use the package eclipse-jdt (this includes the base eclipse package and the Java Development tools). You'll also need to install the eclipse-pde package, without which Eclipse can't install new plugins (good going there, Ubuntu Packaging Team). So in all, it goes like this::

user@host:~$ sudo apt-get install eclipse-jdt eclipse-pde

Also, before starting to work, make sure that Eclipse is configured to compile using the Sun Java 6 tools by default (it should be)

2. Download and install the SDK starter package

Direct link (linux only)

To install the SDK, simply unpack the starter package to a safe location.

Optionally, you may want to add the location of the SDK's primary tools directory to your system PATH. On Linux, edit your ~/.bash_profile or ~/.bashrc file. Look for a line that sets the PATH environment variable and add the full path to the tools/ directory to it. If you don't see a line setting the path, you can add one:

export PATH=${PATH}:<your_sdk_dir>/tools

3. Install the ADT Plugin for Eclipse

Instructions

4. Add Android platforms and other components to your SDK

Use the Android SDK and AVD Manager, included in the SDK starter package, to add one or more Android platforms (for example, Android 1.6 or Android 2.0) and other components to your SDK. If you aren't sure what to add, see Which components do I need?. To launch the Android SDK and AVD Manager on Linux, execute the android tool in the <sdk>/tools/ folder.

5. (Optional) Install a physical device

In order to allow ADB to access a device without being run as root, you'll need to get udev to loosen up the permissions on your device when it's connected. To do so, create a file "/etc/udev/rules.d/51-android.rules" and edit it to include the line:

SUBSYSTEM=="usb", ATTRS{idVendor}=="0e79", MODE="0666"

Add one line per vendor (ARCHOS, Motorola, HTC, etc.) substituting the vendor's USB ID after ATTRS{idVendor}== (The example above is for ARCHOS). For a list of the most common vendor IDs go to [1].

Add universal read permissions to the file:

chmod a+r /etc/udev/rules.d/51-android.rules

Restart udev (or your whole computer) for the new rule to be read:

sudo service udev restart

Lastly, as with Macs, you need to add a line with your device's vendor ID to ~/.android/adb_usb.ini. In one line:

echo $VENDOR_ID >> ~/.android/adb_usb.ini # The '>>' operator appends the output of echo to the file instead of overwriting

Android Resources

  • DroidDraw a new graphical GUI editor for Android apps (currently in beta).

Archos 5

Useful Apps from Appslib

GPS Test - does what the name suggests. Gives useful info about the number of visible satellites and signal strengths, your current position, the uncertainty in that position, and the position on a world map.

System Monitor - tells you what apps are currently resident in memory and their run status. Allows you to remove dormant apps from memory. This doesnt really save resources because Android will remove them as needed for new apps, but it may help with clean uninstalls, especially for native shared libraries.

Wiimote Controller - replaces the current input device (i.e. the touchscreen) with the Wii remote so it can be used with existing games. Make sure to undo this change before disconnecting the wiimote.

Not Responding

Under the USB connector on the bottom left side is a tiny hole, with a nearly invisible label which says "reset". Put a pin in the hole to reset the Archos.

Personal tools