Sign in

Sign in to confirm

Have you forgotten your password?

... or login with Facebook:

Don't have an AndroidPIT account yet? Sign up

How to create your first Android app

Henrique Rocha
27

This article will be the beginning of an AndroidPIT Android Development series.Knowing a programming language already will be very helpful to follow up with the tutorial but it’s not required.

Android development is mainly done in Java, which is the usual language used to teach programming in computer science courses. If you don't know Java but already know another language, you can easily pick up Java along the way.The development environment we're going to use is the new Android Studio which was announced during the latest Google Developer’s Conference (I/O 2013).

Our goal for this week's mini project is to create an app that displays "Hello AndroidPIT" on the screen of your Android device.

LV1A3278
© AndroidPIT

First steps

The first thing you need to do is to download Android Studio.

I’ll be using Ubuntu Linux for this tutorial, but you can also use Windows or Mac. You just need to adapt the instructions to your particular situation. Since I don’t use Windows or Mac, unfortunately, I can’t provide you with instructions.

Android Studio is written in Java and you are also going to write in Java for this tutorial so you need to install the Java Development Kit (JDK) also. Follow this link and download the version for your system:

We will deploy your “Hello” app directly into your phone. For that reason, you need to enable USB debugging on your device, which is only available if you have your device in developer mode.

To enable “Developer mode” you need to go to Settings > About phone and tap “Build number” until a toast displays that you're a developer. Then, in the previous screen you'll see a new entry called "Developer options" and there you should enable "USB debugging".

Creating your first Android project

So, assuming that you have already installed Android Studio, let’s create a new project. I’ll use screenshots to make it easier for you to follow up with the steps.

pi
© AndroidPIT

We’re going to name our project HelloAndroidPIT. Module name, Package name and Project Location get filled in automatically and you don’t need to change them.

What we’re going to change is the minimum required SDK to API 15 (Android 4.0.3 IceCreamSandwich). Yes, we’re going to ignore Android 2.3 (API 8) which will hopefully die by mid-2014. I know that currently Android 2.3 still has 26.3% of market share, but I’m confident that it will start dropping very quickly after Christmas. If you want to know more about the percentage of users each Android version has, please consult this page.

Our target SDK will be KitKat and you can choose either Java 6 or 7. Support for Java 7 is very recent and some features are only available if your minimum required SDK is 19. Which won’t happen soon probably.

Since we’re not going to create a custom icon, please uncheck that checkbox.

After pressing next, you’ll see this screen:

pi1
© AndroidPIT

Just press Next again and you’ll see another screen…

Ignore all those fields and just press Finish.

After completing these steps, connect your device to your computer, press the green Play button and the auto-generated code should compile, get deployed to your device and run.

Now that the app is running it should display “Hello world”. Saying hello to the world is nice, but we'll say hello to AndroidPIT also.

pi4
© AndroidPIT

Hello AndroidPIT

Now, to say hello to AndroidPIT you just need to open the strings.xml file inside your values folder which is found inside your res folder. You should see the string there which says “Hello World!”. Simply change it to Hello AndroidPIT and press Play again.

pi5
© AndroidPIT

Localization (L10n)

Localization (usually abbreviated to L10n) is very important nowadays. We're not in the age where software was only available in English anymore, so it's important to know how Android deals with L10n.

Since I'm from Lisbon, Portugal, living in Berlin, Germany but speaking English everyday at the office (yes, German is not easy to learn), we will learn how to say “hello” in all those three languages.

If you look to your values folder in your project you see that there is a strings.xml file there.

To add other languages you just need to add a values folder followed by a dash and the codename of the country to your res folder inside your project, for example: values-pt and values-de. Copy the strings.xml file from the default values folder to each of those two folders and then edit each of those files and replace “Hello AndroidPIT” with “Hallo AndroidPIT” and “Olá AndroidPIT” for German (values-de) and Portuguese (values-pt) respectively.

If you change the language on your device and run the app again, you should see the app translated.

I hope that this tutorial has made you excited to learn about Android development. The next article that I might possibly write will be about displaying how to display AndroidPIT news articles. What do you think about that?

Please let me know if you liked the article in the comments below.

Related Topics

From the forum. Join the discussion now!

Comments

Write new comment:
  • Bruno Zatta 11 months ago Link

    Great tutorial I've always been curious and now I'm feeling pretty inspired to research and learn.

    1
  • Amit 11 months ago Link

    good start.. will wait for next one... good idea for next tutorial. . PIT News...

    2
  • Amit 11 months ago Link

    thank you very much

    1
  • Luis Costa 11 months ago Link

    Obrigado :)
    Keep it coming!

    2
  • Jacques Peloquin 11 months ago Link

    The Application "Unexpectedly Quit" each time after "Finish" is pressed. I'm working on the Mac version of Android Studio. I updated the Studio to 0.3.6 (latest) and still Quit. I also noticed that the second and third blocks (module name and package name) did not change with the Project name as in this demo.... is it a problem.... do I have to write it manually? I don't know. :-(

    0
  • Oku Tain 11 months ago Link

    Thank you for the article. This is the first time to read such a subject. I like it and I am very excited to follow the instructions. Give us further lessons of making apps.

    1
  • Szabolcs Husz 11 months ago Link

    Wow, great, thanks! :D Looking forward to some other tutorials too, but take it easy, most of us never developed for Android, so let's go slow :)

    1
  • Christopher Ballenger 11 months ago Link

    Please, make another tutorial. Thank you so much.

    1
  • User picture
    Mod
    Henrique Rocha 11 months ago Link

    The next tutorial will be about showing the RSS feed of the AndroidPIT website.

    0
  • Cris Alves 11 months ago Link

    Looking forward to the next tutorial. I presently program on Android studio but I am a newbie so I need lots of fun help :-)

    0
  • Corbau Kazaki 11 months ago Link

    that so much easy from programig with androidapp inventor

    0
  • User picture
    Mod
    Henrique Rocha 10 months ago Link

    Don't forget to check out the second article in this series: http://www.androidpit.com/java-guide-2-program-your-own-rss-reader

    0
  • Daniel Lipinski 10 months ago Link

    Is this article missing the screen shot after the "New Project" screen.

    A sentence under that screen says:

    [ Just press Next again and you’ll see this screen… ] {but nothing is here}

    The next sentence I see is:

    [ Ignore all those fields and just press Finish. ]

    After this, you go on to describe the transfer of the app to the android device:

    [ After completing these steps, connect your device to your computer, press the green Play button and the auto-generated code should compile, get deployed to your device and run. ]

    But, nowhere do I see where any code is entered that would have the app say "Hello World!". It seems something is missing from this article. How else does the "Hello World" text get entered into the HelloAndroidPIT app?

    0
    • User picture
      Admin
      Kris Carlon 10 months ago Link

      Hi @Daniel, I've changed the text so the (unnecessary) screenshot isn't referred to. You don't need to worry about those fields so after the first screen just hit next and then Finish.

      As for the ''Hello world'' text, I believe it is a default value in the strings.xml folder. It's there if you click on the strings folder. And you can of course change it to whatever you like.

      0
      • Daniel Lipinski 10 months ago Link

        @Kris: Thank you! Very good. Yes, I noticed the "Hello World!" text is part of the sample project source code. All seems well on the Android Studio and PC based VM, but I have not been able to get the APP to go to my devices (One, a Huawei U8800-51 but it is running Android Version 2.2.2, so perhaps it cannot accept the APP. The other device is an HP Slate 7 with Android Version 4.1.1. It does not support OTG cable connections either, so maybe it does not allow transfer of the APP when connected via USB either. Does anyone here at the AndroidPIT know if these could be the reasons for the lack of transfer to the device?

        UPDATE: 03/08/2014 - The connection to my devices now works. I needed to install special drivers for the tablet I am connecting (a Nook Color, but it is usings N2A (Nook to Android) and emulates a Nexus 7). The phone was also now recognized. I actually moved my development environment to a desktop running Ubuntu 13.10. I did some Google searching to find the right drivers for my hardware. Seek, and you shall find!

        After being successful on Ubuntu, I went back to a laptop running Windows 8.1 and was also able to locate drivers that allowed both devices to be connected. The HP Slate 7 Tablet still is not recognized, and that problem is the lack of OTG support in the HP USB interface.

        0
  • ifrah A/rahman 10 months ago Link

    i want to install my laptop android studio is there any things i need before it , but i have already installed my laptop (jdk1.7.0_07) and eclipse java EE IDE and the OS of my laptop is windwos7 so please help me how to install android studio

    0
    • User picture
      Admin
      Kris Carlon 10 months ago Link

      Hi @ifrah, there's nothing else you need to install Android Studio. You simply need to follow the link and hit the "Download Android Studio for Windows" button. There is the following known issue though:

      On some Windows systems, the launcher script does not find where Java is installed. If you encounter this problem, you need to set an environment variable indicating the correct location.
      Select Start menu > Computer > System Properties > Advanced System Properties. Then open Advanced tab > Environment Variables and add a new system variable JAVA_HOME that points to your JDK folder, for example C:\Program Files\Java\jdk1.7.0_21.

      0
  • Daniel Lipinski 10 months ago Link

    @ifrah A/rahman: The Android Studio link in the article has the information you need to know to install Android Studio.

    0
  • Ayush Katoch 8 months ago Link

    after clicking on the finish and connecting my phone to the computer nothing happens please help

    0
  • Daniel Lipinski 8 months ago Link

    @Ayush Katoch: To connect devices to the Android Development environment see "Using Hardware Devices" at http://developer.android.com/tools/device.html ... Note: Your device may also require special drivers. Check that out too.

    0
  • Do Xa 8 months ago Link

    For the localization part, I advise developers to use an online tool to simplify the translation process. https://poeditor.com/ is a good choice in this sense if you ask me.

    0
  • Abhinav kumar Singh 8 months ago Link

    to make app with more feature which program i have to learn???
    http://www.unzipweb.com

    0
  • pdxevergreen 7 months ago Link

    I agree that tutorials are the best way to learn app creation.
    Donna
    Website Owner
    http://easyappcreation.com

    0
  • yash khanvilkar 7 months ago Link

    how to i go to ur second tut now?

    0
  • Sonia Mesquita 6 months ago Link

    I keep receiving the same error message, but I can't figure it out what is wrong. Could you help me?
    I have a Windows 8.1 system, 64-bit system type, if it helps.

    Error message bellow:
    Error:Gradle: A problem occurred configuring root project 'HelloAndroidPIT'.
    > Could not resolve all dependencies for configuration ':classpath'.
    > Could not resolve com.android.tools.build:gradle:0.9.+.
    Required by:
    :HelloAndroidPIT:unspecified
    > Failed to list versions for com.android.tools.build:gradle.
    > Could not list versions using M2 pattern 'http://repo1.maven.org/maven2/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]'.
    > Could not GET 'http://repo1.maven.org/maven2/com/android/tools/build/gradle/'.
    > Connection reset

    0
  • Russell Winkler 4 months ago Link

    Great tutorial! Since this article was written 7 months ago I wanted to add a few updates that I found while following it however. There is now a JDK version 8 available from oracle at http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

    The second thing is that the Android Studio download is out of date upon download. This disables access to the SDK Manager initially so if you are following the tutorial in the link you will get stuck there. Go to Configure->Settings and select Updates near the bottom of the left window. Once the update is complete it will ask you to restart Android Studio and once it is up the SDK Manager will be available again.

    Again great tutorial! Can't wait to check out part 2!

    0