<p>In this article, we will talk about how to get started with the very first android application <strong>HelloWorld</strong>. 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.</p>
<h3 id="title" class="style-scope google-codelab-step"><strong><span class="style-scope google-codelab-step" style="color: #000080;">Install Android Studio</span></strong></h3>
<p>Android Studio provides a complete integrated development environment (IDE) including an advanced code editor and a set of app templates.<br />
In addition, it contains tools for development, debugging, testing, and performance that make it faster and easier to develop apps.<br />
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.</p>
<p>Note: Android Studio is continually being improved. For the latest information on system requirements and installation instructions, see<strong><span style="color: #008000;"><a style="color: #008000;" href="https://developer.android.com/studio/index.html"> Android Studio</a></span></strong>.</p>
<h3><span style="color: #000080;"><strong>Create Android Application <span class="style-scope google-codelab-step">Hello World</span></strong></span></h3>
<ul type="1">
<li>To create a simple Android Application using Android studio firstly click on Android studio icon <img class="alignnone wp-image-1127" src="https://c1ctech.com/wp-content/uploads/2019/07/android-150x150.jpg" alt="android" width="19" height="19" /> . It will show the welcome screen as shown below:</li>
</ul>
<p style="padding-left: 60px;"><img class=" size-full wp-image-1117 aligncenter" src="https://c1ctech.com/wp-content/uploads/2019/07/start_android_proj_nnew.png" alt="start_android_proj_nnew" width="972" height="598" /></p>
<ul>
<li>In welcome screen on the left side it is showing the list of projects you have but the first time it is empty.</li>
<li>In the <span style="color: #0000ff;"><strong>Welcome to Android Studio</strong></span> window, click on <strong><span style="color: #008000;">Start a new Android Studio project</span>.</strong></li>
</ul>
<p style="padding-left: 60px;"><img class=" size-full wp-image-1115 aligncenter" src="https://c1ctech.com/wp-content/uploads/2019/07/start_android_proj_new-3242295379-1562237615237.png" alt="start_android_proj_new" width="971" height="594" /></p>
<p> Or if you have a project opened, select <span style="color: #008000;"><strong>File >; New >; New Project</strong></span>.</p>
<ul type="1">
<li>Now<strong><span style="color: #0000ff;"> Choose your project</span> </strong>window appears. Select <strong><span style="color: #008000;">Phone and Tablet</span></strong> tab to create an application for phone and tablet. To create an app for smartwatches, select <strong><span style="color: #008000;">Wear OS</span></strong>, for TV applications select <strong><span style="color: #008000;">TV</span></strong> or you can select the other two options also ie. Android Auto and Android Things.</li>
<li>In the <strong><span style="color: #008000;">Phone and Tablet</span></strong> tab, Android Studio provides Activity templates to help you get started. An Android activity is one screen of the Android app&#8217;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 <span style="color: #0000ff;"><strong>HelloWorld</strong></span> project, Inside <strong><span style="color: #008000;">Phone and Tablet</span></strong> tab choose <strong><span style="color: #008000;">Empty Activity</span></strong> as shown below, and click <span style="color: #008000;"><strong>Next</strong></span>.</li>
</ul>
<p style="padding-left: 60px;"><img class="alignnone size-full wp-image-1118" src="https://c1ctech.com/wp-content/uploads/2019/07/create_new_project.png" alt="create_new_project" width="1127" height="853" /></p>
<ul type="1">
<li>Now a new <strong><span style="color: #0000ff;">Configure your project</span> </strong>window will open. It will ask you about your Application name, package name, and location of the project. Enter <span style="color: #0000ff;"><strong>HelloWorld</strong></span><span style="color: var(--color-text);"> for the </span><span style="color: #008000;"><strong>Application name</strong></span><span style="color: var(--color-text);">.</span></li>
</ul>
<p style="padding-left: 60px;"><img class="alignnone size-full wp-image-1119" src="https://c1ctech.com/wp-content/uploads/2019/07/configure_project_new.png" alt="configure_project_new" width="1070" height="783" /></p>
<ul type="1">
<li>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 <span style="color: #008000;"><strong>com.c1ctech.helloworld</strong></span>.</li>
<li>Verify that the default <span style="color: #008000;"><strong>Project location</strong></span> is where you want to store your Hello World app and other Android Studio projects or change it to your preferred directory.</li>
<li>Select the language in which you want to create the application ie. <span style="color: #0000ff;"><strong>Java</strong></span> or <span style="color: #0000ff;"><strong>kotlin</strong></span>.</li>
<li>The default minimum API level selected is <span style="color: #008000;"><strong>API 21: Android 5.0(Lollipop)</strong></span>, 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.</li>
<li>Leave unchecked <span style="color: #008000;"><strong>This project will support Instant apps</strong></span>. If your project requires additional components for your chosen target SDK, Android Studio will install them automatically.</li>
</ul>
<ul>
<li>Click <span style="color: #008000;"><strong>Finish</strong></span>.</li>
</ul>
<h3><span style="color: #000080;"><strong>Explore the Project structure of HelloWorld</strong></span></h3>
<p>Now we will explore how the project is organized in Android Studio.</p>
<ul type="1">
<li>When you first create an app project, the <span style="color: #008000;"><strong>Project >; Android</strong></span> pane appears with the <span style="color: #0000ff;"><strong>app</strong></span> and <span style="color: #0000ff;"><strong>Gradle Scripts</strong></span> folder as shown below.</li>
</ul>
<p style="padding-left: 60px;"><img class="alignnone size-full wp-image-1133" src="https://c1ctech.com/wp-content/uploads/2019/07/android_folder_new.png" alt="android_folder_new" width="445" height="356" /></p>
<ul>
<li>The expanded form of <span style="color: #0000ff;"><strong>app</strong></span> and <span style="color: #0000ff;"><strong>Gradle Scripts</strong></span> folder of <span style="color: #008000;"><strong>HelloWorld</strong></span> application as shown below:</li>
</ul>
<figure id="attachment_1138" aria-describedby="caption-attachment-1138" style="width: 637px" class="wp-caption aligncenter"><img class="alignnone size-full wp-image-1138" src="https://c1ctech.com/wp-content/uploads/2019/07/and_proj_stru-3530591771-1562675165112.png" alt="and_proj_stru" width="637" height="777" /><figcaption id="caption-attachment-1138" class="wp-caption-text"><span style="color: #000080;"><strong>Application level project structure</strong></span></figcaption></figure>
<p> ;</p>
<p>1. <span style="color: #0000ff;"><strong>AndroidManifest.xml</strong>:</span></p>
<p>Every project in Android includes a manifest file, which is <a href="https://www.geeksforgeeks.org/application-manifest-file-android/"><span style="color: #008000;"><strong>AndroidManifest.xml</strong></span> </a>, stored in the <strong><span style="color: #008000;">app>;manifests</span></strong> 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.</p>
<p>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).</p>
<p>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&#8217;t provide the features or system version that your app requires.</p>
<p>The default <span style="color: #008000;"><strong>AndroidManifest.xml</strong> </span>file looks like as shown below:</p>
<p><span style="color: #000080;"><strong>AndroidManifest.xml</strong></span></p>
<pre><strong><;?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>;</strong></pre>
<p> ;</p>
<p>2. <span style="color: #0000ff;"><strong>Java</strong></span> :</p>
<p>The <span style="color: #008000;"><strong>java</strong></span> folder includes Java class files in three subfolders.The <span style="color: #008000;"><strong>com.c1ctech.helloworld</strong></span> (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 <span style="color: #0000ff;"><strong>com.c1ctech.helloworld</strong></span> contains <strong><span style="color: #008000;">MainActivity.java </span></strong><span style="color: #000000;">which is t</span>he name of the first <span style="color: #008000;"><strong>Activity</strong></span> (screen) the user sees.</p>
<p><span style="color: #000080;"><strong>MainActivity.java</strong></span></p>
<pre><strong>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);
 }
}</strong></pre>
<p>3. <span style="color: #0000ff;"><b>drawable</b></span>:</p>
<p>This folder contains drawable resources which define various graphics with bitmaps(PNG, JPEG) or XML. Drawable resources are accessed from the <strong><span style="color: #008000;">R.drawable</span></strong> class.</p>
<p>4. <span style="color: #0000ff;"><strong>layout</strong></span>:</p>
<p>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 <strong><span style="color: #008000;">R.layout</span></strong> class. By default it contains <span style="color: #008000;"><strong>activity_main.xml</strong></span> layout corresponding to <span style="color: #008000;"><strong>MainActivity.java</strong></span> looks like as shown below:</p>
<p><strong><span style="color: #0000ff;">activity_main.xml</span></strong></p>
<pre><strong><;?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>;</strong></pre>
<p>5. <span style="color: #0000ff;"><strong>mipmap</strong></span>:</p>
<p>The <strong><span style="color: #008000;">res/mipmap </span></strong>contains your app-launcher icons (icon displayed on the home screen) for various screen resolutions.</p>
<p>6. <span style="color: #0000ff;"><strong>values</strong></span>:</p>
<p>The <strong><span style="color: #008000;">res/values</span> </strong>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.</p>
<p>7. <strong><span style="color: #0000ff;">colors.xml</span></strong>:</p>
<!-- WP QUADS Content Ad Plugin v. 2.0.98.1 -->
<div class="quads-location quads-ad2" id="quads-ad2" style="float:none;margin:0px;">

</div>

<p>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.</p>
<pre><strong><;?xml version="1.0" encoding="utf-8"?>;
<;resources>;
 <;color name="colorPrimary">;#008577<;/color>;
 <;color name="colorPrimaryDark">;#00574B<;/color>;
 <;color name="colorAccent">;#D81B60<;/color>;
<;/resources>;</strong></pre>
<p>8. <strong><span style="color: #0000ff;">strings.xml</span></strong>:</p>
<p>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.</p>
<pre><strong><;resources>;
 <;string name="app_name">;HelloWorld<;/string>;
<;/resources>;</strong></pre>
<p>9. <strong><span style="color: #0000ff;">style.xml</span></strong>:</p>
<p>style.xml is used to define the look and format for a UI . A style can be applied to an individual <strong><span style="color: #008000;">View</span></strong> (from within a layout file) or to an entire <span style="color: #008000;"><strong>Activity</strong></span> or application (from within the manifest file).</p>
<pre><strong><;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>;</strong></pre>
<p> ;</p>
<p>10. <b><span style="color: #0000ff;">build.gradle(Project: helloworld)</span>:</b></p>
<p><b> </b>This is where you&#8217;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&#8217;t need to make any changes to this file, but it&#8217;s still useful to understand its contents.</p>
<p>Given below is the <span style="color: #008000;"><strong>build.gradle(<b>Project: helloworld</b>)</strong></span> file for the HelloWorld app:</p>
<pre><strong><span style="color: #008000;">// Top-level build file where you can add configuration options common to all sub-projects/modules.</span>

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
}</strong></pre>
<p><b>11. <span style="color: #0000ff;">build.gradle(Module: app)</span></b>:</p>
<p>This file defines the module-specific build configurations. In addition to the project-level <code>build.gradle</code> file, each module has a <code>build.gradle</code> file of its own, which allows you to configure build settings for each specific module (the HelloWorld app has only one module).</p>
<p>Given below is the <span style="color: #008000;"><strong>build.gradle(Module:app)</strong></span> file for the HelloWorld app:</p>
<pre><strong>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'
}</strong></pre>
<p> ;</p>
<h3><span style="color: #000080;"><strong>Running the Application</strong></span></h3>
<p>Let&#8217;s try to run our <b><span style="color: #008000;">HelloWorld</span>!</b> application we just created.</p>
<h4 id="title" class="style-scope google-codelab-step"><span style="color: #000080;"><strong><span class="style-scope google-codelab-step">Use a virtual device (emulator)</span></strong></span></h4>
<p>Before running the application on virtual device firstly we will use the <span style="color: #008000;"><strong><a style="color: #008000;" href="http://developer.android.com/tools/devices/managing-avds.html">Android Virtual Device (AVD) manager</a></strong></span> 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.</p>
<p>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.</p>
<h5><span style="color: #0000ff;"><strong> Create an Android virtual device (AVD)</strong></span></h5>
<p>In order to run an emulator on your computer, you have to create a configuration that describes the virtual device.</p>
<ul>
<li>In Android Studio, select <span style="color: #008000;"><strong>Tools >; Android >; AVD Manager</strong></span>, or click the AVD Manager icon <img class="alignnone wp-image-1128" src="https://c1ctech.com/wp-content/uploads/2019/07/avd.png" alt="avd" width="26" height="26" /> in the toolbar. The <strong><span style="color: #0000ff;">Your Virtual Devices</span> </strong>screen appears. If you&#8217;ve already created virtual devices, the screen shows them (as shown in the figure below); otherwise you see a blank list.</li>
</ul>
<p style="padding-left: 30px;"><img class="alignnone size-full wp-image-1120" src="https://c1ctech.com/wp-content/uploads/2019/07/virtual_device.png" alt="virtual_device" width="1211" height="656" /></p>
<ul>
<li>Click the<span style="color: #008000;"><strong> +Create Virtual Device</strong></span>. The <span style="color: #0000ff;"><strong>Select Hardware</strong></span> window appears showing a list of pre-configured hardware devices. For each device, the table provides a column for its diagonal display size (<strong>Size</strong>), screen resolution in pixels (<strong>Resolution</strong>), and pixel density (<strong>Density</strong>).</li>
</ul>
<p style="padding-left: 30px;"><img class="alignnone size-full wp-image-1121" src="https://c1ctech.com/wp-content/uploads/2019/07/select_hardware-3975169854-1562264392207.png" alt="select_hardware" width="1120" height="776" /></p>
<ul>
<li>Choose a device such as <strong>Nexus 5</strong> or <strong>Pixel XL</strong>, and click <span style="color: #008000;"><strong>Next</strong></span>. The <span style="color: #0000ff;"><strong>System Image </strong></span>screen appears.</li>
</ul>
<p style="padding-left: 30px;"><img class="alignnone size-full wp-image-1123" src="https://c1ctech.com/wp-content/uploads/2019/07/system_image.png" alt="system_image" width="1047" height="828" /></p>
<ul>
<li>Click the <span style="color: #008000;"><strong>Recommended</strong></span> tab if it is not already selected, and choose which version of the Android system to run on the virtual device (such as <strong>Oreo</strong>).There are many more versions available than shown in the <strong style="color: var(--color-text);">Recommended</strong><span style="color: var(--color-text);"> tab. Look at the </span><strong style="color: var(--color-text);">x86 Images</strong><span style="color: var(--color-text);"> and </span><strong style="color: var(--color-text);">Other Images </strong><span style="color: var(--color-text);">tabs to see them.</span></li>
<li>If a <strong>Download</strong> 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 <strong>Finish</strong> when it&#8217;s done.</li>
<li>After choosing a system image, click <span style="color: #008000;"><strong>Next</strong></span>. The <span style="color: #0000ff;"><strong>Android Virtual Device (AVD)</strong></span> window appears. You can also change the name of the AVD. Check your configuration and click <span style="color: #008000;"><strong>Finish</strong></span>.</li>
</ul>
<p style="padding-left: 30px;"><img class="alignnone size-full wp-image-1124" src="https://c1ctech.com/wp-content/uploads/2019/07/avd_window.png" alt="avd_window" width="1048" height="784" /></p>
<h5></h5>
<h5><span style="color: #0000ff;"><strong>Run the app on the virtual device</strong></span></h5>
<p>Now you will finally run your HelloWorld app.</p>
<ol>
<li>In Android Studio, choose <span style="color: #008000;"><strong>Run >; Run app</strong></span> or click the <span style="color: #008000;"><strong>Run</strong></span> icon in the toolbar.</li>
<li>The <span style="color: #0000ff;"><strong>Select Deployment Target</strong></span> window, under <span style="color: #008000;"><strong>Available Virtual Devices</strong></span>, select the virtual device, which you just created, and click <span style="color: #008000;"><strong>OK</strong></span>.</li>
</ol>
<p><img class="alignnone size-full wp-image-1125" src="https://c1ctech.com/wp-content/uploads/2019/07/select_device-1.png" alt="select_device" width="781" height="606" /></p>
<p>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.</p>
<p>You should see the <strong><span style="color: #008000;">HelloWorld</span></strong> app as shown in the following figure.</p>
<p><img class="alignnone wp-image-1126" src="https://c1ctech.com/wp-content/uploads/2019/07/Screenshot_1562244111-576x1024.png" alt="Screenshot_1562244111" width="356" height="633" /></p>
<h4 id="title" class="style-scope google-codelab-step"><span style="color: #000080;"><strong><span class="style-scope google-codelab-step">Use a physical device</span></strong></span></h4>
<p>Now we will talk about how to run the application on a physical mobile device such as a phone or tablet.</p>
<p>What you need:</p>
<ul>
<li>An Android device such as a phone or tablet.</li>
<li>A data cable to connect your Android device to your computer via the USB port.</li>
<li>If you are using a Linux or Windows system, you may need to perform additional steps to run on a hardware device. Check the <strong><span style="color: #0000ff;"><a style="color: #0000ff;" href="http://developer.android.com/tools/device.html">Using Hardware Devices</a></span></strong> documentation. You may also need to install the appropriate USB driver for your device. For Windows-based USB drivers, see <strong><span style="color: #0000ff;"><a style="color: #0000ff;" href="http://developer.android.com/tools/extras/oem-usb.html">OEM USB Drivers</a>.</span></strong></li>
</ul>
<h5><span style="color: #0000ff;"><strong>Turn on USB debugging</strong></span></h5>
<p>To let Android Studio communicate with your device, you must turn on USB Debugging on your Android device. This is enabled in the <span style="color: #008000;"><strong>Developer options</strong></span> settings of your device.</p>
<p>On Android 4.2 and higher, the <strong>Developer options</strong> screen is hidden by default. To show developer options and enable USB Debugging:</p>
<ol>
<li>On your device, open <span style="color: #008000;"><strong>Settings</strong></span>, search for<strong> <span style="color: #008000;">About phone</span></strong>, click on <strong>About phone</strong>, and tap <span style="color: #008000;"><strong>Build number</strong></span> seven times.</li>
<li>Return to the previous screen (<strong>Settings / System</strong>). <span style="color: #008000;"><strong>Developer options</strong></span> appears in the list. Tap <strong>Developer options</strong>.</li>
<li>Choose <span style="color: #008000;"><strong>USB Debugging</strong></span>.</li>
</ol>
<h5><strong> <span style="color: #0000ff;">Run your app on a device</span></strong></h5>
<p>Now you can connect your device and run the app from Android Studio.</p>
<ol>
<li>Connect your device to your development machine with a USB cable.</li>
<li>Click the <span style="color: #008000;"><strong>Run</strong></span> button in the toolbar. The <strong><span style="color: #008000;">Select Deployment Target</span> </strong>window opens with the list of available emulators and connected devices.</li>
<li>Select your device, and click <span style="color: #008000;"><strong>OK</strong></span>.</li>
</ol>
<p>Android Studio installs and runs the app on your device.</p>
<p>I hope this article will help you in understanding how to get started with your Android application.

