Build Your First Android App (With No Step Skipped)

Have you ever wanted to start learning how to build android applications?. Cool, Simply sit tight and I will take you through all the steps. (With no step skipped.)

# Create an Android Project

  1. In the Welcome to Android Studio window, click Start a new Android Studio project.
    • Otherwise, If Android Studio is already open or if you already have an open project, Click File > New > New Project...Create An Android Project - File - New - New Project
  2. In the Choose your project window, select Empty Activity and click Next. Create An Android Project - Empty Actvity
  3. In the Configure your project window:
      Create An Android Project - Configure Your Project
    • Type a name for your app. i.e Name: My Android App
    • Type a package name for your app. It's typically your website domain name in reverse order plus the app name in lowercase. i.e Package name: com.stevenmwesigwa.myandroidapp
    • Choose where you want to save your app if you want to save it in a different directory. i.e Save location: F:\ANDROID\learn
    • Choose the programming language you want to use to write this app. In my case, I'll go with Java from the dropdown menu i.e Language: Java
    • Choose the minimum android version you want your app to support. i.e Minimum API level: API 16: Android 4.1 (Jelly Bean)
    • Click the Finish button.
  4. It may take some time as Android Studio prepares your app for the first time. Once it's done, you should see your editor appear like the one below. Create An Android Project - First Time Android Application Build
  5. Open the Project window (View > Tool Windows > Project). Or use a keyboard shortcut (ALT + 1) .
      Create An Android Project - Project Window
    • In the Project window, we have a couple of important files we will put more focus on namely :-
    • app > java > com.stevenmwesigwa.myandroidapp > MainActivity
      • This file acts as the main entry point for our app.
    • app > res > layout > activity_main.xml
      • This is where the layout of the activity's user interface is defined.
    • app > manifest > AndroidManifest.xml
      • This is where we define each component as where as define the main attributes about our app.
    • Gradle Scripts > build.gradle
      • As you may well notice, we have 2 build.gradle files. One for "app Project" and another for "app Module".
        • We'll use these files to configure 'build settings' to provide custom packaging options.
  6. Let's now run our app. Here we have a couple of options namely:
    • # Running The App On An Actual Device (SECTION A).

      • Connect your smart phone to your laptop or Desktop that you're currently working with using a USB cable. Make sure that your computer can recognize your phone. i.e That it is visible among the connected devices. If you're using Windows as your main operating system and your computer can't recognize your phone, you may need to install the appropriate USB driver for your smart phone.
      • # Enable USB Debugging on your smart phone.

        • Depending on your phone's android version, how to achieve this may vary. These steps have been tested on "Android v7.0" or higher.
        • Open Settings app. Enable Usb Debugging On Your Smart Phone - Open Settings App
        • If your device uses Android v8.0 or higher, select System. Otherwise, proceed to the next step.
        • Scroll down until you reach and select About phone. Enable Usb Debugging On Your Smart Phone - Select About Phone
        • Scroll until you reach and select Build number 7 times repeatedly.
            Enable Usb Debugging On Your Smart Phone - Select Build Number 7 Times Repeatedly
          • A tool tip may appear for a few seconds stating that "You are now a developer"
          • To confirm, Tapping Build Number again may show a tooltip stating that "No need, you are already a developer".
        • Tap your smart phone's "back" button once(previous screen), then scroll up or down and select Developer options. Enable Usb Debugging On Your Smart Phone - Select Developer Options
        • In the Developer options window,Turn On the top most button slider to allow "development settings". Enable Usb Debugging On Your Smart Phone - Allow Development Settings - Step 1 Enable Usb Debugging On Your Smart Phone - Allow Development Settings - Step 2
        • Scroll down or up till you find USB debugging and turn On the bottom slider to allow "USB debugging". Enable Usb Debugging On Your Smart Phone - Allow USB Debugging - Step 1 Enable Usb Debugging On Your Smart Phone - Allow USB Debugging - Step 2
    • # Running The App On Your Device(Smart phone) (SECTION B)

      • Once you've set your phone in debugging mode as explained above and your physical smart phone is still connected to your Computer / Laptop, make sure that the Notification window states that "Android system. USB debugging connected." Run App On Smart Phone - Notification Window States That 'Android System. USB Debugging Connected'
      • Now we will edit the run/debug configuration settings to make sure that when we click the Run button in Android Studio, our app will run on our smart phone.
      • In Android Studio's tool bar, click Run > Edit Configurations... Run App On Smart Phone - Run - Edit Configurations
      • In the Run/Debug Configurations window, under Deployment Target Options, select "Open Select Deployment Target Dialog" .Then click the Ok button. This will allow us to have a window automatically opened up for us when we click the Run button in the tool bar for more Run options. Run App On Smart Phone - Run - (Debug) - Configurations Dialog Window
      • Now click the Run button in the tool bar. Then click Run 'app' to open up a Select Deployment Target dialog box where we can click the connected smart phone to run our app. Run App On Smart Phone - Run - Run App In Toolbar Run App On Smart Phone - First Time Select Deployment Target Window
      • Now, as you can see from the image above, my smart phone was detected, but had a label of UNAUTHORIZED. For some reason it wasn't able to know that my phone was in debugging mode. I had to turn debugging Off and On from Settings app > Developer options > USB debugging 'Debug mode when USB is connected' . After that, my smart phone prompted me with an Allow USB debugging dialog box with the computer's RSA key fingerprint Tap the box to 'Always allow from this computer'. Then click the Ok button to accept. Run App On Smart Phone - Allow USB Debugging (Computer RSA Key Fingerprint)
      • After that, your smart phone should be successfully detected by Android Studio as shown in the diagram below. i.e TECNO TECHNO WX3P (Android 7.0, API 24) Run App On Smart Phone - Android Studio - Phone Detected
      • Click Ok. Android Studio may prompt you with an Instant Run dialog box. Instant Run allows you to push code changes without building a new Android Package (APK). But for our use case, we will keep things simple by clicking Proceed without Instant Run button. Run App On Smart Phone - Proceed Without Instant Run
      • After that Android Studio will build an Android package for your smart phone and run it. The building process may take some time depending on your machine.(It took 2 minutes for my case).Run App On Smart Phone - Console After Build On Phone APK
      • Yes!. This is it. We built our first app that displays "Hello World". Hooray!!, If all went well, you should be able to see your first Android app launching on your smart phone as shown in the diagram below. Run App On Smart Phone - Final App Phone Hello World
      • If you made it to this point, am proud of you.
    • # Running The App On An Emulator

      • Assumptions:

      • I assume you have an Android Emulator installed on your machine.
      • . The emulator simply simulates (mimics) actual Android devices on your computer so that you can test your application on a variety of devices and Android API levels without needing to have multiple physical devices.
        1. # Let's open android studio and try creating an Android Virtual Device (AVD).

          • On the toolbar, Click Tools>AVD Manager.Creating An Android Virtual Device - Open AVD Manager
          • When the AVD Manager window opens up, Click the Create Virtual Device... button. Creating An Android Virtual Device - Create Virtual Device Button
          • In the Virtual Device Configuration window on step Select Hardware , Select Phone as your category, then choose the virtual phone you plan on creating. In my case, I went for Pixel 2. Leave other settings as they are for now and click the Next button. Creating An Android Virtual Device - Select Hardware (Virtual Device Configuration)
          • In the Virtual Device Configuration window on step System Image , Select a system image of your preference. In my case, I went for the latest at the time of writing this article which is Q as the release name with API Level 29. If the system image wasn't download prior to this step, you will get a warning A system image must be selected to continue. To resolve this, click the Download link next to your preferred system image to download it. Creating An Android Virtual Device - Select System Image (Virtual Device Configuration)
          • From the step above, the SDK Quickfix Installation window will open up to show you the System Image download progress. Wait until the download is complete. WARNING: Be prepared to provide enough disk space for this system image. In my case, the system image was 1.1 GB. Creating An Android Virtual Device - SDK Quickfix Installation Window
          • Once installation is complete a screen displaying a successful installation process should show up. Click the Finish button. Creating An Android Virtual Device - SDK Quickfix Installation Window Complete
          • As you would notice, we no longer have a Download link next to our chosen System Image. Click Next button to proceed to the next step. Creating An Android Virtual Device - System Image Download Complete
          • In the Verify Configuration Window, Type in a name you would love displayed in our newly created system image. In my case, I labelled it "Pixel 2 API 29 Android 10". Creating An Android Virtual Device - Change AVD Name - Step 1 Creating An Android Virtual Device - Change AVD Name - Step 2
          • Finally, If all went well, an Android Device Manager window will pop up displaying a list of currently installed virtual devices. Creating An Android Virtual Device - List Of Installed System Images
        2. # Run Your App On An Emulator.


          Let's click the target device drop-down menu and choose which virtual device we would love to run our app on. In my case, I selected my newly created virtual device.( Pixel 2 API 29 Android 10 )Run App On An Emulator - Select Target Virtual Device
          • After selecting a virtual device to run on, Click the green Run button in the toolbar to run your app. Or you may go to the toolbar > Click Run > then Run 'app' which is equivalent to pressing SHIFT + F10 on a Windows machine. Run App On An Emulator - Select Run - Run App - On Toolbar
          • Android Studio will now install our app on our selected virtual device and will start the Emulator. After the install process is done, you should be able to see your app display "Hello World". Run App On An Emulator - Final Hello World App On An Emulator
          • That's it. You've now been able to build your first Android app. This is your first step to building more complex applications.
          • Subscribe to my newsletter so that you don't miss out on any upcoming articles.

# Resources:

I hope you learn a thing or two from this blog. Thanks for checking it out.

If anything is unclear or you wish to make any corrections, don't hesitate to leave a comment. Your feedback is greatly appreciated.

Sharing is caring. Share this blog to help out others getting started with building Android applications.

Au revoir!

About The Author   

Steven Mwesigwa

Software Engineer at Vogue Book Consultancy Services Ltd


Picture Of Steven Mwesigwa

Steve is currently a software developer at Vogue Book Consultancy Services Ltd and a technology author. He holds a Dip. in civil engineering from Kyambogo University. He founded and maintains stevenmwesigwa.com a website that receives more than 1.5 thousand visits per month. Steve can be reached on Twitter at @steven7mwwesigwa