Your First Android Project

Your First Android Project

It’s time to create your first project in Android Studio! It’s important to note this lesson focuses on getting your first Android app running as quickly as possible. As such, you’ll encounter a few unfamiliar screens, but don’t worry — you’ll learn more about those later.

The first time you launch Android Studio, you’ll see the Welcome screen.

On the Welcome screen, click New Project:

The Welcome screen disappears, and a new window takes its place. This is where you choose the type of device you want your project to support.

By default, Phone and Tablet is selected, showing a variety of screen types. Click Empty Activity to choose it as your preferred project setup. Click Next in the bottom-right of the window to move on to the next step.

Now, this screen requires some crucial app details:

  1. Name is where you enter the app’s name. For this project, name the app Kodeco Chat.
  2. Package name provides a package name for the app, a concept you might be familiar with from Java or Kotlin. Make sure this field reads as com.kodeco.chat.
  3. Save location denotes where Android Studio will store the project. Create your project anywhere you want. Choose a save location that makes sense for your setup. To avoid confusion, choose a dedicated directory per Android project. The folder button to the right of the field provides a system navigator to help you select.
  4. Minimum SDK sets the minimum version of Android the app will support. Ensure API 28 (“Pie”, Android 9.0) is selected.
  5. Build configuration language lets you choose between Kotlin or Groovy for the Gradle configuration scripts language. Until recently, you had to use Groovy, but now the default language for Gradle is Kotlin, letting you use a single language for all your Android development. Choose the default, Kotlin DSL.
  6. Finish, the button in the bottom-right of the window, completes the project setup. Click this when you’re ready to move on.

Android Studio uses this information and gathers the required libraries and resources to generate a new project. Depending on your internet connection, this phase might take some time.

When that process finishes, Android Studio displays the new project with MainActivity.kt already open:

If you see Gradle Sync in Progress or progress bars at the bottom of the Android Studio screen, wait for it to finish.

Android Studio

With the project created, you’re ready to work on it. But don’t jump in so quickly. Android Studio is a robust piece of software. If you dive in too fast, you might find yourself lost.

Before you start building your app, take a moment to review what Android Studio has to offer.

  1. The first window that appears is the editor. This window provides a space to edit your app’s source code. It includes tools like syntax highlighting, auto-completion for methods and objects, and the ability to set breakpoints in your code while debugging. You’ll learn more about breakpoints and debugging later. You’ll spend most of your development time using the editor to code your app.

  2. To the left of the editor is the project navigator. This window shows everything your project contains, including code and image assets. Android Studio provides a lot; you can see what by clicking the arrow to the left of the items in the project navigator. There’s no need to worry about these files for now; you’ll get well acquainted with them as you progress through this module.

Creating an Android Virtual Device

Note: If you have a physical Android device you want to use for development, skip to the next section.

Seeing your code is good, but running the app and seeing it in action requires a device — whether it’s real or virtual. Look at the button highlighted in the following image.

This button opens the Device Manager pane to show all the available devices. Click this button to open the Device Manager pane.

If you have any physical Android devices connected, they’ll show here. This pane also lists the Android Virtual Devices available, usually abbreviated as AVD. An AVD is an emulator that acts as an Android device on your computer. This lets you test your app without requiring a physical device. If you don’t have a physical device for testing, you’ll need to create a virtual device before you can run your app.

Click the + button at the top of the Device Manager pane.

A new window appears, titled Select Hardware. In this window, you can select the type of device you want your AVD to emulate.

Select Pixel 7 Pro from the list of virtual devices. This is an excellent choice because it closely emulates an actual device many people use.

In the bottom-right of the window, click Next to progress to the System Image window. In this window, you select the version of Android to run on your emulator.

A few tabs run along the top of the list. The most interesting is Recommended, which shows a list of Android versions that Google recommends you use when testing your apps. Currently, those versions are grayed out because they’re not available on your computer. You can change this by downloading the latest version of Android recommended by Android Studio.

Select the highest API Level item in the table (in this example, UpsideDownCake/API Level 34), and click Download in the Release Name column.

The Component Installer window appears and automatically downloads the selected version of Android.

Once the download is complete, click Finish in the bottom-right. The Component Installer window disappears, and the System Image window reappears. At this point, the latest version of Android is ready to use. To move on, click Next in the bottom-right of the window.

The next and final window for creating an emulated device is a summary of the characteristics the device will have.

This window lets you name the AVD and confirm other aspects of the device, such as the Android version. You don’t need to change anything here, so click Finish at the bottom-right of the screen to create the AVD.

The current window disappears. In the Device Manager pane listing the available AVDs and devices, your new AVD shows up and is ready for use:

Setting Up an Android Device

Note: If you don’t have an Android device to use for development, read the previous section on how to set up an Android Virtual Device.

Before installing the Kodeco Chat app on your device, you must prepare your device setup for use with Android Studio. But first, connect your Android device to your computer with a USB cable.

Note: If you’re using a Windows computer, you need to download a USB driver for your device. You can download the driver and find instructions for installing it at https://developer.android.com/studio/run/oem-usb.html.

On your device, open the Settings app. At the top, in the search bar, type “build number” to search for the Build number setting.

When you see the Build number item, tap it several times until you see a message that you’re a few steps away from being a developer. Keep tapping away until another message lets you know you’ve become a developer.

Note: If your device is locked with a PIN, you must enter it before you can reach this stage.

So what did this magical button do? Tap the back button to go to the Settings page, then tap the System button. Can you see what to look for?

Note: On some devices, you might only need to tap back once to go to the Settings page.

A new item titled Developer options shows up. Tap this new option to see all the available developer features.

There’s a lot to go through here. The only option you need right now is USB debugging.

Find this option and switch it on. A confirmation dialog appears, informing you of the intended use of USB debugging.

Granting USB debugging privileges is a potential security hole, so most devices have this turned off by default. You’ll need to turn this on because you need to install apps over USB using Android Studio.

When you’re ready, tap OK, and the USB debugging toggle is enabled.

Another pop-up may appear, asking to confirm your computer’s RSA key fingerprint. This is another step Android takes to ensure no unauthorized computers can access your device data.

Because you’ve just enabled USB debugging, it’s safe to assume this is your computer accessing the device. Click Allow; check Always allow from this computer if you don’t want to give your computer permission every time you connect your device.

Congratulations, your device is now set up for development.

Running the App

It’s time to run Kodeco Chat! Along the top of Android Studio, there’s a drop-down with the name of your device:

To the right of the dropdown is a button that looks like a green Play button. This is the Run App button.

The drop-down lets you select a device to run Kodeco Chat on.

Depending on what device you set up earlier, the name of your physical device or your AVD will appear.

As long as a device is selected and appears in the closed dropdown button, it doesn’t matter which device you use.

With the device selected, click Run App. Android Studio begins building Kodeco Chat and installs the app onto your device. You can see this happening at the bottom of Android Studio.

When Android Studio finishes building and installing, Kodeco Chat will appear on your device:

Congratulations! You just created and ran your very first Android app! Next, in the demo, you’ll dive in and learn a bit more about how every app is structured.

See forum comments
Download course materials from Github
Previous: Introduction Next: Demo