Creating an Android Project

The first step is to create an Android project. An Android project contains the files that make up an application. To create a new project, first open Android Studio.

If this is your first time running Android Studio, you will see the Welcome dialog, as in Figure 1.3.

Figure 1.3  Welcome to Android Studio

Welcome to Android Studio

Before you begin your project, take a moment to turn off a feature that could interfere with your work. Instant Run is designed to streamline development by allowing you to push code changes without building a new APK. Unfortunately, it does not always work as intended, so we recommend that you disable it while working through this book.

At the bottom of the Welcome dialog, click Configure, then choose Settings. On the lefthand side of the Preferences for New Projects screen (Figure 1.4), expand Build, Execution, Deployment and choose Instant Run. Uncheck the box next to Enable Instant Run to hot swap code/resource changes on deploy (default enabled) and click OK.

(If you have used Android Studio before and do not see the Welcome dialog when you start up, go to Android StudioPreferences, then expand Build, Execution, Deployment and continue as above.)

Figure 1.4  Preferences for New Projects

Preferences for New Projects

Back at the Welcome dialog, choose Start a new Android Studio project. If you do not see the dialog, choose FileNewNew Project....

Welcome to the Create New Project wizard (Figure 1.5). Make sure the Phone and Tablet tab is selected, pick Empty Activity, and click Next.

Figure 1.5  Choosing a project template

Choosing a project template

You should now see the Configure your project screen (Figure 1.6). Enter GeoQuiz as the application name. For package name, enter com.bignerdranch.android.geoquiz. For the project location, use any location on your filesystem that you want.

Select Kotlin from the Language drop-down menu. Select a Minimum API level of API 21: Android 5.0 (Lollipop). You will learn about the different versions of Android in Chapter 7. Last, make sure the checkbox next to Use AndroidX artifacts is checked. Your screen should look like Figure 1.6.

Figure 1.6  Configuring your new project

Configuring your new project

Notice that the package name uses a reverse DNS convention: The domain name of your organization is reversed and suffixed with further identifiers. This convention keeps package names unique and distinguishes applications from each other on a device and on the Google Play Store.

As of this writing, new projects generated by Android Studio are in Java by default. Selecting Kotlin as the language tells Android Studio to include the dependencies, such as Kotlin build tools, necessary to write and build Kotlin code for your app.

Java was the only development language officially supported until May 2017, when the Android team announced official support for Kotlin for Android development at Google I/O. These days, Kotlin is preferred by most developers, ourselves included, which is why this book uses Kotlin. But if you choose to use Java in your projects outside of this book, the Android concepts and content you will learn here will still be applicable.

Google used to provide a monolithic support library of helpers and compatibility shims. AndroidX explodes this single library into many independently developed and versioned libraries, collectively called Jetpack. Selecting Use AndroidX artifacts makes your project ready to use these newly independent tools. You will learn more about Jetpack and AndroidX in Chapter 4, and you will use various Jetpack libraries throughout this book.

(Android Studio updates regularly, so your wizard may look slightly different from what we are showing you. This is usually not a problem; the choices should be similar. If your wizard looks very different, then the tools have changed more drastically. Do not panic. Head to this book’s forum at forums.bignerdranch.com and we will help you navigate the latest version.)

Click Finish. Android Studio will create and open your new project.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.236.219.157