Saturday 9 June 2012

Getting Started with Android


This tutorial is a quick start guide for installing Android and building a Hello World application using Android SDK. I've tried to keep it as brief as possible, for a detailed description please refer to the Android's official installation instructions [1].

The recommended practice for developing Android applications is using Eclipse and ADT plugin.  Android required at least Eclipse Helios and Java 6, and I assume that these are already installed on your system. If not, download and install Eclipse Classic [2] and JDK 6 [3] following the instructions specific to the OS you are using.

Install ADT plugin

1. In Eclipse, select Help > Install Software.
2. Click on Add button to add a new repository.
3. Enter the following url in Location field and click OK button:
https://dl-ssl.google.com/android/eclipse/
4. Select select all the items from the list press Next.
5. Follow the onscreen instructions to install the ADT plugin.

Configure SDK with ADT plugin

After installing ADT plugin when Eclipse restarts it asks for configuring Android SDK with the plugin. If you already have SDK and platform tools installed, you can choose the "Use existing SDKs" option and provide the path to the location of SDK. I installed configured it using the other option "Install new SDK" and selected both latest version and Android 2.1 supported by ~97% phones and tablets (as reported by eclipse). Follow the on screen instructions for installation. You can skip this step at this point and configure it later by selecting Window > Android SDK Manager from menu.

Create an AVD

Before transferring application to an android phone and running it there, you would like to test it on an emulator. The settings of a device that needs to be emulated are defined in an AVD(Android Virtual Device). You must create an AVD before launching the emulator. To create an AVD, select Window > AVD Manager and click New button. Define the settings of AVD and click Create AVD button. The AVD will be listed in the Android Virtual Device Manager window.

Say Hello Android

Now we are done with the setup part, lets get started with sample Android application that prints Hello World on screen:
1. In Eclipse, select File > New > Project
2. Select Android Project from the list, press Next.
3. Enter name of the project HelloWorld, press Next.
4. Choose an SDK from list, press Next.
5. Enter Application Name (HelloWorld), package (com.techobian.hello), select Create Activity checkbox and enter activity name (HelloWorldActivity) , press Finish.
6. Open HelloWorldActivity.java and replace its code with the following:
 package com.techobian.hello;

 import android.app.Activity;  
 import android.os.Bundle;  
 import android.widget.TextView;  
 public class HelloWorldActivity extends Activity {  
   /** Called when the activity is first created. */  
   @Override  
   public void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     TextView tv = new TextView(this);  
     tv.setText("Hello Android!!");  
     setContentView(tv);  
   }  
 }

7. Right click on project in Package Explorer and select Run As > Android Application from Context Menu. The emulator will take some time to load. Once done you will get a screen saying Hello World!!!

Say hello to device

So the app is now running fine on emulator, but before releasing it to you would like to test it on a real device. Here are the things to do:
1. Enable debugging on the device: On the device, go to Settings > Applications > Development and turn on USB Debugging.
2. Set up your system to detect the device: Skip this step if you are using Mac OS. On windows machine you need to install OEM USB Driver [4]. If you are using Ubuntu, you need to add udev rules file that contains USB configuration for each device on which you want to test. Add the following rule in the rules file /etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", MODE="0666", GROUP="plugdev"

This rule is for vendor Samsung, replace 04e8 with your vendor's id [5]. You can add multiple rules here if you are using different devices for testing. After saving our changes in the rules file, make the file readable by all users:
chmod a+r /etc/udev/rules.d/51-android.rules

3. Connect your device to the system and check whether the device is detected properly by running the following command from platform-tools/ directory in your SDK:
adb devices

4. Right click on your project and select Run As > Android Application and it runs on your device. You may also be presented with Device Chooser using which you can select the device for running the application. When you run the application on device, it also gets installed on the device.

REFERENCES

[2] http://www.eclipse.org/downloads/
[3] http://www.oracle.com/technetwork/java/javase/downloads/index.html
[4] http://developer.android.com/sdk/oem-usb.html
[5] http://developer.android.com/guide/developing/device.html#VendorIds

Tuesday 18 October 2011

Adding JRE in Eclipse

If you have multiple JREs installed on you system you can add all of them in Eclipse following these steps:

1. Open Window > Preferences


2. Go to Java > Installed JRE section. This section lists all the JREs that are currently added in eclipse.



3. Click on Search button and select the root directory in which your JRE/JDKs are installed. I'm using Ubuntu 11.10 and all the JDK/JRE that I'm using are installed in /usr/lib/jvm, hence I chose this directory as root to reduce search time.

After search completes all the JRE found will be listed in screen.


4. Select the default JRE by clicking on the check-box next to it in the list and click OK button.
You can also add individual JRE by clicking the Add button and following the on-screen instructions.

Friday 14 October 2011

Installing VMWare Tools on Ubuntu 11.10(Oneiric Ocelot)

Ubuntu 11.10(Oneiric Ocelot) released yesterday and I installed 32-bit desktop version on VMware Player. Installation was smooth and everything went great until I realized that VMware Tools was not installed automatically by VMware Easy Install. So I thought of installing it manually from VM > Install VMware Tools.


But this reported an error "VMware Tools installation cannot be started manually while the easy install is in progress". Luckily VMware  provides solution for this [1] :

1. Poweroff virtual machine

2. Go to virtual machine settings

3. Remove Floppy and CD/DVD(ide) from Hardware.

Power on the virtal machine now and insall VMware tools manually ( VM > Install VMware Tools) [2].

1. Extract VMwareTools in a temp directory
   $ cd /tmp
   $ tar zxpf /mnt/cdrom/VMwareTools-<x.x.x-xxxx>.tar.gz

2. Install Vmware Tools
  $ cd vmware-tools-distrib
  $ sudo ./vmware-install.pl

3. Answer few configuration related questions and tools be installed. The questions already have a default answer so you just need  to press Enter key most of the time, until you want to configuew something differently.

The installer was not able to able to find the path to kernel header

Searching for a valid kernel header path...
The path "" is not valid.
Would you like to change it? [yes]

What is the location of the directory of C header files that match your running kernel?

4. Open a new terminal and apply the following fix for kernel headers [3]
  $ cd /lib/modules/$(uname -r)/build/include/linux
  $ ln -s ../generated/utsrelease.h
  $ ln -s ../generated/autoconf.h

5.  Specify the header directory in first terminal:  
  /lib/modules/xxx/build/include/
where xxx is the kernel release version. You can get it from the following command
  $ uname -r


REFERENCES
[1] http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1017687

[2] http://www.vmware.com/support/ws55/doc/ws_newguest_tools_linux.html

[3] http://superuser.com/questions/199365/vmware-linux-headers-not-found-for-ubuntu-10-10

Thursday 19 May 2011

Touchpad problem in Ubuntu 11.04


I upgraded HP Mini 110 netbook last week from Ubuntu 10.10 to 11.04. Though it some really cool features, it created some serious trouble (atleast for me) with touchpad. Edge scrolling and middle button emulation stopped working. It was very annoying as I'm too much used to these features.

I found many patches for this problem but I'm reluctant to applying patches from untrusted sources. After some more research I found a simple solution for these problems:

1. Install gpointing-device-settings
sudo apt-get install gpointing-device-settings

2. Open System -> Preferences -> Pointing Devices, and enable Edge Scrolling and Middle Button Emulation.

3. Restart.

After restart a new tab "Touchpad" was added in System -> Preferences -> Mouse that provides various options for customzing touchpad features. More advanced features are available in System -> Preferences -> Pointing Devices.

Now I can edge scroll vertically/horizontally, scroll using two fingure drag and right click by tapping with two fingures. There is much more to TRY OUT!!!

REFERENCE
http://ubuntuforums.org/showpost.php?p=10751052&postcount=209

Friday 11 March 2011

HOW-TO: Enable logs in tomcat

When you install tomcat 6 from Ubuntu's repository, it does not write the access log automatically. To enable logging uncomment the following line in /usr/share/tomcat6/conf/server.xml

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>

Save the changes and restart tomcat:

$ /etc/init.d/tomcat6 restart

The logs will be stored in /usr/share/tomcat6/logs/ directory which is a symbolic link to  /var/log/tomcat6/ directory.