[Linux] Setting up Eclipse for Android development

DON'T post new tutorials here! Please use the "Pending Submissions" board so the staff can review them first.
Post Reply
User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

[Linux] Setting up Eclipse for Android development

Post by ayu »

Setting up Eclipse for Android development

Target Operating System: Gnu/Linux
Distribution used: Debian

Image

Setup Eclipse

Install the Java JDK and JRE

Code: Select all

apt-get install openjdk-6-jdk openjdk-6-jre
Download Eclipse.

Code: Select all

http://www.eclipse.org/downloads/
I will use "Eclipse IDE for Java EE Developers" (32-bit) in this tutorial.

Save the tar.gz file somewhere.

Now extract it to your home directory (You don't have to put it in your home directory, I just like to have it like this, but there are more 'correct' ways to do it)

Code: Select all

tar -xzf eclipse-jee-indigo-linux-gtk.tar.gz -C $HOME
Navigate to the eclipse directory that you just extracted, and start eclipse.

Code: Select all

cd $HOME/eclipse
./eclipse
eclipse will now ask you for your workspace location, personally I put this in the same folder (the eclipse folder).

Now, to make sure that everything is working as expected, create a new Java project by pressing File -> New -> Project

Choose "Java Project", press "Next", then name it the project HelloWorld.
In case Eclipse asks you if you want to switch to the "Java Perspective" then press "Remember my decision" and then press "Yes".

Now, to your left you will have your Package Explorer, and our Project called "HelloWorld".
Expand it in the list, and under "src" right click and add a new class file (New -> Class), name it "Main". You can use the package name "helloWorld".

Now, in the newly created Main.java file, copy/paste this code below.

Code: Select all

package helloWorld;

public class Main {
	public static void main(String args[]) {
		System.out.println("Hello World!");
	}
}
Now press the "Run" button (If Eclipse asks you how to run it, just choose "Java Application").

If everything works, then you should see the text "Hello World!" in the output window.

Setup the Android SDK

Download the Android SDK

Code: Select all

http://developer.android.com/sdk/index.html

Code: Select all

wget http://dl.google.com/android/android-sdk_r12-linux_x86.tgz
Extract it to the eclipse folder (Not needed, but I like to have it gathered like this)

Code: Select all

tar -xzf android-sdk_r12-linux_x86.tgz -C $HOME/eclipse/
Install the ADT Plugin for Eclipse (Android Development Tools)

Now, start eclipse if you don't already have it running.
Then select Help -> Install New Software.
Click Add, in the top-right corner.

In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the Location

Code: Select all

https://dl-ssl.google.com/android/eclipse/
Press "OK"

Note: If you have trouble acquiring the plugin, try using "http" in the Location URL, instead of "https" (https is preferred for security reasons).

In the Available Software dialog, select the check box next to Developer Tools and click Next.

In the next window, you'll see a list of the tools to be downloaded. Click Next.
Read and accept the license agreements, then click Finish.

Note: If you get a security warning saying that the authenticity or validity of the software can't be established, click OK.

When the installation completes, restart Eclipse.

Configuring the ADT Plugin

After you've successfully downloaded the ADT as described above, the next step is to modify your ADT preferences in Eclipse to point to the Android SDK directory:

Select Window -> Preferences... to open the Preferences panel
Select Android from the left panel.

You may see a dialog asking whether you want to send usage statistics to Google. If so, make your choice and click Proceed. You cannot continue with this procedure until you click Proceed.

For the SDK Location in the main panel, press "Android" and then click Browse... and locate your downloaded SDK directory.

In my case it's

Code: Select all

$HOME/eclipse/android-sdk-linux_x86
Click Apply, then OK.

You will probably get a warning saying that you have not installed any platform tools yet, so next we will do that.

Installing Platforms and Platform-tools

Press Window -> Android SDK and AVD Manager.

Next press "Available packages".

Now expand "Android Repository" in the list, and choose to install "Android SDK Platform-tools, revision 6" and "SDK Platform Android 2.3.3, API 10, revision 2". Of course you can choose whatever you want here, and as many platforms and packages that you like as it all depends on what you want to develop and for what device, but in this tutorial I will only choose these two.

Now press "Install Selected".
In the next window, accept the licenses and press Install.
When everything is done, close the window.

Adding Android Virtual Devices

Open up the "Android SDK and AVD Manager" again (Window -> Android SDK and AVD Manager).
In the "Virtual devices" choose "New".
You can name it whatever you want, but in this tutorial we'll just name it "test".
Set the target to Android 2.3.3.
The SD Card option can be set to 50 MB or whatever you want.
You can leave the rest of the options as they are.
Now press "Create AVD".
There should now be a "test" AVD in the Virtual devices list, now that we have finished that step, you can close down the manager.

Now, shutdown Eclipse and run the following commands

Code: Select all

$HOME/eclipse/android-sdk-linux_x86/platform-tools/adb kill-server
$HOME/eclipse/android-sdk-linux_x86/platform-tools/adb server-server
Now start eclipse again, it's time to create your first app

Creating your first Android app.

Press "File -> New -> Project -> Android Project"

You can name it "HelloWorld", and the package name "hello.World" (notice the dot, as a package name must have at least two identifiers here). Press "Finish"

Now, in the Package Explorer you should now have a project called "HelloWorld", expand it, and then expand "src" and you should have a file called "HelloWorldActivity.java".

Copy and paste this code into the file

Code: Select all

package hello.World;

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);

    }
}
now, before we can run this code we have to create a run configuration.
Right click on your project and select "Run As -> Run Configurations".

Now select "Android Application" and press "New launch configuration" (the small icon up the the left).

In the view you have to your right, enter "Android conf" in the name field.

In the "Android" tab, press browse and choose your project in the "Project" field.

In the next tab (Target), you can have it set to "Automatic" and then have the AVD deselected.

In the third tab "Common", choose "Run" and "Debug" in the "Display as favorites" window.

Press apply, and then close.

You can now press the "Run" button in Eclipse, and choose your "Android conf" configuration.
If everything goes as expected, your Android Virtual Device should now fire up and run your application :)

If you have a phone running Android, you can simply install the drivers for it and connect it via a USB cable. ADB will then recognize it and make it selectable in your configurations settings.

Have fun!
"The best place to hide a tree, is in a forest"

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Re: [Linux] Setting up Eclipse for Android development

Post by ayu »

Since my guide here might become (or it already has become) outdated, I will post the official installation guide here as well for future visitors.

Code: Select all

http://developer.android.com/sdk/installing.html
The one at the link covers all supported systems.
"The best place to hide a tree, is in a forest"

User avatar
joebox
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 213
Joined: 19 Mar 2012, 18:15
12
Contact:

Re: [Linux] Setting up Eclipse for Android development

Post by joebox »

Thanks cats I will try it out when I get some time.
Award winning Unlimited Web Hosting
$1.81/month http://www.topratedhostservice.com
3 free domains | $100.00 Free advertising credits | Free Custom website design
Image

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Re: [Linux] Setting up Eclipse for Android development

Post by bad_brain »

good work man! =D>
Image

Post Reply