Step-by-step guide to Android development with Eclipse

In this tutorial, you will learn to create a simple application of a game we all used to play when we were kids, Rock Paper Scissors. As easy as it might seem, it requires some hard work on your part before you can create an app that runs without errors. If you are reading this tutorial, it means you are probably new to the Android app development field. Don't worry -- we will divide this tutorial into different parts to make it easy for you. Snapchat Saver APK

Step 1: Setup Java Development Kit (JDK)

You can download the JDK and install it, which is pretty easy. After that, you just have to set PATH and JAVA_HOME variables to the folder where you have java and javac. Xbox Emulator APK

PRO+

Content

Find more PRO+ content and other member only offers, here.
  • E-Handbook

    DevOps automation tools and Java combine to speed continuous delivery
Note for Windows Users: If you installed the JDK in C:\jdk1.6.0_15 then you will have to add the following two lines in your C:\autoexec.bat file.
set PATH=C:\jdk1.6.0_15\bin;%PATH%
set JAVA_HOME=C:\jdk1.6.0_15

Step 2: Configure Android SDK

After you have successfully installed the Android SDK, it is time to configure it. After installing the Android SDK, you will get a window like this: Run Apple Apps On Android With iOS Emulators
Figure 1
Just de-select the Documentation for Android SDK and Samples for SDKpackages if you want to reduce the installation size and time. Click on Install 7packages to continue with the installation. You will get a dialogue box like this: Cider APK 
Figure 2
It will take some time to install, so in the meanwhile you could do some other task to kill the time. How long will it take? Well, it depends on the speed of your Internet connection. Once it is done, you can close the SDK manager. iEMU APK Latest Version

Step 3: Setup Eclipse IDE

Install the latest version of Eclipse. After successful installation, it should display a window like this: Ski Safari 2  APK
Figure 3

Step 4: Setup Android Development Tools (ADT) Plugin

Here you will learn to install the Android Development Tool plugin for Eclipse. To do this, you have to click on Help > Software Updates > Install New Software. This will display the following dialogue box. Spider Man Unlimited APK
Figure 4
Just click on the Add button as shown in the picture and add https://dl-ssl.google.com/android/eclipse/ as the location. When you press OK, Eclipse will start to search for the required plug-in and finally it will list the found plug-ins.
Figure 5

Step 5: Create Android Virtual Device

The last step is to create Android Virtual Device, which you will use to test your Android applications. To do this, open Eclipse and Launch Android AVD Manager from options Window > AVD Manager and click on New which will create a successful Android Virtual Device. Use the screenshot below to enter the correct values.
Figure 6
Voila! You have successfully created Android Application Development environment. You are now ready to create a simple Rock Paper Scissors Android App.HD wallpapers for Android mobile
Before we write the code, you need to know how to take input from the user. The most efficient way of taking input from the user is to use the Scanner class, which is found in the java.io package as it is just a two-step process.
Scanner scanner =  new Scanner(System.in);
String input   =  scanner.next();

/* or String input   =  (new Scanner(System.in)).next(); */
I recommend using the Scanner class because it works equally well on command line as well as with Eclipse that we will use to make the Rock Paper Scissors app.

Calling the Java code in Eclipse

We will save you the trouble of writing the java code for a simple Rock Paper Scissors app and use can use the code below, but you are free to use your own code if you prefer.
// Android Rock Paper Scissors App 
// Rock_Paper_Scissors 
// ************* 

import java.util.Scanner; 
import java.util.Random; 


public class Rock 
{ 
public static void main(String[] args) 
{ 
    String personPlay; //User's play -- "R", "P", or "S" 
    String computerPlay = ""; //Computer's play -- "R", "P", or "S" 
    int computerInt; //Randomly generated number used to determine 
                     //computer's play 
    String response; 


    Scanner scan = new Scanner(System.in); 
    Random generator = new Random(); 

    System.out.println("Hey, let's play Rock, Paper, Scissors!\n" + 
                       "Please enter a move.\n" + "Rock = R, Paper" + 
                       "= P, and Scissors = S.");

    System.out.println();

    //Generate computer's play (0,1,2) 
    computerInt = generator.nextInt(3)+1; 

    //Translate computer's randomly generated play to 
    //string using if //statements 

    if (computerInt == 1) 
       computerPlay = "R"; 
    else if (computerInt == 2) 
       computerPlay = "P"; 
    else if (computerInt == 3) 
       computerPlay = "S"; 


    //Get player's play from input-- note that this is 
    // stored as a string 
    System.out.println("Enter your play: "); 
    personPlay = scan.next();

    //Make player's play uppercase for ease of comparison 
    personPlay = personPlay.toUpperCase(); 

    //Print computer's play 
    System.out.println("Computer play is: " + computerPlay); 


    //See who won. Use nested ifs 

    if (personPlay.equals(computerPlay)) 
       System.out.println("It's a tie!"); 
    else if (personPlay.equals("R")) 
       if (computerPlay.equals("S")) 
          System.out.println("Rock crushes scissors. You win!!");
    else if (computerPlay.equals("P")) 
            System.out.println("Paper eats rock. You lose!!"); 
    else if (personPlay.equals("P")) 
       if (computerPlay.equals("S")) 
       System.out.println("Scissor cuts paper. You lose!!"); 
    else if (computerPlay.equals("R")) 
            System.out.println("Paper eats rock. You win!!"); 
    else if (personPlay.equals("S")) 
         if (computerPlay.equals("P")) 
         System.out.println("Scissor cuts paper. You win!!"); 
    else if (computerPlay.equals("R")) 
            System.out.println("Rock breaks scissors. You lose!!"); 
    else 
         System.out.println("Invalid user input.");
Now calling the Java code in Eclipse is a tricky process and it helps to pay attention while you're doing this. Launch Eclipse and click File > New > Java Project
Figure 7
When the Create a Java Project box appears, it's time to give your project a name. Click on Finish to save it and it should appear in the Package Explorer window. Then we are supposed to add a package which will contain all our package files. Click on New Java Package icon to do this, as shown in the screenshot below.
Figure 8
Name your project and then click Finish.
Figure 9
Now we need to add a Java Class, which is as easy as adding a Java Package.
Figure 10
After giving it a name, make sure that the following options are checked:
Figure 11
After you create a new class, it will show up in the Work Space where you can write or copy the code.
Congratulations! You have just finished writing your first Java Application in Eclipse. It wasn’t that difficult was it?
Now you need to build the application and to do this, Right Click on your Android Project and select Android Tools->Export Signed Application Package. After selecting the export button, select Create new keystore and it will take you to the location where you want to save it, so give it a name and save it. Fill in all the required fields that are self-explanatory and save it. You have successfully exported the apk file to your computer and you can test the app it on your android device. 
Share:

0 comments:

Post a Comment

Copyright © TODAY MOBILE SOFT