In today’s article, Part 6 of the multi-part series, I will teach you how to run your Android apps on real devices. In part 4, I taught you how to test your application in the Android emulator. But, seeing your app running in the emulator is not near as rewarding as seeing your app running on an actual cellphone or tablet. Besides, before sharing your app with the rest of the world to enjoy, it’s always best to test your app on a device yourself. So, for that, I will be teaching you how to debug your app on your device using a USB cable and I will also be teaching you how to sign your application and deploy it to an actual device so that you can use it just like any other app on your device. So, let’s begin.
To get started, you will need to make sure you have a USB cable that can connect your device to your computer. You will also need to make sure that Windows can recognize the device and install the appropriate device drivers. If you have any issues connecting your device to your computer, you will need to check the website of the device manufacturer. The most commonly faced issue with connecting a device to a computer is missing drivers which can typically be downloaded directly from the device manufacturer’s website.
After you have successfully established a connection from your device to your computer, you will need to setup the device to allow remote debugging connections. To do that, go into Settings on your device and scroll to the bottom of the menu. There you will see a menu item labeled “Developer options”. Click on that menu item. There, you will find an option labeled “USB debugging”. Check the box next to that option. When you do, you’ll probably be presented with a dialog that says something about allowing USB debugging. Go ahead and click “OK” to allow it.
Next, inside Eclipse, right-click on the root of your project and select “Run As > Run Configurations…”. Click to select the “Target” tab. Check the radio button next to “Launch on all compatible devices/AVD’s”. Drop down the box just below that and set it to “Active Devices”. After you have done that, click the “Run” button and check your device. Your app should now be running on the device. Instead of choosing “Run As” when you right-click on your project, you can also choose “Debug As” and follow the same steps as before. By doing this, Eclipse will bind its debugger to your device. At that point, you can set breakpoints in your project and step through your code just like you would when using the emulator. Debugging your app on an actual device is highly recommended as it can help you identify and fix bugs before your users find them.
After you have tested and debugged your app on your device using a USB cable, it’s time to take it to the next step. By that, I mean it is time to export your app to an APK (Application Package) file that is basically an Android app installer. By having an APK, you can freely distribute your application for others to use on their devices which brings you one step closer to deploying your app on the Google Play Store.
To begin with, you have two options for exporting your application. The first option is to export it as an unsigned app. The second option is to export it as a signed app. But, what does signed and unsigned mean? According to Wikipedia, a digital signature or digital signature scheme is a mathematical scheme for demonstrating the authenticity of a digital message or document. A valid digital signature gives a recipient reason to believe that the application was created by a known sender such that they cannot deny sending it (authentication and non-repudiation) and that the application was not altered in transit (integrity). Basically, by signing your application, you are telling users that the application has not been messed with (had malware added in by a third-party) and that it is safe to install and use according to you.
If I’m not mistaken, I believe that you can distribute unsigned copies of your app on Amazon. However, it is always best practice to distribute signed copies of your app. Besides, the Google Play Store requires your apps to be signed. So, we will focus on exporting a signed version of our apps. To do that, right-click on the root (the project name in Package Explorer) of your project in Eclipse. Next, scroll down to “Android Tools” and select “Export Signed Application Package…”.
You should see your app listed in the “Project” field. If not, click the “Browse…” button, select your project, and click the “OK” button. Then, click the “Next >” button to continue to the next step of the export wizard.
On the next step, check the radio button that says “Create new keystore”. The keystore is a file that will include the information that will be used for signing your application. Next, click the “Browse…” button and select a location to save your keystore. You will also need to enter a name for your keystore. For the purposes of this tutorial, I have chosen to name my keystore “android_keystore” and have decided to save it to my desktop. However, I would recommend saving your keystore to a more permanent location than on your desktop. After you have specified your keystore location, you will need to enter a password for your keystore and enter the same password a second time to confirm that you haven’t included any typos. Make sure you use a password that you can remember because you will need to re-enter this password every time you make changes to your application and need to re-export it. After that, click the “Next >” button to continue.
On the next step, you will need to enter something for the alias, password, validity, and at least one field for the certificate issuer (information below the line). For the alias, I typically use the same name that I used for my keystore file. But, you can use something that makes more sense, especially if you plan on using multiple keystores for different projects. For the validity, as of the writing of this article, Google requires that all signatures be signed with a minimum of 30 years. Just like in the last step, make sure you use a password that you can remember because you will need it every time you re-export your app going forward. To keep things simple, I typically use the same password as the one in the last step. The rest of the fields are pretty much self explanatory. After you have everything filled in, click the “Next >” button to continue.
On the last page of the export wizard, you will need to select a location and file name to export your APK file to. Again, for the purposes of this tutorial, I have chosen to export my APK file to my desktop. But, you can export your file to where ever you want. You can also change the file name to whatever you want, but I will stick with the default file name which happens to be the name of my project with the “.apk” file extension. After you have selected your APK file destination, click the “Finish” button to complete the export process.
Now that you have successfully exported a signed copy of your Android app, you have a new keystore that can be used to sign your app every time you make changes and want to re-export your app. For that, you can follow the same export instructions as explained above. However, from now on, you will not need to rebuild your keystore. Instead, when you get to the step that asks for your keystore location, you will select “Use existing keystore”. On the next couple of steps, you will need to re-enter the same passwords you specified while building your keystore the first time.
There you have it! You now have an Android app installer that can be shared with the world. But, before you begin sending it to all of your friends, you should test it to make sure that it works. There are several ways you can do that. One way you can do that is to upload your APK file to a web server where it can be downloaded on a device via the web browser. If you want, you can upload your APK to a WordPress site or other server just as long as the file can be accessed directly. As an example, I have uploaded my APK file to the web server that is hosting this site which you can download for yourself by opening the web browser on your device and browsing to http://www.prodigyproductionsllc.com/downloads/UDPTester.apk. As soon as you press the enter key, the APK will download to your device. After the download has completed, you can execute the installer either from the messages section in Android or by manually locating it on your device using the “File Manager”.
If you do not have a web server or WordPress website to upload your APK file to, don’t worry. Instead, you can connect your device to your computer using the USB cable just like you did at the beginning of this article. With your device connected, you can open Windows Explorer where you can manually copy your APK file onto your device. If your device has an SD card of sorts and your computer has an SD card reader, you can always insert the card into your computer and copy the APK file that way, then re-insert the card back into the device.
If you do not have a way to connect your device to your computer using USB or using an SD card, you can always connect your device to your computer using bluetooth if your computer supports it. If you have a wireless network that you can connect your computer and your device to, there are ways of getting your APK file onto your device that way. Or, you can also email your file from your computer to an account that can be accessed on your device. If you still can’t find a way to get your APK onto your device, leave me a comment below and I will work with you to figure out a way to make it happen.
That’s all for now. If you followed these steps correctly, you should now have your Android app running on your Android powered cellphone and / or tablet. You are also one step closer to getting your app listed on the Google Play Store where people all around the world can find and download it. With that said, tomorrow will be the article where I teach you how to do that so that you can begin making some money from your new Android app. Until then, have fun and share your Android app stories with us in the comments below.
Create Your Own Android Apps for Fun or Profit
Part 1: Downloading and Installing Java, Eclipse, and the Android SDK
Part 2: Configuring Eclipse and Creating Your First Android App
Part 3: Creating a Layout and Adding Some Code
Part 4: Testing Your App with the Android Emulator
Part 5: Monetizing Your Android App with Google AdMob
Part 6: Running Your Android App on Cellphones and Tablets
Part 7: Publishing Your Android App to the Google Play Store