Category Archives: Ubuntu

Install Android SDK and Tools with Eclipse in Ubuntu, Mac OS X and Windows

Here I’ll explain the process to install Android SDK and Tools. There are 4 things you have to install in order to develop Android applications:

  • Android SDK
  • Eclipse
  • Android Development Tools plugins for Eclipse (ADT)
  • Android Virtual Device (ADV)

Android SDK

You can download the latest version of the Android SDK for your OS at the official Android SDK web. Latest versions at the time of this writing are those:

Ubuntu android-sdk_r24.4.1-linux.tgz
Mac OS X android-sdk_r24.4.1-macosx.zip
Windows android-sdk_r24.4.1-windows.zip

Once downloaded uncompress it anywhere you like in your hard drive. It can be for example in your users home folder (/home/username/android-sdk-linux for Ubuntu, /Users/username/Applications/android-sdk-macosx for Mac OS X, C:\Documents and Settings\username\android-sdk-windows for Windows XP, C:\Users\username\android-sdk-windows for Windows Vista/7/8/10) or beside other applications (/usr/lib/android-sdk-linux for Ubuntu, /Applications/android-sdk-macosx for Mac OS X, C:\Program Files\android-sdk-windows for Windows).

Be sure you have configured the JAVA_HOME, ANDROID_HOME and PATH environment variables:

In Linux edit the ~/.bashrc file:

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:/bin/javac::")
export ANDROID_HOME=~/android-sdk-linux
export PATH=$PATH:~/android-sdk-linux/tools

For Mac OS X you should edit the ~/.bash_profile file:

export JAVA_HOME=$(/usr/libexec/java_home)
export ANDROID_HOME=~/Applications/android-sdk-macosx
export PATH=$PATH:~/Applications/android-sdk-macosx/tools

Eclipse

For Eclipse installation just go to https://eclipse.org/downloads/, download it and install it.

Android Development Tools

Open Eclipse and go to “Help→Install New Software”, click “Add…” and enter “ADT Plugin” for “Name” and “https://dl-ssl.google.com/android/eclipse/” for “Location”.

eclipse-add-new-software

eclipse-add-new-software-adt-plugin

Select that repository in “Work with:”, choose all the packages and proceed the installation. Click OK if you see a message saying that unsigned content is being installed . Once installed you have to restart Eclipse.

After the restart, Eclipse will ask you to configure the Android SDK location. Click “Open Preferences”, select “Use existing SDKs” and fill “Existing Location” with the path you used to decompress Android SDK. If you don’t configure it now you can configure it anytime in the Eclipse preferences under the Android options.

eclipse-preferences-android

After configuring the Android SDK location path you will be asked to install SDK Platform Tools. Click “Open SDK Manager” (or select “Window->Android SDK Manager”), select all the packages inside “Tools” and the version of Android of your choice (I used 4.2) and click “Install X packages…”. Don’t worry if you see “Stopping ADB server failed (code -1).” in the log messages, it’s OK.

Android Virtual Device

Now that everything is installed you have to create an Android Virtual Device (AVD) so you can use the emulator. Open the Java perspective (Window->Open Perspective->Java or click the icon with the yellow plus sign at the top right of the IDE and select Java). You will see 2 new icons with the Android symbol in the tools bar. Click the one on the right that looks like a phone (the other one opens the Android SDK Manager), click “New…” and give your Android Virtual Device a name, a device type, a target, etc. If you can’t select a target just restart Eclipse so it can load the newly installed SDK Platform Tools.

In Ubuntu for 64 bit systems you can get this error when creating an AVD:

Error: Failed to create the SD card.
Error: Failed to create sdcard in the AVD folder.

To solve it install the ia32-libs libraries (http://stackoverflow.com/questions/3878445/ubuntu-error-failed-to-create-the-sd-card). Beware that they are about 260MB:

sudo apt-get install ia32-libs

Your first Android Application

Now you are ready to create your first Android application. Create a new “Android Application Project” with all the default options, just fill a “Application Name” like “Hello World”. The default option uses a “BlankActivity” with a template that needs the the Adroid Support library. It will ask you to install it and is as simple as clicking the “Install/Upgrade” button showed in that dialog window.

And there you have a fresh new “Hello Word” Android application. If you make the mistake of clicking the “Run” button you will get an error like this:

Error in an XML file: aborting build

That’s because by default the opened file after creating this “Hello World” project is “activity_main.xml”. You can also notice that a new file called “activity_main.out.xml” has been created, and it even is marked with errors. Delete that newly created file and open the “MainActivity.java” file under “src” folder. Now you can click the “Run” button. Select “Android Application” in the “Run As” dialog window.

I had a problem in Mac OS X Lion after running the emulator several times. When I tried to run the application the emulator crashed every time. Searching on the Internet I found this page where it explains that if you run the emulator in a secondary monitor and close it while in that monitor, a value of the X position of the window is stored and next time that value is bigger that the first monitors resolution and chashes. Deleting the emulator-user.ini file from the /Users/username/.android/avd/device_name folder (executing open /Users/username/.android/avd/device_name from a terminal window) and running the emulator again solved the problem.

As a hint I always deselect “Project->Build Automatically” option because I prefer to build the code manually pressing Control+B or Command+B.

Sources: http://developer.android.com/sdk/installing/installing-adt.html
http://developer.android.com/sdk/installing/adding-packages.html

Remove old Linux kernels in Ubuntu

As time goes new kernel versions are released. After a kernel update old installed versions are not removed automatically, they are keep in case something goes wrong so you can boot again to a previous version.

linux-penguin-logo

But you may end up having lots of old versions you’ll never use. To remove them first you need to find all the installed versions:

$ dpkg -l | grep linux-image | grep -v extra | awk '{print $2}'
linux-image-3.16.0-30-generic
linux-image-3.16.0-31-generic
linux-image-3.16.0-34-generic
linux-image-3.16.0-37-generic
linux-image-3.16.0-43-generic
linux-image-generic-lts-utopic

Then remove all the unwanted versions using apt-get autoremove:

$ sudo apt-get autoremove linux-image-3.16.0-30-generic linux-image-3.16.0-31-generic linux-image-3.16.0-34-generic

You should probably leave at least the latests 2 versions just in case.

Ref: https://help.ubuntu.com/community/Lubuntu/Documentation/RemoveOldKernels

Enable hosting files outside /var/www in Apache2

I’m using Ubuntu and Mac OS X in my computer. I wanted both to share a partition to put all the things that could be duplicated in both systems: DropBox, downloads, music, etc. The websites I’m developing would be also there but I was getting 403 errors all the time. Anything outside /var/www won’t work. Finally I found out that there is a Directory configuration in /etc/apache2/apache2.conf that denies access to anything outside /var/www and /usr/share:

<Directory />
       Options FollowSymLinks
       AllowOverride None
       Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

To fix this you can disable the first Directory block or even better add a new one with Require all granted in it for your speceific path:

<Directory /home/shared/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

apache_logo

Install BCM4360 Wi-Fi drivers in Ubuntu for Macbook Pro 13″ Retina display mid 2014

Ubuntu 14.04 doesn’t install by default any driver suitable for the Wi-Fi device in the Macbook Pro 13″ Retina display mid 2014 (A1502 model or MacBookPro11,1). This is what you can see in dmesg for the Wi-Fi device:

Broadcom Corporation BCM4360 802.11ac Wireless Network Adapter [14e4:43a0] (rev 03)

BCM4360

But this Macbook does not have any Ethernet port so… How can you install the drivers? If you have access to an USB-Ethernet adapter just connect it to the network and install:

$ sudo apt-get update
$ sudo apt-get install bcmwl-kernel-source

But in case you don’t have one, it’s posible to download all the deb packages (from another computer and copy them to an USB drive) and install them manually. The version numbers will differ from one distribution version to another so check them. For Ubuntu 14.04 I installed those:

The installation process is quite simple, just follow this order:

$ sudo dpkg -i libfakeroot_1.20-3ubuntu2_amd64.deb
$ sudo dpkg -i fakeroot_1.20-3ubuntu2_amd64.deb
$ sudo dpkg -i dkms_2.2.0.3-1.1ubuntu5.14.04_all.deb
$ sudo dpkg -i bcmwl-kernel-source_6.30.223.248+bdcom-0ubuntu0.1_amd64.deb

You may need to load the wl module:

$ sudo modprobe wl

And add it to modules loaded at boot in /etc/modules:

lp
rtc
wl

Now the Wi-Fi device should work just fine.

Create a bootable Ubuntu USB drive from an ISO in Ubuntu

The first thing we need to do is download an Ubuntu ISO file. The second one is plugin the USB drive and discover which device file it is related with. Using dmesg can help us with this:

$ dmesg
...
[  161.448084] usb 2-4: new high-speed USB device number 4 using ehci-pci
[  161.581198] usb 2-4: New USB device found, idVendor=8564, idProduct=1000
[  161.581203] usb 2-4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  161.581205] usb 2-4: Product: Mass Storage Device
[  161.581208] usb 2-4: Manufacturer: JetFlash
[  161.581210] usb 2-4: SerialNumber: XXXXXXXXXX
[  163.501196] usb-storage 2-4:1.0: USB Mass Storage device detected
[  163.504617] scsi6 : usb-storage 2-4:1.0
[  163.505185] usbcore: registered new interface driver usb-storage
[  164.506478] scsi 6:0:0:0: Direct-Access     JetFlash Transcend 8GB    1.00 PQ: 0 ANSI: 6
[  164.506779] sd 6:0:0:0: Attached scsi generic sg2 type 0
[  164.508311] sd 6:0:0:0: [sdb] 15433728 512-byte logical blocks: (7.90 GB/7.35 GiB)
[  164.508698] sd 6:0:0:0: [sdb] Write Protect is off
[  164.508702] sd 6:0:0:0: [sdb] Mode Sense: 23 00 00 00
[  164.509072] sd 6:0:0:0: [sdb] Write cache: disabled, read cache: disabled, doesn't support DPO or FUA
[  164.512353]  sdb: sdb1
[  164.514327] sd 6:0:0:0: [sdb] Attached SCSI removable disk

There we can see it’s sdb. So now we just have to use dd to write the ISO file to the device:

$ sudo dd if=ubuntu-14.04.2-desktop-amd64.iso of=/dev/sdb bs=20M

We can also use the “Make Startup Disk” application to do the same in the desktop environment. If you don’t find it anywhere just run this from the command line and it should start:

$ usb-creator-gtk &

make-startup-disk

There just select the origin ISO and the destination USB drive and click “Make Startup Disk”.