Installing Android Studio on Debian Wheezy

Android Studio is the new IntelliJ IDEA based Android IDE. It succeeds the current Eclipse based IDE.

Android Studio requires Oracle Java 1.6 or later. It won’t work with OpenJDK.

Installing Oracle Java 1.7

These instructions describe how to install Oracle Java using java-common. java-common only works with Java 1.6 or 1.7. It doesn’t work with Java 8.

  • Download the latest 1.7 JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html. To find the tarball follow the links “Previous Releases – Java Archive” -> “Java SE 7” -> “Java SE Development Kit 7u..”. You’ll need the tarball not the RPM, e.g. jdk-7u67-linux-x64.tar.gz. Note: you’ll need an Oracle account to download archive versions of Java (those < Java 8).
  • Install java-common

    # apt-get install java-common

  • Create a deb file using the Java tarball,
    $ make-jpkg <downloaded tarball>
  • Install the resulting package (your deb file name will likely be different),
    # deb -i oracle-j2sdk1.7_1.7.0+update67_amd64.deb
  • Update your java links to point at this new Oracle Java package. To find the name of this package take a look in /usr/lib/jvm/. There should be a directory named j2sdk1.7-oracle (or something similar). Use this directory name in a call to update-java-alternatives.
    # update-java-alternatives -s j2sdk1.7-oracle
  • Test your system is using the correct version of Java using,
    $ java -version
     java version "1.7.0_67"
     Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
     Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
    $ javac -version
     javac 1.7.0_67

Install the Android SDK Tools

The Android SDK Tools package contains the SDK Manager. You’ll need this to download one or more SDKs.

Download “SDK Tools Only” from https://developer.android.com/sdk/index.html. Extract the downloaded file to your applications directory, e.g. ~/apps/.

Install Android Studio

Download Android Studio from http://developer.android.com/sdk/installing/studio.html.

Unzip the downloaded file to whereever you keep your apps, e.g. ~/apps/.

To start Android Studio run <install dir>/android-studio/bin/studio.sh.

Configure the location of your Android SDK by selecting “Configure” -> “Project Defaults” -> “Project Structure” -> “Android SDK Location”. Enter the directory where you extracted the Android SDK Tools.

I find it useful to create a launcher icon. This way I can launch Android Studio by clicking Alt-F1 and entering the first few characters of the app name. To create a launcher icon from the Welcome splash screen select “Configure” -> “Create Desktop Entry”.

References

Installing Debian 7.1 “Wheezy”

Every time I install Linux, no matter what the distribution, I have the same problems; configuring video and audio. When I installed Debian 7.1 recently I documented the steps I took. Hopefully you’ll find something of use here.

My Hardware

Video: Advanced Micro Devices [AMD] nee ATI RV710 [Radeon HD 4350]
Sound: Advanced Micro Devices [AMD] nee ATI RV710/730 HDMI Audio [Radeon HD 4000 series]
Monitor: Dell SP2208WFP (with built in webcam)
WebCam: OmniVision Technologies, Inc. Monitor Webcam

Video and sound devices can be determined using lspci. The Webcam is a USB device so it can be determined using lsusb.

Video

For regular use the opensource Radeon display driver is considered adequate. If you’re a gamer or just want to squeeze every bit of performance out of your card then you might consider the AMD proprietary display driver. For my needs the opensource driver is fine.

On the first boot GNOME 3 failed to load. The installer recognized my video card and installed the correct package, xserver-xorg-video-radeon, but as documented on the wiki my card requires proprietary firmware. This firmware is available in non-free. The steps to install it are,

  1. Open up Synaptic Package Manager and select Settings, Repositories from the menu
  2. Tick the checkbox next to Non-DFSG-compatible Software (non-free)
  3. Click Close and then the Reload toolbar button
  4. Search for and install firmware-linux-nonfree
  5. Reboot

GNOME 3 should start successfully after the reboot.

Audio

When I didn’t hear any sound I thought I was going to be in for a world of pain with sound drivers, ALSA and PulseAudio. Luckily all I needed to do was select the right output device. My system has two sound devices, an onboard Intel device and the sound device on the AMD video card. My monitor is connected by HDMI. I have a soundbar on my monitor drawing it’s signal from the HDMI cable. All I needed to do was,

  1. Open up the System Settings
  2. Click the Sound icon
  3. In the Output tab select the HDMI audio device, i.e. RV710/730 HDMI Audio [Radeon HD 4000 series] Digital Stereo (HDMI)

Update (Aug-2014): HDMI audio is disabled by default in the kernel/audio driver. To enable it,

  1. Edit /etc/default/grub and append “radeon.audio=1” to the GRUB_CMDLINE_LINUX_DEFAULT variable.
  2. Open a terminal execute sudo update-grub
  3. Reboot

Source: No sound on HDMI with Radeon driver

Webcam

My monitor has a built in Webcam. It’s an OmniVision Technologies, Inc. Monitor Webcam. I managed to get it working but it’s a bit hit and miss. When then uvcvideo kernel module is loaded it should create the device /dev/video0. Sometimes it does, sometimes it doesn’t. To get it to work is a matter of removing the module and reloading. After two or three attempts it usually works. Not very satisfying but I don’t use it very often so I’m not that bothered.

$ sudo modprobe -r uvcvideo     # unload the module
$ sudo modprobe uvcvideo        # load the module

Once the module loads successfully and creates the /dev/video0 device you can use the Cheese application to test it.

Microphone

The mic didn’t appear to be working initially but as with audio out all I needed to do was select the right device and turn up the volume. I use the mic on my monitor (attached to the webcam).

  1. Open up the System Settings
  2. Click the Sound icon
  3. Select the Input tab
  4. Select the Monitor Webcam Analog Stero device
  5. Turn the volume up to 100%

After getting the hardware working these are the applications I installed.

Flash Player

The Flash Player package is avaiable from contrib.

  1. Open up Synaptic Package Manager and select Settings, Repositories from the menu
  2. Tick the checkbox next to DFSG-compatible Software with Non-Free Dependencies (contrib)
  3. Click Close and then the Reload toolbar button
  4. Search for and install flashplugin-nonfree
  5. Restart your browser if you

Reference: FlashPlayer on the Debian Wiki

Java Browser Plugin

Simply install the package icedtea-6-plugin.

gThumb

gThumb is a photo manager. I prefer it over the default, Shotwell, because it feels quicker and more lightweight. I already organise my photos in a year, month, day folder structure so I have no need for anything fancy.

While gThumb itself is very easy to install (the gthumb package) it was failing to properly list all the photos and videos in a directory containing one or more videos. The problem was it couldn’t find the image it uses to surround videos (to give the reel effect). The fix is simple,

$ sudo ln -s /usr/share/gthumb/ui/filmholes.png /usr/share/filmholes.png

Reference: Redhat Bug 842183 – Gthumb breaks file list on movies

Android Tools

The Android Tools are used when developing Android applications. After installing the Android SDK I found adb wouldn’t work. When I ran it it gave a “file not found”. The problem is down to missing shared libraries. Here are the steps I took to fix it,

$ sudo dpkg --add-architecture i386
$ sudo aptitude update
$ sudo aptitude install libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386

Reference: Installing Android SDK tools on Debian Wheezy

Testing Android Activity & Process Lifecycles

Developing robust Android applications is challenging. At any moment your application can be interrupted, sent the background or just simply terminated. There are a few hooks to help you prepare for these scenarios but it’s such a dynamic environment it can be hard to anticipate how your application will behave.

Take the activity lifecycle for example. Under normal circumstances activities are only destroyed when their finish() method is called or the system needs to free up some memory. From a testing perspective this isn’t very deterministic so testing what happens when activities are destroyed is either forgotten about or not given the attention it deserves.

Luckily there are tools to help in these scenarios. The Dev Tools App is particularly useful. It’s automatically installed with every virtual device created using the Android Virtual Device Manager in Eclipse.

Testing Activity Destruction

To test what happens to your app when activities are destroyed tick the Immediately destroy activities checkbox under Development Settings in Dev Tools. This instructs Android to immediately destroy activities that are no longer visible. Under normal conditions you might never get to this test scenario if you don’t explicitly call finish() on your activities. It’s amazing the subtle bugs this can throw up.

Testing Process Termination

Another very useful test is to see what happens when your application’s process is terminated. When I stated out with UPM I received quite a number of crash reports that initially baffled me. The stack traces suggested situations that I just couldn’t recreate. It wasn’t until I started thinking about the impact of process termination that I found the root of the problems.

When a terminated application is restarted Android will try and return the user to whatever activity was previously in the foreground. This can cause problems if the activity assumes too much about the application’s state, e.g. what static variables are initialized. Restarting the application means there’s a new process so the static state of the previous instance is gone. Here’s how I test this scenario.

First I start the application in an emulator as normal. Once I’ve made it to the activity under test I hit the Home button to send the application into the background. Now I need to kill the application’s process. There’s a few ways to do this. My favourite is to use adb. adb is located in the Android SDK platform-tools directory. Running

$ adb shell

starts a shell on the emulator. From there I use

$ ps

to find the application’s process and

$ kill -9 <pid>

to kill the process. Once I’ve killed the process I go back to the emulator and hit the application’s icon to restart it. Android will try to resume the activity that was previously in the foreground. Ideally there should be no problems but if there are they’ll usually present themselves as a NullPointerException with a “Force Close” dialog for the user.

Android can be a difficult, confusing platform to work with. This is particularly true if you’re coming from a regular desktop application environment. There’s a paradigm shift in thinking required to fully appreciate the transient nature of the Android environment. Thankfully, once you’ve made that leap things do get easier. The most useful resources I’ve found are the Android Developer’s Guide and Stackoverflow.

UPM for Android 1.2 Released

Universal Password Manager for Android 1.2 has been released. The easiest way to install it is from the Android Market. Alternatively the apk can be downloaded from SourceForge. The source is also available there.

From the release notes…

  • Long-clicking on an account now brings up a context menu allowing you to copy username, copy password, launch URL or edit account
  • Added the ability to trust self signed certificates and certificates that have a different Common Name to the website hostname
  • Increased the font size on the Account Details activity
  • Fixed a bug on the main Accounts page so that it recovers gracefully when the database is closed unexpectedly

UPM 1.1 Released

With this release UPM on Android reaches feature parity with the desktop version. The main features included with this release are,

  • Shared Database support
  • Delete Database support
  • Lots of bugs fixes and improvements

The shared database feature was the primary focus of 1.1. With this it’s now possible to sync your password database with the desktop version. For full details on how to setup and use database sharing see the user guide.

You can upgrade from the Android Marketplace or download the APK directly from Sourceforge.

If you have any problems post please use the Help Forum.

UPDATE: When you upgrade you may get an error telling you UPM is no longer available when you try to start it. To fix this you should restart your phone and recreate any shortcut you have to UPM on your Home screen.

For those who are interested this seems to be a problem with Android 1.5 and how it handles a change to the main Activity after an upgrade. If you have any experience or details on this problem I’d be interested hear about it.