Skip to end of metadata
Go to start of metadata

Objective

In this chapter, you will learn how to deploy an Android app to a device for testing.

Contents

Configure the Android device

In order to install an application directly to your device, you need to configure it to use a USB connection.  The configuration settings vary by device.

For 2.x and 3.x Devices:

  1. Open Settings.
  2. Click Applications.
  3. Enable Unknown sources, that is, check this option.  This permits the device to install apps that do not originate from Google Play.
  4. Click Development.
  5. Enable USB debugging, that is, check this option.  This permits the device to install apps over a USB connection.
  6. (Optional) Enable Allow mock locations, that is, check this option.  This option creates fake GPS locations to test location services.
  7. (Optional and if available) Enable Stay awake, that is, check this option.  This option keeps the screen on and disables the lock screen while the device is connected to USB.
  8. Back out of or close Settings.

For 4.x Devices:

For Android 4.2 and later devices, you need to enable Developer options by opening Settings, click About then click the Build number item seven items.  If you do not do this, you will not see the Developer options item in Settings.

  1. Open Settings.
  2. Click Security.
  3. Enable Unknown sources, that is, check this option.  This permits the device to install apps that do not originate from Google Play.
  4. Back out to Settings.
  5. Click Developer options.
  6. (If available) Set the switch in the title bar to on.
  7. Enable USB debugging, that is, check this option.  This permits the device to install apps over a USB connection.
  8. (Optional) Enable Stay awake, that is, check this option.  This option keeps the screen on and disables the lock screen while the device is connected to USB.
  9. (Optional) Enable Allow mock locations, that is, check this option.  This option creates fake GPS locations to test location services.
  10. Back out of or close Settings.
Icon

These configuration settings are the default Android settings. Some options may not appear or you may need to configure other manufacturer-specific settings.

Install the USB driver (Windows only)

Developers on Windows may need to install a USB driver specific to the manufacturer, sometimes even the make of the device on which they'll be testing. The driver enables your Windows computer to communicate with your Android device. Google provides download links to the drivers at Android Developer: OEM USB Drivers.

Connect the device

Connect the Android device to your computer using an USB cord.  Note that some USB cables are only power cables and do not allow a data connections.  Make sure you use a USB cable that allows a data connection.

For 4.3 devices, a "Allow USB debugging?" dialog appears.  Optionally enable the Always allow from this computer checkbox. Click OK.

For 3.x and later devices, make sure when you connect your device that it is connected as a media device or for USB debugging.  After connecting the device, pull down the notification tray.

  • If you see a Connected as media device item, you have the correct USB setting.
  • If you see a Connected as camera item, click this item to open a dialog. Check the  Media device (MTP) option and uncheck the Camera (PTP) option.  Hit the Back or Home button.
  • If you do not see either option and you see USB debugging connected, your device is connected for USB debugging.
  • If you do not see any of these options, make sure you correctly followed the directions in the previous sections.

Deploy the application using Studio

Once you have configured your device and connected it to your computer's USB port, you are ready to deploy your app to it.

In Studio, first select the project in the Project Explorer view, then in the global tool bar, select Run from the Launch Mode drop-down list and an Android device from the Target drop-down list under the Android Application Installer category.  If the Launch Automatically option is enabled under the Target drop-down list, the application will be automatically launched after the device is selected.  If not, you need to click the Launch button to start the build process.  Your app will be built, installed to your device and automatically launched.

Prior to Studio 3.2.0:

Make sure only one device is connected to your computer.  In Studio, click on the Run menu as shown, then choose Android Device

Deploying the application using the CLI

To launch the application using the Titanium CLI, run the following command: 

You may omit the --device-id parameter if you only have one device connected.  To retrieve a list of connected devices, run one of the following commands: 

Deploy the application using adb

You can use the adb command to install apps to a connected device if you have a built APK file. If the platform-tools directory (within the Android SDK) is in your system's PATH, from a terminal, run the following command:

Hint: use the -e switch to interact with a single running Android emulator; use -d to interact with a single connected device.

You can uninstall an app with adb as well:

Deploy to remote testers

You can deploy your app to remote users for testing. They will need to configure their device as described above. From there, all you need to do is get the APK file to them and their device. A simple solution is to post it on a web site (such as a Dropbox) account. You could also email it to them, as long as they receive the email on their device and not a desktop. In either case, on a device, if you tap on an APK file, Android will prompt you to install that application.

Over the air distribution frameworks were popularized in the iOS space by services such as TestFlight App. With such systems, users install a common client app on their device. That client interacts with a remote server, which is used to distribute beta versions of your app. When you update your app, the client component can detect the change and notify the user to upgrade your app. The open source HockeyKit system (http://hockeykit.net/) supports distributing both iOS and Android apps to beta testers. It also provides a framework for gathering user feedback and statistics. You can install HockeyKit on your own web server or subscribe to their HockeyApp service and they'll host the server for you.

Install to the SD Card

By default, your application is installed to the device's internal storage.  To configure you application to install to the SD card, you need to add the android:installLocation attribute to the manifest element in the tiapp.xml file.  This attribute is supported on Android 2.2 (API Level 8) and later.  Assign the installLocation element one of the following values:

  • preferExternal -- specifies that you prefer your app to be installed to the SD card, but if one is not present the app can be installed to internal storage.
  • auto – specifies that the phone's configuration will determine the installation location. Generally, your app will be installed to internal storage if sufficient space is available. In that case, users could still move your app by opening Settings > Applications > Manage applications or Settings > Application manager, tapping your app, and tapping Move to SD card.  Note that some manufacturers do not allow applications to be run from the SD card.
  • internalOnly – which specifies that your app cannot be installed to the SD card. See the Android docs for the various reasons why you might choose this option.
tiapp.xml

Change the version number

To change the version of the application, add the following attributes to the manifest element in your tiapp.xml:

  • android:versionCode - The versionCode cannot be a floating point number like "0.9", it needs to be a whole number like "2". The versionCode must be an int and each time it is submitted to the market must be greater than the last time.
  • android:versionName - The versionName can be anything you want.
tiapp.xml

For more information on versioning in Android, see http://developer.android.com/guide/publishing/versioning.html.

Troubleshooting

Restart adb

If your device is not recognized after following the above instructions, the adb process may have hung.  Run the following commands in a terminal to restart adb: 

USB cord

Some USB cords are only power cables and do not allow a data connection.  Make sure that your USB cord allows a data connection.

Summary

In this chapter, you learned that deploying to an Android device is fairly simple. You configure the device to accept non-market apps. Then, you just need to get the APK file to the testing device. You can do that via Studio, adb, an ad-hoc distribution method like a web page, or via a framework like HockeyKit.