Exploring Android Studio
Let's see how we can do some basic things with the official Android Studio IDE. You can change the appearance of Android Studio as you wish. It has some inbuilt themes like:
- The IntelliJ theme, which is the default theme
- The Dracula theme, which is a dark cool theme
You can change the theme by navigating to File | Settings | Appearance.
Creating a sample application
Let's create our first sample Android application using Android Studio.
- To create a new project, select File | New Project. The following window will appear:
- Enter the values in Application name:, Company Domain:, and Package name:. Then, select the project location.
- In the next screen, you need to select the minimum SDK version that your application supports. Targeting your application for a lower SDK version ensures that your application runs on a maximum number of devices. As of now, KitKat has a market share of 34 percent.
- In the next screen, you need to select an activity template. This template helps you to simplify the task. For our sample application, select Blank Activity.
- In the next screen, you should enter the name of your main activity and the name for your main layout. Menu Resource Name is for the action bar menu layout file.
- Then, click on Finish. Wait for some time until Gradle builds your project information.
Your sample app template is now created. Let's now explore Android Studio.
The section on the left-hand side is the project explorer and the section on the right-hand side is the code editor. You will see three folders:
manifests
,java
, andres
inside your app. Themanifests
folder contains our application'sAndroidManifest.xml
file. Thejava
folder contains our Java classes, which make ourActivities
,Fragments
, and other functions. Theres
folder contains all our layout files and styles. - Now, run your application on the Android emulator or on your own physical device. To run the application, you can click on the green Run app icon in the toolbar or you can select Run | Run app.
You will see the text Hello World in TextView. Physical devices are a lot faster than the Android emulator, which runs on your PC.
Exporting the Android application as APK
Your Android app should be exported as APK and signed to be able to publish it in the Google Play store and install it on your device. In order to sign an APK, you need to create a key store. Let's see how to export in Android Studio.
- Select Build | Generate Signed APK.
- The Generate Signed APK Wizard window will appear. You need to create a new key store by selecting the Create new button. Enter the required details. One of the fields in the Certificate section needs to be nonempty. You can leave the rest of the fields empty. The minimum validity should be
25
years. - Then, select OK. Your new key store will be created. If you have already created a key store, you can use it. It is recommended to sign different apps you create with the same key store. Key store is used to authenticate you. So, keep your key store safe. Note that, if you lose your key store, you can't update your app published in Play store.
The following screenshot shows the Generate Signed APK Wizard window:
- Then, select Next. In the next window, you should select the destination folder of your APK. Then, select the build type, whether it is Release or Debug. While running our app on the virtual device, it will run in the Debug mode. You cannot distribute a Debug build in Play store. The Release build is the final build that can be uploaded to the Play store in which the app must be signed with your own certificate. Finally, select Finish. Your APK will be generated.