Target Operating System: Gnu/Linux
Distribution used: Debian
Setup Eclipse
Install the Java JDK and JRE
Code: Select all
apt-get install openjdk-6-jdk openjdk-6-jre
Code: Select all
http://www.eclipse.org/downloads/
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
Code: Select all
cd $HOME/eclipse
./eclipse
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!");
}
}
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
Code: Select all
tar -xzf android-sdk_r12-linux_x86.tgz -C $HOME/eclipse/
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/
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
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
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);
}
}
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!