Previous  | Next  | Home

Creating a New Project


 

The starting point for developing an Android app is to create the framework of a corresponding project. Android Studio permits this to be done in very simple fashion.


The following instructions for creating a new Android project in Android Studio are based on the Linux version of Android Studio 2.1.2 current in mid-2016. For other versions of Android Studio similar information will be required, but the format for entering it may differ some from that in the current instructions.

To create a new Android project with the Android Studio, select Start a new Android Studio project from the AS homescreen or, with the interface open, select File > New > New Project from the top menu. This should give a window similar to the following figure:



Fill this screen out as appropriate, where the fields have the following meaning:

  1. Application name: The name that will appear in the app launcher, that will be shown in the Play Store, and that will appear in the Settings > Manage Applications menu when installed on a device. The choice is arbitrary and it need not coincide with the project or package name, but it is usually less confusing to keep them similar.

  2. Package name: namespace of the package corresponding to this project. It must be a fully qualified package namespace (following the rules for packages in Java) where all the source code will reside, must have at least two components separated by dots, and should uniquely identify your project. A common approach is to reverse the internet domain name for your organization (or make one up that is unique), followed by one or more application identifiers. Example: com.lightcone.myapp (it is normal for this package name to be all lower case).


    Each application in the system must have a unique package name, which can be ensured by systematically naming packages using the same reversed domain prefix but different suffixes: com.lightcone.app1, com.lightcone.app2, ... For practice and development you can use a default like org.myname.example (e.g., org.myname.example.myapp), but for deployment of apps for use by others you should systematically name your packages with a reversed domain that is unique (ideally an internet domain that you control, though that isn't essential).

    Choose the package name carefully, since it determines organizational structure for the project and is not very easy to change later because it ends up being used in various places. The package name is typically not visible to users. It must remain the same for the life of your app if it is uploaded to the Play Store (this is how in the Play Store successive versions of an app are identified as the same app).


    By default Android Studio accepts a domain in the Company Domain field that it then reverses and concatenates with the Application Name converted to lower case with all blank space removed to produce the Package name. However, you can change this using the Edit button to the right of the Package name if you desire.

  3. Project location: Path to the subdirectory in the workspace directory where your project will be created. Android Studio will choose a default value, but you may change it.

Once this screen is filled out, click Next, which should give a screen like the following figure.



This screen specifies the devices for which we will develop the app, and the minimum version of the Android SDK that will be supported. Our discussion will concern primarily development for phones or tablets, but on this screen there are options for other formfactors such as wearables or Android TV.

The Minimum SDK is the minimum API Level required to run your application properly. This entry automatically sets the minSdkVersion attribute in the build.gradle file (it was set in the AndroidManifest.xml in earlier versions of Android). Generally you should specify the lowest SDK value under which your app will run correctly, since this will target the broadest range of devices.

The minSdkVersion level is NOT the Android version number. Some Android platforms that we will use and the corresponding SDK number (in parentheses) include:
  • Android 4.0 (API level 14)
  • Android 4.0.3 (API level 15)
  • Android 4.1 (API level 16)
  • Android 4.2 (API level 17)
  • Android 4.3 (API level 18)
  • Android 4.4 (API level 19)
  • Android 5.0 (API level 21)
  • Android 6.0 (API level 23)
Most phones or tablets manufactured since about 2012 should be running one of these at a minimum. In keeping with the whimsical Android convention of naming versions after sweet desserts or candies, Versions 4.0-4.0.3 are also known as Ice Cream Sandwich, versions 4.1-4.3 as Jelly Bean, version 4.4 as Kit Kat, versions 5.x as Lollipop, and versions 6.x as Marshmallow. A complete list of SDK versions may be found in Android Versions, and the versions available for development in Android Studio are listed in the SDK manager (Tools > Android > SDK Manager).

Set the values on this screen as desired and click Next, which should give a screen similar to the following.



This screen allows the choice of a stub for a main activity to be inserted. Empty Activity is the typical choice but others may be more appropriate for specific tasks like a mapping application. After making a choice, click Next, which gives a screen similar to the following.



The top field gives the name of the main activity class (Java file) to create. The bottom field gives the name of the corresponding XML layout file. The defaults can be changed if desired but they are commonly called MainActivity and activity_main, respectively. Typically one will want to check the Generate Layout File box to produce a default initial layout for the main activity. When done, click Finish. This should create a new project, which will appear in the package panel on the left of the Android Studio interface, ready for editing, as illustrated in the following figure.



If you look at your workspace directory at this point, you will see that subdirectories and files corresponding to the new project have been created there with the same directory hierarchy displayed in the Android Studio package explorer.

Last modified: June 9, 2016


Previous  | Next  | Home