What is Android Studio?
To write some code for your Android application, you need some kind of environment or code editor that will make your task easy. No doubt, you can write the same code by using any normal text editor but that will increase your workload. You can use that energy in developing some cool logic in your Android application.
So, Android Studio is an Integrated Development Environment (IDE) for Android app development. To enhance productivity while building Android application, Android Studio provides a number of features, some of these are:
- Instant run on your mobile device or any virtual device to check the working of the application
- Extensive testing tools that can be used for better testing before launching your application on the Play Store
- Flexible Gradle-based build system
- Code autocomplete
- Provides predefined templates that can be used in our Project
- Emulator support, that can be used to have a virtual feel of the Android device
- It provides C++ and NDK support
- Support for GitHub and other Version Control Systems
How to install Android Studio?
In order to install Android Studio in your system, make sure to download the latest version of the Android Studio from Android Studio website. Also, check the system requirements of Android Studio.
Writing your first Android Studio application
By default, Android Studio provides you a number of templates that you can use while making your very first Android Studio project. To create a new project in Android Studio, click on Start a new Android Studio project. After that, select from the number of predefined templates that you can use in your project without coding for the same. If the desired template is not present then you can select Basic or Empty Activity template. After selecting the desired template, click on next and then enter the name of the application, package name of the application, save location, language and minimum API level (this is the minimum API level supported by your app). After selecting these, click on Finish. You can run your project on your device by connecting the device with USB and then run your application. But, before that, get familiar with the Android Studio.
To understand in a better way, we can divide the Android Studio screen into four parts:
- Menu part: Here, you will get various options like creating a new project, opening a project, running your project on the desired device, build your project and many other options.
- Coding area: This is the area where you can actually write code for your .kt or .java or .xml file. You can open a number of files at a time in different tabs, but the editing can be done in only one at a particular instant of time.
- Project structure: This is the part from where you can access all your files present in your project. There are various views of the project structure in Android Studio.
- Current execution part: This part is the most important part of the Android Studio. Here, you can see the currently executing process or activity. You can detect the error if any in your Android application. Here, you will get all your build outputs and actions, logcat results, todos and also, you can use terminal here in your Android Studio.
Run your app
In Android Studio, you can run your application in two ways, either you can use your mobile device to run the app or you can create a virtual device called emulator and run the app on it. The virtual device will perform the same as that of a normal device but it will require some RAM and storage.
To run an app on your device, follow the below steps:
- Use a USB cable to connect your device with your PC.
- Then open the Settings of your device.
- (Only on Android 8.0 or higher) Select System.
- Scroll to the bottom and select about phone.
- Scroll to the bottom and tap Build number 7 times.
- Return to the previous screen to find Developer options near the bottom.
- Open Developer options, and then scroll down to find and enable USB debugging.
- After that, in your Android Studio, click on Run to run your application by selecting the connected device
To run your app on Emulator, follow the below steps:
- In Android Studio, click on Run
- In the Select Deployment Target window, click on Create New Virtual Device.
- In the Select Hardware screen, select a phone device from a list of Phones and click on Next.
- In the System Image screen, select the version with the highest API level and click next.
- On the Android Virtual Device (AVD) screen, leave all the settings alone and click Finish.
- Back in the Select Deployment Target dialog, select the device you just created and click OK.