How to create an Android app

Content (Click to view)
  1. Android app
  2. Install Android Studio
  3. Create a new project in Android Studio
  4. How to create an Android app from scratch
  5. How to create a game for Android
    1. Download LibGDX and create a new project for an Android game
    2. Clone a game for LibGDX from Github
  6. Learn how to program applications for Android
  7. You may be interested:

Android app

Before you get scared, I'll tell you that creating your first application is very easy. The difficult thing is to create a good app and, above all, to have a good idea to carry it out until it becomes an application.

Android app

The tools you need to create an Android app are free and available to everyone. Without further ado we are going to create our first "Hello World" application.

From these links you can quickly access the different sections:

Before you get scared, I'll tell you that creating your first application is very easy. The difficult thing is to create a good app and, above all, to have a good idea to carry it out until it becomes an application.

The tools you need to create an Android app are free and available to everyone. Without further ado we are going to create our first "Hello World" application. From these links you can quickly access the different sections:

Install Android Studio

To create an app the first thing we need is Android Studio. It is the official program to develop applications for Android, created and recommended by Google itself.

From the official website of Android Developers we can download Android Studio for any platform: Windows, Mac OS and Linux. We also need to have the latest Java JDK installed. When installing Android Studio will ask us the route where we have installed this JDK.

Anyone can create an Android app in minutes

To develop an Android application we need to know two programming languages: XML and Java. XML is just a layout language (similar to HTML) with which we will create the visual part of our application.

Java is a programming language with which we will create the operation below what we see. That is to say, with XML we draw the button and Java does the magic when we press it. Parallel to Java, Android Studio also supports C++ and Kotlin, since September 2017.

Once everything is installed, let's get to work!

Create a new project in Android Studio

Android Studio may take a while to load. The first time we start it it will greet us with a screen similar to the one we have here below.

An application is created from a good number of files and folders so to make our application we need to generate a new project. Selecting 'Start a new Android Studio project' will generate everything you need to create our application.

Once you have selected a new project, you will need to name it 'Application Name'. You can name it whatever you want. I'm gonna call it "HelloAndroidPIT."

The next line, 'Company Domain', is to put the developer code that Google gives us to publish our applications on Google Play.

As we are not going to place it in Play Store we can leave this line as it is. The last line is the path where this project is saved on the hard disk, it is also better to leave it as it is. Once ready click on 'Next', which is at the bottom right.

In the next window we are going to choose the device to which we are going to destine our application, from a smartphone or tablet to Google Glass. Once we have chosen the type of device we have to choose the API level.

This means that if we choose API 23 Android 6.0 (Marshmallow) for our application, it will not work with devices that have a version lower than this, that is, the vast majority of devices. This is often a delicate decision point. For our application we can leave it in API 15 and click on 'Next'.

Now you can name the main activity, which will be shown above in our application. You can name it after your application. I'm going to name it "HelloAndroidPIT". Then all you have to do is click on 'Finish'.

How to create an Android app from scratch

Once the project is created, we will have a window in which to the left we find the tree with the project's folders and files. At the beginning the file with extension.

xml of our main activity that is inside the folder 'layout' will be selected. To the right is shown what the file contains and there are two tabs at the bottom to view it.

One is 'Design' which shows the design of what our app would look like, where we can also pick up other components such as buttons from the left menu and drop them onto the smartphone screen.

The other tab is 'Text' and here is the XML code of all the layout of the different elements that we have in the activity. If you want your application to work well you're going to look more at the code than the designer.

We're going to stay in the 'Design' tab and now we're going to change the text that appears at the top right. Select it with the mouse.

It will be marked with a blue box. Press any letter and you will be able to modify the text. Write whatever you want. To continue with the custom I have put "Hello AndroidPIT".

The letter seems a little small to me so I'm going to put it bigger in the 'textSize' section in the 'Properties' box and put 35dp.

In 'textStyle' I'm going to mark 'bold' to put it in bold. And I'm also going to center it on the screen by dragging the text with the mouse.

In the component tree, 'Componet Tree', above the properties, our text has a small yellow warning triangle.

Android Studio informs you of possible code errors and even spelling mistakes. By default, it only corrects English and if we write in another language it will mark it as an error. It can be configured to detect other languages but for now we will not bother.

Just above the preview of the device we can change it to see how it looks in the different screen sizes of the Nexus both smartphones and tablets. Display the list and try switching to another device, a Nexus 9 or a Nexus 6P.

If you have a notice of rendering problems and the device is not displayed you can change the API display a little further to the right in the green android icon with a number.

We are now ready to pass our first application to our device. On the smartphone you activate the development options and within them you activate the 'USB Debugging'. Connect your smartphone to your computer with a USB cable.

In Android Studio, at the top of the icon bar look for the play symbol, it is a green triangle to the right of an android next to the word 'app'.

Press the triangle, the ADB will start. A window will appear with our selected device and click on 'OK'. And voilĂ ! We already have our app running on our smartphone.

How to create a game for Android

To create a game for Android we need a graphic engine that allows to manage "easily" the handling of images, something that only with Java can become complicated.

To make life easier for us, there are several Frameworks (frameworks with tools that make life easier) that offer us very powerful graphic engines. My recommendation is: for 2D LibGDX games and for 3D Unity games.

Learning each of these frameworks takes some time. Here we'll focus on how to create a project for a 2D game with LibGDX and we'll also clone an opensource example game from Github that we can learn from.

Download LibGDX and create a new project for an Android game

The first thing is to download LibGDX from its official website. Here we press 'Download Setup App' and save it in a folder on the computer.

When the download is finished we will find a Java application in the destination folder. Double click on this application to run it. The panel will open to create a project with LibGDX.

Here we are going to name the game in 'Name' (Super Mariano Bros, for example), the package with our name followed by the game (for example, com.luis.supermarianobros), the name of the class cannot have spaces (for example, SuperMarianoBros).

Then we will choose the destination folder of the project (I recommend creating a folder with the project inside the folder where we have our Android Studio projects), and very important, the folder where we have installed the Android Studio SDK (you can check in Android Studio in Tools > Android > SDK Manager > Android SDK Location).

In the 'Sub Projects' we will leave marked only Android and 'Extensions' can stay as is. Finally, we only have to click on 'Generate' to generate the whole project, it needs to have an Internet connection because it downloads some libraries that we need.

Now we go to Android Studio to open the project we just created. File > Open, we look for the folder of our project and open it.

The main code will be written inside the core/java/name.of.the.package/PackageName (in my case it would be core/java/com.luis.supermarianobros/SuperMarianoBros).

In it we find several methods: 'create' serves to start all the images and tools we are going to use, 'render' is the part that runs without stopping several times per second where we will put the action of the game and 'dispose' where we will free the GPU of all the images that we load in 'create'.

If we run this game on our smartphone we will see an image with the bottom corner placed at point 0.0 of the coordinate axis.

Clone a game for LibGDX from Github

To create your own game you first have to have an idea and then we need to know a little about the functioning of the framework we are using, in this case LibGDX. Therefore, the easiest thing to learn is to use an example.

At GitHub and other Internet sites we can find open source game code to learn from. To clone a game you just have to do a quick search in GitHub, there you will see some interesting projects. In libgdx's own repository there are already some examples.

We're going to clone as an example the game of the plane that couldn't fly well "The plane that couldn't fly good". Go to The plane that couldn't fly good repository and in the upper right corner there is a green button that says 'Clone or Download'. If we already have a linked GitHub account in Android Studio we can clone the repository directly.

If not, we will simply download it as a .zip file. Now unzip the file and place the folder it contains inside your Android Studio project folder and open it in Android Studio.

Android Studio messages may ask you to install some components, just click on the warning and they will be installed automatically.

Now you can connect your smartphone to your computer with a USB cable, run the game on the device and fly! From here you'll be able to learn how LibGDX works from the sample code and you can also search for tutorials on this great library on Youtube.

Learn how to program applications for Android

If you're curious, this may not be enough for you. The world of programming is something very fun where you can get spectacular things and a lot of satisfaction.

To continue learning, if you don't know anything about programming and you want to start with Android, I recommend the Android Development for Beginners course from Udacity. It is in English but considering that the world of programming moves in this language, the sooner you get used to it the better.

Of course, there are also many tutorials on YouTube with which to learn self-taught. And don't forget that you have behind you all the support of the large and wonderful android community.

You may be interested:

Which are the best browsers for Android 

How to choose Spotify songs as an alarm clock on your phone 

How to easily rotate a video with this application 

Know if your emails have been read 

Go up

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site, we will assume that you agree to it. You can also click Accept, to consent to the use of all cookies. Read More...