Hello friends, in this tutorial I will teach you how to build first android app with the help of android hello world example. I hope that before reading this tutorial you have already installed Android Studio and done environment setup that I have taught in last tutorial. If you have not done it yet then you can read it from below link.
Android Hello World Example – Build First Android App
Create Android Project
1. When you will open Android Studio for first time you will see following screen. Select Start a new Android Studio project option.
2. Now in Application name field enter the name of the application. Enter website domain in Company Domain field. Remember that the package name will be the company domain in reverse order plus name of application. You can fill these fields according to your choice. Then click Next.
3. Now in the next window it will ask for Target Android Devices. It means the minimum android version on which you want your app to run. Always keep the minimum sdk version as lower as possible, so that your app can run on maximum number of devices.
4. In the next window choose a blank activity. An activity is a screen or window in your android mobile that holds all the components like buttons, textbox, etc. Your app can have multiple activities, right now we are creating single activity app.
5. In the next window you can leave all the fields as it is. Title is the name that will be shown on the activity when we will open in mobile. Activity Name is the name of the Java file, Layout Name is the XML file. We have two files for an activity, one is a Java file that contains all the logic and working related code and another is a XML file that contains the designing related code. Remember that by default Java file name is same as activity name. If you want, you can change these files name or you can also add other activities in your app depending upon your requirement.
6. Finally click on Finish button to create the project.
Create Android Virtual Device (AVD)
AVD is a virtual device that is used to run and test android apps on computer. So before running your app you need to create a virtual device.
1. Before creating AVD you need to download some more tools and packages. So click on SDK Manager option located at top, it is shown in below screenshot.
2. Now select all the packages of an API level, always choose latest API level that is available. This is the API level on which we will run and test our apps. Now install the packages, it will take few minutes or hours to download the packages depending upon you internet speed.
3. After completing the package downloading, just click on the Android Device Monitor option located at the right side of SDK Manager option.
4. In the next window click on Android Virtual Device Manger option.
5. Now click on Create button. This will open a window to create a new virtual device. In AVD Name field enter any name, after that select a device whatever you like (I would recommend Nexus S because it is standard size device). In the Target option choose Google APIs. In Skin type, choose QVGA. You can customize your virtual device like whether you want hardware keyword or not, you can manually allocate RAM size, etc. Leave all other fields as it is. Now finally click on OK button to create the device.
6. After that select the device and click on Start button to start it. For first time it may take some time to start the device.
Note: In case you are getting any error related to intel HAXM or virtualization then check below article. There I have mentioned all possible solutions for these problems.
Run Android Project
1. When we create our new project, by default we get code to display hello world. So we don’t need to write any code.
2. For running the app just click on Run button located at the top. It will take some time to build the project.
3. Now a new window will open that will ask to choose a virtual device to run your project. Just choose the running virtual device and click on OK button.
4. Finally you can see the output as shown below.
So, this was the step by step guide to make your first android app. If you have doubts or getting any difficulty then feel free to ask it by commenting below.
Happy Coding!! 🙂 🙂