[Guide] [Explained] Your first Android App

Search This thread

Rachid.Ala

Senior Member
Aug 28, 2012
503
519
Rabat
Probably u could have just told them to download "android bundle" from developer site..that could have saved a lot of their work:cowboy::cowboy:

Dude a suggestion don't get angry you can just link to the ADT bundle instead of downloading SDK and Eclipse separately... By the way nice guide for starters.. :good: But you could have also included using XML stuff and not just the coding.. Just a suggestion.. After all they also need XML to master developing...:)
I prefer the users know exactly what they are installing anyway I will add it to the tut ASAP :D And XML stuff will be a complete new tutorial in the near future
Thanks for all of you and enjoy :highfive:
 

magestic1995

Senior Member
Jun 18, 2011
368
154
The toolbox : JDK​

As I said quickly in the introduction, Android applications are developed in Java. You may already have some of the tools that I will present here if you ever developed in Java. Well, so much better! It is much less work for you. ;)

A word about Java

One characteristic of Java is portability, which means that computer programs written in the Java language must run similarly on any hardware/operating-system platform. This is achieved by compiling the Java language code to an intermediate representation called Java bytecode, instead of directly to platform-specific machine code. Java bytecode instructions are analogous to machine code, but they are intended to be interpreted by a virtual machine (VM) written specifically for the host hardware. End-users commonly use some special tools installed on their own machines.

These tools are included in the JDK. In addition, the JDK contains the JRE (so also the virtual machine), which is handy. :)
To summarize, there has two cases:
  • You are a simple user of Java : you must have JRE.
  • You are a developer : you need the JDK tools

Frequently asked question :

  • Since I tried to put myself in Java, I may already have JDK installed ... How do I know if this is the case ?

We will make a very simple little test (or rather 2 ;) ).

Start by opening a command prompt in Windows (Start -> Programs -> Accessories -> Command Prompt) or a terminal if you're on a Mac or GNU / Linux.

  • To know if JRE is installed, type the following command:
    Code:
    java -version
  • To know if JDK is installed, type the following command:
    Code:
    javac

In both cases, if the command is not recognized, is that you do not have the tool in question (JRE or JDK).

If you have only the JRE, install the JDK.
If you have nothing ... Install the JDK: p (the JRE is included anyway).

In short, now that you know where you stand with your Java environment, you can do (or not btw) the installation.

While all of these explanations were not necessarily required, it is still better to know what is installed, right ?


Installing the JDK

The installation of the JDK will be faster than his explanations, I promise :D

downloading
To start, go to this address.
Click the "Download JDK" button.
On the next page, accept the license agreement and click on the executable to download : jdk-7u51-windows-x64.exe in my case

installation
To start the installation, double-click the executable previously downloaded and let it guide you (or run it from a terminal).

And voilà ! Here is the first brick laid. :D

Hello when you said "To start, go to this address" there is no address to go to. Really looking forward to using this guide but need the link:eek:
 
  • Like
Reactions: Rachid.Ala

Aadi

Senior Member
May 27, 2012
468
290
infinityhacks.wordpress.com
I prefer the users know exactly what they are installing anyway I will add it to the tut ASAP :D And XML stuff will be a complete new tutorial in the near future
Thanks for all of you and enjoy :highfive:

:highfive: good and dude remember i am ready to help if you need any like some tutorials and stuff. If at all you need anything just PM me.:good:
 
  • Like
Reactions: Rachid.Ala

mlazzarotto91

Senior Member
Feb 26, 2013
120
24
Italy
Hi thanks for the guide! :laugh:

Unfortunately the app crashes as soon as it opens!
Can someone take a look to the log?
 

Attachments

  • HelloXda-University_log.txt
    7.6 KB · Views: 10
  • MainActivity.java.txt
    2.1 KB · Views: 9

Breach

Senior Member
Apr 1, 2009
334
182
I was having an issue with the directions to open SDK Manager, seems some people do, but a quick Google Search resulted in a work around... So, if you...

Try to run SDK Manager from Windows Explorer and a DOS box pops up and disappears.

or

Try to run SDK Manager from DOS Prompt and nothing seems to happen.

then just watch this video..

http://www.youtube.com/watch?v=Dpik8yxhv-8
 
Last edited:

davant155

Senior Member
Dec 23, 2012
85
16
1. Thank you very much for this Tutorial!
2. With the latest Android Development Kid, a couple things changed... (Actionbaractivity...)
so if i start a new Project the source code is already different. But i just deleted it and used your sourcecode, but that doesn't work :(

I get errors like:

- extension WGL_ARB_make_current_read was not found
- extension WGL_EXT_swap_control was not found
- This application has requested the Runtime to terminate it in an unusual way.

Can somebody please help me?

Thank you
 

googleminded

Senior Member
Mar 26, 2014
103
31
29
Delhi
Specific tools for Android : Android SDK​

Download the Android SDK and decompression

To download the Android SDK, go here and choose the file depending on your system.
As you can see, this file is compressed (zip for Windows and Mac or tgz for GNU / Linux). Unzip it where you want on your hard drive.

hey.. i have downloaded android SDK like many times successfully but whenever i try to open/extract the zip am getting a msg (attached the ss below) i dont know why am getting this.. if u r able to understand my problem then plz help me :confused:

am using Windows 8 n i have downloaded SDK Tools for 64 bit from ur link
i have downloaded both of them android-sdk_r22.6.2-windows.zip
installer_r22.6.2-windows.exe

ss here
 

Top Liked Posts

  • There are no posts matching your filters.
  • 53
    Introduction​

    Hello guys and welcome to my first guide (be indulgent please haha) :D
    In this guide I will show you how to build your first Android app, knowing java langage will be very helpful to follow up but it's not required.
    In addition, we will not see a lot of Java in this introductory tutorial.
    That said, if you want to go further in the development of Android applications, you will need to know Java. :)

    In this guide we will create a very simple Android application ("Hello World!) The goal is to see basis of development.
    What to expect from this guide


    • Setting up the development environment
    • A very simple example

    I’ll be using Windows for this tutorial. However, there will be not much difference on another system (GNU/Linux or Mac OS X). You just need to adapt the instructions to your particular situation.
    25
    New Android project​

    Finally! We reach the goal! Now it's good, our environment is in place. If you have not had any problems so far, you are ready to create a new Android project.

    Create a new project

    To begin, select from the menu "File" -> "New" -> "Project". With the ADT plugin, you now have the option to create a "Android Application Project". Select this option and click "Next". Then you come to the window, which allows you to initialize your Android project:
    363809pro.jpg


    Here are the important information to fill :

    • Application name: This time it is the name of your application. That will appear in the very eyes of the user. You can put special characters if you wish.
    • Project Name : This is the name that will define your Eclipse project. You can put whatever you want but avoid spaces and other special characters.
    • Package name: By convention, the name of a package is in the form of a "url upside down ." You can put your personal domain name or whatever you want. As long as you do not post your application on a large scale , it is not very important.
    • Minimum required SDK: This is the minimum number required API to run your application. You can not install the application on a mobile with an older API.
    • Build Target : Select the version of Android on which you want to work .

    Click "Finish" to create your project.

    Application code

    Code créé par défaut

    Here is the code created by default:

    Code:
    package com.test.helloxda_university;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    
    public class MainActivity extends Activity {
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);
    	}
    }

    This code contains various elements:
    • Package Name
    • some "import" android.*** : Required libraries to the script
    • The class MainActivity that inherits from Activity.

    I will not detail what constitutes the onCreate() method because we will now change it.

    Code of our "Hello XDA-University!"

    The purpose of our application is to say "Hello XDA-university". For this, we need a field "text". On Android, a field of this type is a TextView (Android, all the elements are based on the View class).
    We create our TextView with the following line:
    Code:
    TextView tv = new TextView(this);
    This requires to import the corresponding library:
    Code:
    import android.widget.TextView;
    we apply a text to our TextView:
    Code:
    tv.setText("Hello XDA-university !");
    Finally, we apply the TextView to the current view:
    Code:
    setContentView(tv);
    You will notice the following line:
    Code:
    super.onCreate(savedInstanceState);

    It can tell Android how to start the application (we call the onCreate method of the parent class by passing the savedInstanceState, which is the previous state of the application).

    Complete code (what a code!) of our application:

    Code:
    package com.test.helloxda_university;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.TextView;
    
    public class MainActivity 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 XDA-university !");
            
            setContentView(tv);
        }
    }

    With this, our text should be able to be displayed without issues. :)

    Launch the application in the AVD

    To launch the application, choose "Run" from the menu ... "Run"
    The AVD will then take a few moments to start: you will see the letters "ANDROID" in gray on black background. This might take some time depending on your configuration.

    Once the AVD is fully started, your application will launch automatically:
    668983Capture.jpg


    Ta daaaa! :cowboy:

    Well I told you: nothing transcendent ... But we must start somewhere. ;)

    We arrive at the end of this tutorial dedicated to the establishment of an environment of Android development. This is not the only way.

    There are many steps to finally not much except a little "Hello!" ... But you are now armed to get started with Android. I leave it to you to learn the art of developing Android applications: Sights, Activities, Intents, etc. .... ;)

    I hope you learned something with me and if you have any questions do not hesitate to ask me.
    24
    The toolbox : JDK

    The toolbox : JDK​

    As I said quickly in the introduction, Android applications are developed in Java. You may already have some of the tools that I will present here if you ever developed in Java. Well, so much better! It is much less work for you. ;)

    A word about Java

    One characteristic of Java is portability, which means that computer programs written in the Java language must run similarly on any hardware/operating-system platform. This is achieved by compiling the Java language code to an intermediate representation called Java bytecode, instead of directly to platform-specific machine code. Java bytecode instructions are analogous to machine code, but they are intended to be interpreted by a virtual machine (VM) written specifically for the host hardware. End-users commonly use some special tools installed on their own machines.

    These tools are included in the JDK. In addition, the JDK contains the JRE (so also the virtual machine), which is handy. :)
    To summarize, there has two cases:
    • You are a simple user of Java : you must have JRE.
    • You are a developer : you need the JDK tools

    Frequently asked question :

    • Since I tried to put myself in Java, I may already have JDK installed ... How do I know if this is the case ?

    We will make a very simple little test (or rather 2 ;) ).

    Start by opening a command prompt in Windows (Start -> Programs -> Accessories -> Command Prompt) or a terminal if you're on a Mac or GNU / Linux.

    • To know if JRE is installed, type the following command:
      Code:
      java -version
    • To know if JDK is installed, type the following command:
      Code:
      javac

    In both cases, if the command is not recognized, is that you do not have the tool in question (JRE or JDK).

    If you have only the JRE, install the JDK.
    If you have nothing ... Install the JDK: p (the JRE is included anyway).

    In short, now that you know where you stand with your Java environment, you can do (or not btw) the installation.

    While all of these explanations were not necessarily required, it is still better to know what is installed, right ?


    Installing the JDK

    The installation of the JDK will be faster than his explanations, I promise :D

    downloading
    To start, go to this address.
    Click the "Download JDK" button.
    On the next page, accept the license agreement and click on the executable to download : jdk-7u51-windows-x64.exe in my case

    installation
    To start the installation, double-click the executable previously downloaded and let it guide you (or run it from a terminal).

    And voilà ! Here is the first brick laid. :D


    Next steps are installing android sdk, eclipse and ADT plugin or you can just download and install adt bundle wich provide you with :
    • Eclipse + ADT plugin
    • Android SDK Tools
    • Android Platform-tools
    • The latest Android platform
    • The latest Android system image for the emulator
    Thanks to @FreakOde and @Chain Hacker
    20
    Specific tools for Android : Android SDK

    Specific tools for Android : Android SDK​


    We have just installed the JDK. So now you have the tools to develop a Java program. That said, an Android application is a particular Java program. You have the basic tools but not the specific tools to Android.
    The tool you are missing is the SDKAndroid. It contains what you need, not to develop a standard Java program, but to develop an Android application.

    Download the Android SDK and decompression

    To download the Android SDK, go here and choose the file depending on your system.
    As you can see, this file is compressed (zip for Windows and Mac or tgz for GNU / Linux). Unzip it where you want on your hard drive.

    Remember exactly where you put the decompressed content. His path will be needed for the future. I recommend a safe place that will not move.

    Personally, I put the contents of the zip in : C:\Android\android-sdk-windows

    Add the SDK to PATH

    Frequently asked question :

    • Ok I do not mind ... but what's the point?

    No worries, before the manipulation, let me explain what it is. :)

    What is the PATH?

    When Windows (and this is the same principle on Mac or GNU / Linux) executes a command, it will search for it in specific directories...if it is not found in these directories, it considers that it does not know it and returns an error.
    These specific directories are defined in what is called an environment variable: a variable (which, by definition, contains a value) accessible by Windows, everywhere, all the time.

    The environment variable in question is PATH. To see its value, type the following in the command prompt in Windows:
    Code:
    echo %PATH%
    You get a series of directories separated by ";".
    It is in each of these directories that Windows searches for commands that you ask.

    For example, the java command that we used earlier, is located in the C:\Windows\System32. Well I'm sure that this directory is in your PATH. ;)
    So now, we'll need that Windows knows where the new commands of the Android SDK are.
    To add it to your path, execute this command :
    Code:
    set PATH=%PATH%;"path to android sdk"
    So in my case I should execute
    Code:
    set PATH=%PATH%;C:\Android\android-sdk-windows

    One last step is required to install the Android SDK. Do not worry, this is the easiest. ;)

    Installing Android platforms

    The last step is to install at least one version of Android platform. According to the version of Android, APIs differ a little. At the time of this writing, the latest version of Android is version 4.4.2 (KitKat).

    In the SDK directory, an executable is present: SDK Manager.exe. It's a small interface to manage versions of Android.

    Run it to start the installation.

    Among the available packages, choose the one you want:
    531234260365.png


    Personally, I took everything! To be sure not to return. :p

    On Mac and GNU/Linux, run from a terminal the "android" command in the directory / tools /.

    The installation will take a few minutes (to me it was quite long since I took everything ...).

    Once installation is complete, we can move to: Installing Eclipse.
    16
    Development environment : Eclipse

    Development environment : Eclipse
    As for the JDK, it may be that you already have Eclipse installed. If this is the case, great. :) You can now move on to the next section.

    Otherwise, we will install it together.

    Frequently asked question :

    • But in fact, what is Eclipse?

    Eclipse is what we call an IDE or "Integrated Development Environment". This is a software that allows you to write programs more easily than simple Notepad in Windows (although it is possible). Besides the color code, it will bring you useful tools to compile your programs, debugging, etc.. It can be used to develop with any type of language, but we use it to make Java. ;)

    In addition, Eclipse is designed to be augmented with plug-ins. Thus, there is a plugin to develop Android applications ...! We'll see this in the next section.

    Do you like it? Well let's go for the download and installation!

    Download

    First of all, go here and download Eclipse.
    247441eclipse.jpg


    Choose 32 Bit or 64 Bit depending on your configuration (if you do not know , take 32 Bit ) .

    On the next page , click on the big green arrow and ... wait for it to finish!

    Installing Eclipse

    Installing Eclipse really comes down to ... unzip the downloaded file!

    You can place it anywhere on your hard drive. Personally ( on Windows ), the story that things are organized , I placed the folder " eclipse" in C:\Program Files ( or C :\Program depending on your version of Windows).

    To start Eclipse, run the executable found in the directory "eclipse" (really , you guessed ? haha :D) .

    At startup, Eclipse will ask you the location of your Workspace. This is the directory that contains all the data related to your Java programs ( and thus your Android applications). Your source code will be stored there. This is the time , if you have a hard drive dedicated to your data, choose a directory therein. Otherwise, you can leave the default directory.

    Well. Now , to develop our Android apps more easily , we need a small plugin.