last update: 2024-07-24 at 05:00:07 CEST

Android Development

This page should collect some problems that I have come across while developing for android

Flash Cynogenmod on Google Nexus S

following this howto will wipe all data from the device! It should be clear and I should not tell that but if something goes wrong your device may break. You may waste much time to bring it back alive or it can only be used as a paper weight or something cooler.

Im running Debian Stretch To install adb and fastboot do:

sudo apt-get install android-tools-adb android-tools-fastboot

Enable USB Debugging from the Developer options on the phone

$lsusb | grep Nexus
Bus 002 Device 011: ID 18d1:4e22 Google Inc. Nexus S (debug)

Give udev permissions

sudo vim /etc/udev/rules.d/51-android.rules

Create the file containing:

SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev"
sudo service udev restart

Restart adb server

sudo adb kill-server && sudo adb start-server

Go into fast boot mode on the phone

sudo adb reboot bootloader

Or press vol-up + power button while the phone is off. The device should be listed by fastboot

fastboot devices
xxxxxxxxxxxxxxxx    fastboot

Unlocking the bootloader

My Phone shows the product name HERRING, hw version REV 52. Unlock the boot loader

fastboot oem unlock
OKAY [ 17.251s]
finished. total time: 17.251s

There comes a confirmation screen on the device. change to yes using volume key and accept with the power key

Now your bootloader should show: LOCK STATE - UNLOCKED

Choose REBOOT from the boot loader menu and accept (power key)

Installing a custom recovery using fastboot

Reenable USB Debugging from the Developer options after reboot

I downloaded this image: https://dl.twrp.me/crespo/twrp- sha256sum = 2066c5f2e371dcbbd28f93f559aac60a243bfc7bae2df61641d758fb8fc913f6

make sure everything is connected:

fastboot devices
xxxxxxxxxxxxxxxx    fastboot

Switch into bootloader

adb reboot bootloader

Flash recovery

fastboot flash recovery twrp-
sending 'recovery' (6424 KB)...
OKAY [  1.005s]
writing 'recovery'...
OKAY [  0.905s]
finished. total time: 1.910s

Select RECOVERY from bootloader

If everything went well you now see the menu from the Team Win recovery project

Installing CyanogenMod from recovery

I used http://download.cyanogenmod.org/get/jenkins/162730/cm-11-20160523-NIGHTLY-crespo.zip sha256sum = 6778af177bbf04f1aefedd066e7f0ff60aa96fad529e06f0ababb46f271ee5d3

Push it to the device

adb push cm-11-20160523-NIGHTLY-crespo.zip /sdcard/

Again Boot into recovery

adb reboot bootloader

Select RECOVERY from bootloader

select Wipe and swipe to confirm. Then select Factory Reset and confirm. Now go back and select Install. The installer now presents the contents of the /sdcard folder. select cm-11-20160523-NIGHTLY-crespo.zip and swipe to install. Select Reboot System

Enjoy Cyanogenmod! Thanks to all guys who made it!

Setting Up The Environment

Starting of adb Fails

(adb stands for Android Debug Bridge) Everything seem to be setup correctly but eclipse complains that there might be already an adb server running. If starting the adb manually the following error occurs:

./adb start-server
* daemon not running. starting it now on port 5037 *
cannot bind 'tcp:5037'
ADB server didn't ACK
* failed to start daemon *

There are many solutions out there in the net. Some suggestions are:

  • Kill any running adb instances ps ax | grep adb; killall adb

  • Remove your ~/.android directory rm -Rf ~/.android

  • Run adb like this: ./adb nodaemon server

I had setup all this on a Gentoo Linux system but no solution seemed to work for me..

Then I looked deeper whats going on using strace and found this:

strace ./adb start-server
connect(3, {sa_family=AF_INET, sin_port=htons(5037),
sin_addr=inet_addr("")}, 16) = -1 ETIMEDOUT (Connection timed out)

The syscall connect() returns with a ETIMEDOUT error. So I checked this interface and found that the lo interface simply was not up! x(

ifconfig lo up

How to Get Syntax Highlighting for .js and .html Files in Eclipse

Click on 'Help->Install New Software...'
* Eclipse Web Developer Tools
* JavaScript Developer Tools

Connect Nexus 4 to a Linux System

Enable Developer Mode

To enable developer mode so into Settings→About phone→Buld number. Now tap on the build number entry 7 times until your phone says "Now you are a developer!"

  • Enable devloper mode on the Nexus 4

  • Enable USB debugging in developer mode settings

  • Install the following packages on your system

sudo apt-get install mtp-tools mtpfs
sudo vim /etc/udev/rules.d/51-android.rules

paste the following into the file

#LG - Nexus 4
SUBSYSTEM=="usb", ATTR{idVendor}=="1004", MODE="0666"
#Samsung - Nexus 7 & 10
SUBSYSTEM=="usb", SYSFS{idVendor}=="18d1", MODE="0666"

Restart the udev daemon to make the rule active

sudo service udev restart
sudo mkdir /media/nexus4
chmod 755 /media/nexus4
sudo mtpfs -o allow_other /media/nexus4
sudo umount /media/nexus4

Install mtpfs on Debian 7 Wheezy

on debian 7 (wheezy) its works a little different cause the package mtpfs must be compiled from source. download the source from here

sudo apt-get install libmtp-dev fuse libmtp9 pkg-config libfuse-dev
libglib2.0-dev libmad0-dev libid3tag0-dev
wget http://www.adebenham.com/files/mtp/mtpfs-1.1.tar.gz
tar xvfz mtpfs-1.1.tar.gz
cd mtpfs-1.1/
make -j3
sudo make install

now you can normally mount ur Nexus 4

Mount the Phone via SSHFS

make sure a ssh daemon is installed and started on the phone. Mount your data directory on the phone into /mnt/nexus on your local filesystem. The IP of the phone is the port the ssh daemon is listening is 10222 here

sudo mkdir /mnt/phone
sudo chown timo:users /mnt/phone
sudo sshfs root@ /mnt/phone/ -p 10022 -o reconnect -o allow_other
sudo umount /mnt/phone

Recent openssh versions have deprecated DSA keys by default. You get:

sudo sshfs root@ /mnt/phone/ -p 10022 -o reconnect -o allow_other
read: Connection reset by peer

You can enable ssh-dss again:

sudo sshfs root@ /mnt/phone/ -p 10022 -o reconnect -o allow_other -o HostKeyAlgorithms=+ssh-dss

Then sync your files

rsync -avp /mnt/phone/DCIM/Camera/ /home/timo/pix/digipix/handypix2016

Cpoy Files Via FTP

install primitive ftpd on your phone. Setup is trivial.