In this article, we will talk about how to get started with the very first android application HelloWorld. So step by step we will talk about how to install Android Studio, how to create android application HelloWorld, its initial project structure and then we will talk about how to create and run your first Android app, Hello World, on an emulator and on a physical device.
Install Android Studio
Android Studio provides a complete integrated development environment (IDE) including an advanced code editor and a set of app templates.
In addition, it contains tools for development, debugging, testing, and performance that make it faster and easier to develop apps.
You can test your apps with a large range of preconfigured emulators or on your own mobile device, build production apps, and publish on the Google Play store.
Note: Android Studio is continually being improved. For the latest information on system requirements and installation instructions, see Android Studio.
Create Android Application Hello World
- To create a simple Android Application using Android studio firstly click on Android studio icon
. It will show the welcome screen as shown below:
- In welcome screen on the left side it is showing the list of projects you have but the first time it is empty.
- In the Welcome to Android Studio window, click on Start a new Android Studio project.
Or if you have a project opened, select File > New > New Project.
- Now Choose your project window appears. Select Phone and Tablet tab to create an application for phone and tablet. To create an app for smartwatches, select Wear OS, for TV applications select TV or you can select the other two options also ie. Android Auto and Android Things.
- In the Phone and Tablet tab, Android Studio provides Activity templates to help you get started. An Android activity is one screen of the Android app’s user interface. It is a crucial component of any Android app. An Activity typically has a layout associated with it that defines how UI elements appear on a screen. For the HelloWorld project, Inside Phone and Tablet tab choose Empty Activity as shown below, and click Next.
- Now a new Configure your project window will open. It will ask you about your Application name, package name, and location of the project. Enter HelloWorld for the Application name.
- Enter the package name for your HelloWorld application, you can leave this field as it is or you can change it. It plays an important role when you want to publish your app on play store, it makes your app unique from other millions of application. In my case, I have changed the package name to com.c1ctech.helloworld.
- Verify that the default Project location is where you want to store your Hello World app and other Android Studio projects or change it to your preferred directory.
- Select the language in which you want to create the application ie. Java or kotlin.
- The default minimum API level selected is API 21: Android 5.0(Lollipop), it ensures that your app will only be supported by Android version 5.0 and above but you can not install this app in Android version lower than 5.0. According to your selected API level, it will show you the percent of devices in which your app will run.
- Leave unchecked This project will support Instant apps. If your project requires additional components for your chosen target SDK, Android Studio will install them automatically.
- Click Finish.
Explore the Project structure of HelloWorld
Now we will explore how the project is organized in Android Studio.
- When you first create an app project, the Project > Android pane appears with the app and Gradle Scripts folder as shown below.
- The expanded form of app and Gradle Scripts folder of HelloWorld application as shown below:

1. AndroidManifest.xml:
Every project in Android includes a manifest file, which is AndroidManifest.xml , stored in the app>manifests directory of the project structure. The manifest file is an important file of our app because it defines its components which include all activities, services, broadcast receivers, and content providers.
It describes the permission that Android apps must request to access sensitive user data (such as contacts and SMS) or certain system features (such as the camera and internet access).
It also contains information about what types of hardware or software features your app requires, and thus, which types of devices your app is compatible with. Google Play Store does not allow your app to be installed on devices that don’t provide the features or system version that your app requires.
The default AndroidManifest.xml file looks like as shown below:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.c1ctech.helloworld"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
2. Java :
The java folder includes Java class files in three subfolders.The com.c1ctech.helloworld (or the package name you have specified) folder contains all the java files for an app package. The other two folders are used for testing. Mainly, these java files get the data from the Layout file and after processing that data output will be shown in the UI layout. It works on the backend of an Android application.The com.c1ctech.helloworld contains MainActivity.java which is the name of the first Activity (screen) the user sees.
MainActivity.java
package com.c1ctech.helloworld; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
3. drawable:
This folder contains drawable resources which define various graphics with bitmaps(PNG, JPEG) or XML. Drawable resources are accessed from the R.drawable class.
4. layout:
This folder contains layout resource which defines the architecture for the UI in an Activity or a component of a UI. It can be accessed from the R.layout class. By default it contains activity_main.xml layout corresponding to MainActivity.java looks like as shown below:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout>
5. mipmap:
The res/mipmap contains your app-launcher icons (icon displayed on the home screen) for various screen resolutions.
6. values:
The res/values folder is used to store the values for the resources that are used in many Android projects to include features of color, styles, dimensions etc.
7. colors.xml:
colors.xml is used to store a color value (a hexadecimal color). Different color values are identified by a unique name that can be used in the Android application program.
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="colorPrimary">#008577</color> <color name="colorPrimaryDark">#00574B</color> <color name="colorAccent">#D81B60</color> </resources>
8. strings.xml:
strings.xml is to define the strings, string arrays in one file so that it is easy to use the same string in different positions in the android project plus it makes the project looks less messy.
<resources> <string name="app_name">HelloWorld</string> </resources>
9. style.xml:
style.xml is used to define the look and format for a UI . A style can be applied to an individual View (from within a layout file) or to an entire Activity or application (from within the manifest file).
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> </resources>
10. build.gradle(Project: helloworld):
This is where you’ll find the configuration options that are common to all of the modules that make up your project. Every Android Studio project contains a single, top-level Gradle build file. Most of the time, you won’t need to make any changes to this file, but it’s still useful to understand its contents.
Given below is the build.gradle(Project: helloworld) file for the HelloWorld app:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
11. build.gradle(Module: app):
This file defines the module-specific build configurations. In addition to the project-level build.gradle
file, each module has a build.gradle
file of its own, which allows you to configure build settings for each specific module (the HelloWorld app has only one module).
Given below is the build.gradle(Module:app) file for the HelloWorld app:
apply plugin: 'com.android.application' android { compileSdkVersion 28 defaultConfig { applicationId "com.c1ctech.helloworld" minSdkVersion 21 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' }
Running the Application
Let’s try to run our HelloWorld! application we just created.
Use a virtual device (emulator)
Before running the application on virtual device firstly we will use the Android Virtual Device (AVD) manager to create a virtual device (also known as an emulator) that simulates the configuration for a particular type of Android device, and use that virtual device to run the app.
Using the AVD Manager, you define the hardware characteristics of a device, its API level, storage, resolution and other properties and save it as a virtual device. With virtual devices, you can test apps on different device configurations (such as tablets and phones) with different API levels, without having to use physical devices.
Create an Android virtual device (AVD)
In order to run an emulator on your computer, you have to create a configuration that describes the virtual device.
- In Android Studio, select Tools > Android > AVD Manager, or click the AVD Manager icon
in the toolbar. The Your Virtual Devices screen appears. If you’ve already created virtual devices, the screen shows them (as shown in the figure below); otherwise you see a blank list.
- Click the +Create Virtual Device. The Select Hardware window appears showing a list of pre-configured hardware devices. For each device, the table provides a column for its diagonal display size (Size), screen resolution in pixels (Resolution), and pixel density (Density).
- Choose a device such as Nexus 5 or Pixel XL, and click Next. The System Image screen appears.
- Click the Recommended tab if it is not already selected, and choose which version of the Android system to run on the virtual device (such as Oreo).There are many more versions available than shown in the Recommended tab. Look at the x86 Images and Other Images tabs to see them.
- If a Download link is visible next to a system image you want to use, it is not installed yet. Click the link to start the download, and click Finish when it’s done.
- After choosing a system image, click Next. The Android Virtual Device (AVD) window appears. You can also change the name of the AVD. Check your configuration and click Finish.
Run the app on the virtual device
Now you will finally run your HelloWorld app.
- In Android Studio, choose Run > Run app or click the Run icon in the toolbar.
- The Select Deployment Target window, under Available Virtual Devices, select the virtual device, which you just created, and click OK.
The emulator starts and boots just like a physical device. Depending on the speed of your computer, this may take a while. Your app builds, and once the emulator is ready, Android Studio will upload the app to the emulator and run it.
You should see the HelloWorld app as shown in the following figure.
Use a physical device
Now we will talk about how to run the application on a physical mobile device such as a phone or tablet.
What you need:
- An Android device such as a phone or tablet.
- A data cable to connect your Android device to your computer via the USB port.
- If you are using a Linux or Windows system, you may need to perform additional steps to run on a hardware device. Check the Using Hardware Devices documentation. You may also need to install the appropriate USB driver for your device. For Windows-based USB drivers, see OEM USB Drivers.
Turn on USB debugging
To let Android Studio communicate with your device, you must turn on USB Debugging on your Android device. This is enabled in the Developer options settings of your device.
On Android 4.2 and higher, the Developer options screen is hidden by default. To show developer options and enable USB Debugging:
- On your device, open Settings, search for About phone, click on About phone, and tap Build number seven times.
- Return to the previous screen (Settings / System). Developer options appears in the list. Tap Developer options.
- Choose USB Debugging.
Run your app on a device
Now you can connect your device and run the app from Android Studio.
- Connect your device to your development machine with a USB cable.
- Click the Run button in the toolbar. The Select Deployment Target window opens with the list of available emulators and connected devices.
- Select your device, and click OK.
Android Studio installs and runs the app on your device.
I hope this article will help you in understanding how to get started with your Android application.