How to Create a New Project in Android Studio

  My previous article provided a brief introduction to Android App Development. Here, I’ll tell you how to get started with your first Android Project. As I mentioned in the previous article, Android Studio is currently the official IDE for Android App Development. Therefore, all my articles will assume that you’re using Android Studio. Now, let me show you how to create a new project in Android Studio.

How to Create a New Project in Android Studio

  First of all, you need to have Android Studio installed on your computer. You may install Android Studio on Windows, Mac or Linux. For both Windows and Mac, you have two download options – installer file (.exe or .dmg) or .zip file. On the other hand, Linux users have to download the .zip file. You should download the latest stable version from this link on Android’s official website. As of January 2018, the latest stable version is 3.0.1 which was released in November 2017.

 

The download page shows the SHA-1 checksums for all the files available for download. After downloading the required file, you should verify its SHA-1 checksum against the value mentioned on the download page to make sure that the file you downloaded is not corrupt. However, you may skip this step.

  Before installing Android Studio, you should install Java Standard Edition (or SE). You can download Java Development Kit (also known as JDK SE) from this page on Oracle’s website. You do not need the latest version of JDK. If you have a slightly older version of JDK (but not very old), it will still work. Please Note that Android Studio will not work without JDK. The process of installing Android Studio is very simple. You may require an internet connection if you’re prompted to download or update some components of Android Studio during installation. After the installation completes, you may proceed to the next step i.e. creating your first Android project.



Creating your First Android Project

  When you start Android Studio for the first time, it looks similar to the image shown below. After you add one or more project(s), this window will display a list of recently opened projects on the left. Now, follow the steps mentioned below to start creating a new project.

How to Create a New Project in Android Studio

How to Create a New Project in Android Studio

Step 1 – Click on Start a new Android Studio project. A new window titled New Project will appear.

How to Create a New Project in Android Studio - New Project

How to Create a New Project in Android Studio – New Project

Step 2 – In this window, type the name of the app you want to create in the Application name field. Here, I’m creating an app named Calculator. Type the domain name of your website (if you have any) in the Company Domain field. If you don’t have a domain name, type any random domain name. Many people use example.com. Here, I’m using my domain androidcodebits.com. After you enter both Application name and Company Domain, the Package name will be displayed by combining the contents of both fields. In this case, the package name for my app is com.androidcodebits.calculator.



  Please Note that the domain name is reversed. Probably, you have downloaded APKs for various Android apps and observed that the APK file is named like com.company_name.app_name. I hope you understand the reason for such nomeclature if you’re familiar with Java programming. Finally, the Project Location field displays the location of the project files on your computer. By default, your projects are saved somewhere in the C:/Users/user_name directory (if you’re using Windows OS). In this case, I’ve changed the location to a more suitable directory. After you have made the required changes here, click Next.

Step 3 – The current window titled Target Android Devices lets you choose which Android devices you want to target with your app. The available options are – Phone and Tablet, Wear (Android Smart Watches), TV (Smart TV running Android OS), Android Auto (for Automobiles, read more about it here) and Glass (Google Glass). You may choose one or more of these options. However, since you’re learning Android App Development, you should choose the first option i.e. Phone and Tablet.

How to Create a New Project in Android Studio - Target Android Devices

How to Create a New Project in Android Studio – Target Android Devices

  As you can see in the above image, there is an option to choose the Minimum SDK for each platform (e.g. Phone & Tablet/TV/Wear) . This option is used to specify which minimum version of Android you want to support on which platform. For example, the above image shows that API 17 (Android 4.2 – Jelly Bean) has been selected for Phone & Tablet. It means that if you try to install this app on a phone or tablet that has an older version of Android than 4.2, the app will not be installed. A phone or tablet must have Android 4.2 or above to be able to install this app. Similarly, if you choose other platforms such as TV, you need to specify the Minimum SDK for that too. Please Note that you need to choose the Minimum SDK very carefully. Selecting an old SDK lets your app support more devices. However, if you choose a very old SDK, your app may not be able to use certain new features. Right now, I have chosen API 17 as the minimum SDK for my app. If you’re developing a game, you might want to target a more recent version of Android to get the maximum advantage of new Android features. After you’re done with this screen, click Next.

Step 4 – The next window titled Add an Activity to Mobile lets you choose the type of Activity you want to create for your app.

How to Create a New Project in Android Studio - Add an Activity to Mobile

How to Create a New Project in Android Studio – Add an Activity to Mobile

  First of all, let me tell you what an Activity is. When you open an app on your Android device, you see a user interface which may consist of some buttons, images, text etc. For example, the below image shows the UI of the Programmer’s Calculator app. A music player app may have a different UI. In simple terms, this UI is considered an Activity in Android. An Android app may have multiple activities. For example, a simple music player app may have one activity for displaying all the songs present on your device, one activity to play a particular song and one activity to change settings.

Programmer's Calculator

Programmer’s Calculator

  Now, back to the point. There are several type of activities in Android and they are used to perform different types of tasks. The Add an Activity to Mobile window lets you create an Empty Activity (which is a blank activity),  a Login Activity (for letting the user log in using a username/password combination), a Google Maps Activity (for displaying maps) and so on. You may also choose the Add No Activity option if you want to add an activity later. In this case, we’re going to choose the Empty Activity and click Next. More activities can be added later, if required.



Step 5 – The next window titled Customize the Activity lets you set the name of the Activity you created in the previous step and generate a layout file for it. The layout file of an Activity determines its appearance. The default Activity Name is MainActivity and the default Layout Name is activity_main.

How to Create a New Project in Android Studio - Customize the Activity

How to Create a New Project in Android Studio – Customize the Activity

  There is a checkbox labelled Backwards Compatibility (AppCompat) which is checked by default. The Backwards Compatibility option is used to ensure that the layout of the app appears the same on both new and old versions of Android. This may be useful for you in certain circumstances. For example, if you’re using a theme which was introduced in a new version of Android and you want it to work well on an older version of Android. In this case, I have unchecked it, because it isn’t needed. Now, click on Finish and you’re done. The project has been created successfully.

 

Note – If the Backwards Compatibility (AppCompat) option is checked, the AppCompatActivity class is used as base class for your activity. If it is unchecked, the Activity class is used as base class.

  After you complete all the above five steps, Gradle starts building your project. It takes a few seconds to do so. After this, the following window is displayed. The file currently visible in the IDE is MainActivity.java which is the source file for the main Activity of your project. This is where you add the code to make your app work.

How to Create a New Project in Android Studio - New Project Created

How to Create a New Project in Android Studio – New Project Created

How to Create a New Project in Android Studio: Video Tutorial

  Congratulations!!! You have created your first Android Project. Now, I’ll tell you how to add code to make it actually do something and how to run it on an emulator or an actual device, in my next article.

(Visited 333 times, 1 visits today)

One comment

  • Thanks for the fantastic article. I am a new to Android and your article helped me understand several things about Android projects.

Leave a Reply

Your email address will not be published. Required fields are marked *