The following is the first few sections of a chapter from Exploring Android, plus headings for the remaining major sections, to give you an idea about the content of the chapter.
Creating an Android application first involves creating an Android “project”. As with many other development environments, the project is where your source code and other assets (e.g., icons) reside. And, the project contains the instructions for your tools for how to convert that source code and other assets into an Android APK file for use with an emulator or device, where the APK is Android’s executable file format.
Hence, in this tutorial, we kick off development of a sample Android application, to give you the opportunity to put some of what you are learning in this book in practice.
First, we need an Android project to work in.
Normally, you would use the new-project wizard to create a new project. However, the problem with the new-project wizard is that Google keeps changing what the new-project wizard generates. In most situations, that is not a huge problem. However, it becomes a problem for tutorials like this one, as if Google changes what is in the new project, the tutorial’s instructions become out of date.
So, instead, we will import an existing project, so we can start from a stable base.
Visit the releases page of this book’s GitHub repository.
Then, scroll down to this book’s version and download the
file for this version of the book. UnZIP that project to some place on your development machine. It will
unZIP into a
Then, look at the contents of
gradle/wrapper/gradle-wrapper.properties. It should
look like this:
#Tue Nov 14 13:31:09 EST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
In particular, make sure that the
distributionUrl points to a
URL. Never import a project into Android Studio without checking the
distributionUrl, as a malicious person could have
point to malware that Android Studio would load and execute.
Then, import the project. From the Android Studio welcome dialog, that is handled by the “Import project (Eclipse ADT, Gradle, etc.)” option. From an existing open Android Studio IDE window, you would use File > New > Import Project… from the main menu.
Importing a project brings up a typical directory-picker dialog. Pick the
directory and click OK to begin the import process. This may take a while,
depending on the speed of your development machine. A “Tip of the Day” dialog
may appear, which you can dismiss.
At this point, the IDE window should be open on your starter project:
Figure 16: Android Studio, Showing ToDo Project
If you are using a newer version of Android Studio than then one profiled in this book, you may be prompted to “upgrade” the project. This would replace or modify some of the project’s build instructions. To keep your files synchronized with the book’s instructions, opt out of the upgrade.
It is also possible, if you are using a newer version of Android Studio, that you will be prompted to download the API Level 26 version of the Android SDK. That would occur if you do not already have that downloaded from the SDK Manager. If asked, agree to install the API Level 26 SDK.
The “Project” tool — docked by default on the left side, towards the top — brings up a way for you to view what is in the project. Android Studio has several ways of viewing the contents of Android projects. The default one, that you are presented with when creating or importing the project, is known as the “Android view”:
Figure 17: Android Studio “Android View”
While you are welcome to navigate your project using it, the tutorial chapters in this book, where they have screenshots of Android Studio, will show the project view:
Figure 18: Android Studio “Project View”
To switch to this view — and therefore match what the tutorials will show you — click the arrows to the right of tabs (“Android”, “Project Files”) in the earlier screenshot, to bring up a drop-down of available views. macOS users may instead need to click on the “Android” tab to bring up the drop-down. In the drop-down, choose “Project” to switch to the project view.
The preview of this section is presently indisposed.
The preview of this section was the victim of a MITM ('Martian in the middle') attack.
The preview of this section is off trying to sweet-talk the Khaleesi into providing us with a dragon.
The preview of this section is in an invisible, microscopic font.