Learning Android Game Development
上QQ阅读APP看书,第一时间看更新

Creating your first Android Studio project

Open your Android Studio, and click on Start a new Android Studio project, as shown in the following screenshot:

Once you start a new project, you will see the following screenshot:

In this screen, fill in the details of your first Android app:

  • Application name is the name of your app, which will appear on the icon of your phone when it is installed.
  • Company Domain is an identifier for your app. Make sure that you keep this common throughout your apps for better organization and convention.
  • Package name is another important unique identifier for your app. We learned about this in our first chapter and saw its naming conventions. Refer to that part if you have any doubts regarding package names and their naming.
  • Include C++ support is optional. For the purpose of this book, we will keep it unchecked for now.
  • Project location is the path where your project folder will be situated on your computer.

Once you are ready after filling in all these details, press Next.

Now, you will see this screen:

Different platforms for your Android app

For the purpose of this book, we will only work with Phone and Tablet. However, you can try experimenting with other platforms as well, once you are comfortable with the development cycle. 

Minimum SDK is the OS version that would be required as a minimum factor to run your app. It is recommended that you select the lowest version for your app to run on as many OS versions as possible. However, do note that some functions are deprecated from further versions, so it is recommended that you use Minimum API 14: Android 4.0 (IceCreamSandwich) for hassle-free development. You will also be prompted about how many devices will be supporting your app, as you can see in the image. These figures are real time and change as the market share of an OS changes.

If you want to know about the updated market share and some more interesting stuff related to various versions and their respective market share, you can visit the official Android website at  https://developer.android.com/about/dashboards/index.html.

Once we select our Fullscreen Activity, press Next, as follows:

Different types of activities

You could say that an activity is simply a default layout. Since we are creating a game, we will use a Fullscreen Activity. As you can see in the preceding screenshot, you have many different activity options to choose from, which are quite self-explanatory on their own. So, let's select Fullscreen Activity and press Next:

Naming your activities

Activity Name is the name of your Java class that will be generated. We will be working with this file a lot, so make sure that you remember it.

Layout Name is the name of the XML file, which will deal with how and what components will appear on your app visually. There are some naming conventions that need to be followed for XML files. They are as follows:

  • Names must be all lowercase
  • An underscore is used to separate two words instead of spaces.
  • Always prefix the filename with the type of resources; for instance, if your XML file corresponds to an activity such as MainActivity.java, then your filename would be activity_main.xml.
  • If you have a subitem of a specific group, such as a list item of main activity, then it can be named by suffixing it as activity_main_list_item.xml.
  • This way, you can either suffix or prefix a keyword for your filename, as you prefer.

Title is the name that will appear on the top bar of your app. The title you use for the Activity and the class name of the main Activity might be different; titles may also contain spaces.

Once you are finished with all of this, click on Finish and give yourself a pat on the back. You have successfully learned how to create an Android Studio Project. After this, wait for a few seconds/minutes depending on your system's performance for your project to set up; once it is ready, you will see the following screen:

Our Android Studio Project Folder

If for some reason, you are not able to see this screen after waiting, then click on the 1: Project option, which is vertically aligned below FirstGame on the upper-left corner of the screen.

Congratulations! You have successfully created your first app now. At this point, you can go ahead and run the project and see how it runs on the emulator; however, before we do that, let's walk through the project folder structure of this project. Let's expand each folder to understand it further. Now, this part is very important, since this will serve as a foundation for almost every basic thing you will be doing in Android Studio, so make sure that you understand this properly.