Create a simple project.
Create an Android Virtual Device (emulator), so we can run and test projects.
Create a Project
❶ | NAME—This is what you want to call the application; this is also known as the project name. This name becomes the name of the top-level folder which contains all of the project’s files. This name also becomes part of your application’s identity, should you release it in the Play Store. |
❷ | PACKAGE NAME—This is your organization or company’s domain name in reverse DNS notation. If you don’t have a company name, you can use anything that resembles a web domain. At the moment, it won’t matter if we use a real company name or not, since we won’t release this to the Play Store. |
❸ | SAVE LOCATION—This is a location in your local directory where the project files will be kept. |
❹ | LANGUAGE—You can use either Kotlin or Java; for this project, we will use Java. |
❺ | MINIMUM API LEVEL—The min API level will determine the lowest version of Android which your application can run on. You need to choose wisely and prudently because it can severely limit the potential audience for your app. |
❻ | HELP ME CHOOSE—This shows the percentage of Android devices that your app can run on. If you click the “Help me choose” link, it will open a window that shows the distribution of Android devices, per Android version. |
❼ | INSTANT APPS—If you want your app to be playable, without the user installing your app, enable this check box. Instant apps allow a user to browse and “try out” your app in Google Play without downloading and installing the app. |
❽ | ANDROID.X—These are support libraries. They’re included so that you can use modern Android libraries (like the ones included in Android 9) but still allow your app to be run on devices with lower Android versions. |
When you’re all done, click “Finish” to begin the project creation. Android Studio scaffolds the project and creates startup files like the main Activity file, Android Manifest, and other files to get the project propped up. The build tool (Gradle) will pull quite a few files from online repos—it can take some time.
Android Studio’s screen is composed of several sections which can collapse and expand, depending on your needs. The section on the left (Figure 2-4) is the Project Panel; it’s a tree-like structure that shows all the (relevant) files in the project. If you want to edit a particular file, simply select it in the Project Panel and double-click; at that point, it will be opened for editing in the main editor window. In Figure 2-4, you can see the MainActivity.java file available for editing. In the course of time, we will spend a lot of hours doodling in the main editor window, but for now, we simply want to go through the basic process of application development. We won’t add or modify anything in this Java file nor any other in the project. We’ll leave it as is.
Create an AVD
We can test the application either by running it in an emulator or plugging a physical Android device into the workstation. This section covers setting up an emulator.
Front and back camera
Emulated network speed
Emulated performance
Size of internal storage
Keyboard input (whether enabled or disabled)
Now we can see the newly created emulator (Pixel API 28). You can launch it by clicking the little green arrow on the “Actions” column—the pencil icon edits the configuration of the emulator, the green arrow launches it.
When the emulator launches, you’ll see an image of the Pixel phone pop up on the desktop; it needs time to boot up completely. Go back to the main editor window of Android Studio to run the app.
Android Studio compiles the project; then it looks for either a connected (physical) Android device or a running emulator. We already launched the emulator a while ago, so Android Studio should find it and install the app in that emulator instance.
Key Takeaways
Android projects almost always have an Activity. If you want to start with a basic project, choose one with an “Empty Activity” and build from there.
Pay some attention to what you put in the project details during creation; if you do release the project to Google Play, those project information will be part of your application, and many people will see it.
Choose the minimum SDK carefully; it will limit the number of potential users of your app.
You can use an emulator to run your app and see how it’s shaping up. Testing using an emulator is much better if you have HAXM (emulator accelerator) enabled on your system; if you’re on Linux, acceleration can be achieved using KVM.