Subscribe / Unsubscribe Enewsletters | Login | Register

Pencil Banner

Android Studio for beginners, Part 3: Build and run the app

Jeff Friesen | Aug. 24, 2016
Build your app with Gradle, then run it on an Android device emulator or Kindle Fire tablet

In Part 2 you created your first animated mobile app using Android Studio. Now in Part 3 you'll conclude your introduction to mobile application development with Android Studio. First, you'll use Gradle, an open source build automation tool, to build the app's application package (APK) file. Then you'll get instructions to set up and run the app on an Android device emulator or a Kindle Fire HD tablet.

Building the app

You've loaded your source code and resource files into your Android Studio project and now you're ready to build your app for the first time. In the project window you'll see that Android Studio provides a Build menu. You'll use this menu to access Gradle and build W2A.

Under Gradle in the project window, select Rebuild Project. Gradle will start the build process, which may take a minute. If all goes well, the Gradle Console window should soon show a BUILD SUCCESSFUL message.

androidstudiop3 fig1

Figure 1. Gradle shows a BUILD SUCCESSFUL message when a build completes

Instead of selecting Rebuild Project, you could attempt to run the app directly. In this case, Android Studio would instruct Gradle to rebuild the project. Assuming a successful rebuild, Android Studio would ensure the app's APK file (containing executable code, resources, and other information) was installed on your real or emulated Android device, then run the app. (Note that in some cases using Instant Run makes it unnecessary to restart the app.)

Additional tasks

In addition to a basic build feature, Android Studio's Build menu lets you do a number of useful build tasks. For example, notice the Build APK and Generate Signed APK menu items, which you can use to build a signed version of the app's application package file, or a version used specifically for debugging.

Go further with Gradle

Google provides various tips for getting more out of the Gradle build system. For example, one tip focuses on improving build server performance.

Running the app

Also in the project window, the Run menu provides menu items for running and debugging an app. In this section, you'll learn how to run W2A on an emulated device and on an Amazon Kindle Fire HD tablet.

Running W2A on an emulated device

You can run W2A or another app by selecting the Run menu's Run 'app' menu item. Alternatively, you can click the green triangle button on the tool bar. Either way, Android Studio responds with the Select Deployment Target dialog box.

androidstudiop3 fig2

Figure 2. The Select Deployment Target dialog

Because I'm using a non-Intel processor and have yet to set up the Amazon Kindle Fire HD tablet, my only option for running the app was to use an emulator. The dialog box identifies a single emulator that I couldn't use because Android Studio is unable to parse its properties. To work around this, I clicked Create New Emulator button. Android Studio responded with the Virtual Device Configuration dialog box showing a variety of emulators. Nexus 5x is highlighted below.

 

1  2  3  4  Next Page 

Sign up for CIO Asia eNewsletters.