Codecademy Logo

Getting Started with Android Studio

Android Simulator

The Android emulator allows you to run your app on an Android virtual device (AVD), which behaves just like a physical Android device. You can set up numerous AVDs, each emulating a different type of device.

An example Android simulation, using the Android emulator and an Android Virtual Device (AVD).

The Android emulator has an AVD smartphone and a bar of device controls displayed. The AVD is displaying a live preview of a view that contains a status bar, a heading, text, and a line. 

The status bar is at the very top of the device screen. It takes up the full width of the device screen and about 2% of the device screen height. It shows the time, a settings (cog) icon, a security (shield) icon, and a file icon in the upper left corner of the bar. On the right side of the status bar there is a wifi icon, a cellular service (bars) icon, and a battery icon. The background is dark blue-green, with white font/icon color.

Under the status bar there is a heading. The heading is a medium blue-green rectangle with text. The rectangle is the width of the device screen, and about 10% of the device screen height. The text, 'My Android Diary'', is on the left side of this rectangle in white font, with padding on the left of the word 'My'. The text is centered vertically in the rectangle. 

Under the heading there is the text 'Dear Diary' in dark gray. The text is about 60% of the width of the screen and is centered vertically and horizontally (in the remaining space of the device screen). The text also takes up about 10% of the device screen's height.

Under the 'Dear Diary' text there is a thin gray line, which is also about 60% of the screen width. The line is centered horizontally, and is a distance of about 20% (of the screen height) above the bottom of the view. 

At the bottom of the device under the view, there are device navigation controls. From left to right, the controls are: a back button (triangle), a home button (a circle), and a recently used apps button (square). These device navigation controls are light gray shapes that contrast with the black background of the device.

To the right of the AVD there is a bar of device controls. The bar is a long vertical rectangle. At the top left of the bar there is a close (X) icon, and at the top right there is a minimize (minus) icon. Under the close and minimize icons there are the following controls: power button, volume up, volume down, rotate device left, rotate device right, camera, zoom-in, back button (triangle), home button (circle), and a recently used apps button (square). At the bottom of the controls bar, there is a more icon (three dots).

Android Manifest

Every Android app must include a file called AndroidManifest.xml at its root. The manifest file contains essential information about the app, such as what components it contains, required libraries, and other declarations.

An example of the folder/file structure for an Android application in a folder navigation panel of an editor.  The root directory contains a 'MyAndroidDiary' folder which has three subfolders.  The subfolders are  a '.gradle' folder, an '.idea' folder, and an expanded 'app' folder. The 'app' folder contains a 'build' folder, a 'libs' folder, and an expanded  'src' folder. The 'src' folder contains an 'androidTest' folder, and an expanded 'main' folder. The 'main' folder has a 'java' folder, a 'res' folder, and a 'AndroidManifest.xml' file which selected  and is highlighted in blue. The navigation panel has icons to the left of each folder and file. The folders have expand/collapse arrows (except for the 'libs' folder), they also have folder icons to the right of the arrows. The files have file-type icons.

Gradle Build File

Gradle Scripts > build.gradle

There are two files with this name: one for the project and one for the app module. Each module has its own build.gradle file.

An example file structure of an Android app using Gradle.

The root directory, named 'MyApp', has a 'build.gradle' file, a 'settings.gradle' file, and a directory named 'app' nested inside.

Inside the app directory there is an additional 'build.gradle' file, and a 'build', 'libs', and 'src' folders.

Android Logcat

Adding messages to a log can be a useful way of checking that your code works the way you want. Each message is composed of a String tag you use to identify the source of the message, and the message itself.

Log.v(String tag, String message)
// Logs a verbose message.
Log.d(String tag, String message)
// Logs a debug message.
Log.i(String tag, String message)
// Logs a information message.
Log.w(String tag, String message)
// Logs a warning message.
Log.e(String tag, String message)
// Logs a error message.

Static Code Analysis

A lint, or linter, is a static code analysis tool used to evaluate and improve source code without executing it. It can find and flag programming errors, bugs, and patterns that may compromise security. The most popular JavaScript linters are ESLint, JSLint, and JSHint. They can be customized to one’s needs by using configuration files or third-party plugins.

eslint-plugin-security is a plugin for ESlint that adds rules to detect several security vulnerabilities including unsafe regular expressions, non-literal exec(), eval() used with an expression, and more!

Package Name

The package name is a unique name to identify a specific app. Generally, the package name of an app is in the format domain.company.application, but it’s completely up to the app’s developer to choose the name. The domain portion is the domain extension, like com or org, used by the developer of the app. The company portion is usually the name of the developer’s company or product. The final application portion usually describes the app itself.

Two form fields are shown, 'Name' and 'Package name'. Each of the form fields has a label above the text field area. The field labeled 'Name' is on top and has the text 'My Application' in the form field. Under the 'Name' form field is the field labeled 'Package name' and it has the text 'com.codecademy.myapplication' in the form field.

Android SDK Version

The minimum required SDK is the lowest version your app will support. Your app will run on devices with this level API or higher. Choosing the right version is a bit of a balance since we want to be able to use newer features from later versions, but still write an application that applies to most users.

An example of selecting the Android SDK Version for a new application.

The example shows a field with a dropdown menu used to select the SDK version of a new application. There is also a message under the field that gives us an estimate of the percentage of devices the app (with the selected SDK version) will run on. 

In the example, the field is labeled 'Minimum API level' and 'API 21: Android 5.0 (Lollipop)' is selected from the dropdown menu. The message below the 'Minimum API level' field is 'Your app will run on approximately 85.0% of devices.' To the left of the message there is a circular blue info icon.

App Module

Within a project, there are one or more modules. Typically, an app can be developed with a single module app. Modules provide a container for your app’s source code, resource files, and app level settings, such as the module-level build file and Android manifest file. Each module can be independently built, tested, and debugged.

An example folder/file structure for an Android application in a folder navigation panel of an editor.  Each folder and file shown is on a new line. The root directory contains a 'MyAndroidDiary' folder that has three subfolders.  The subfolders are a '.gradle' folder, an '.idea' folder, and an expanded 'app' folder. The expanded 'app' folder contains 7 items.  These seven items are: a 'build' folder, a 'libs' folder, a 'src' folder, a '.gitignore' file, an 'app.iml' file, a 'build.gradle' file, and a 'proguard-rules.pro' file. The navigation panel has icons to the left of each folder and file. The folders have expand/collapse arrows (except for the 'libs' folder), they also have folder icons to the right of the arrows. The files having file-type icons.

Layout Editor

In Android Studio, the app layout can be edited using Android studio Layout Editor. This generates (and modifies) layout XML files in app->scr->res. These files can also be coded directly or dragging GUI components in the design editor.

An example of the folder/file structure for an Android application in a folder navigation panel of an editor.  The root directory contains a 'MyAndroidDiary' folder which has three subfolders.  The subfolders are  a '.gradle' folder, an '.idea' folder, and an expanded 'app' folder. The 'app' folder contains a 'build' folder, a 'libs' folder, and an expanded  'src' folder. The 'src' folder contains an 'androidTest' folder, and an expanded 'main' folder. The 'main' folder has a 'java' folder and an expanded 'res' folder. The 'res' folder has a 'drawable' folder, a 'drawable-v24' folder, and an expanded 'layout' folder. In the 'layout' folder there is an 'activity_main.xml' file that is highlighted in blue. The navigation panel has icons to the left of the folders and files. The folders have expand/collapse arrows (except for the 'libs' folder), they also have folder icons to the right of the arrows. The files have file-type icons.

Learn More on Codecademy