As the name suggests, in this column I am going to show you how to run and debug your hybrid application from Visual Studio on your Android device. We will not be covering iOS here but in a later post.
If you have attempted to run your application on your Android device and you were not successful, read on.
First of all, to run your application on your device, you need to select the “Device” mode in Visual Studio.
When you try to run the application on your device and although your device is connected, you may see the following error:
As you might have noticed, it is certainly not informative and you may knock yourself out trying to find out what is going on.
Step 1: Install Android SDK Packages
You will need to locate the Android SDK installation directory such as AppDataLocalAndroidandroid-sdk and open up the SDK Manager. The manager will list the packages that are installed and those that aren’t. It will also tell you if you need to update the packages. Just review the list of packages and click Install Packages. Once the SDK Manager finishes installing the new packages, it’s time to Build the project again.
Step 2: Connect Your Device
At this point you will need to have your Android device connected via USB cable and you need to have the USB drivers installed on your computer. Although I had mine connected, I was getting the following error:
Step 3: Enable Developer Options and Check USB Debugging
You need to make sure that you have Developer Options enabled on your phone. On Samsung devices with the latest Android, it’s hidden by default. Once it’s enabled, you need to make sure that USB Debugging is checked.
Step 4: Android SDK and List Devices Command
Although I had USB Debugging checked on my Samsung Galaxy S4 and I was able to browse its content from Samsung Kies, I was still getting the same error.
If you’ve done any development on PhoneGap before, this may seem familiar. If not, you will be glad you’re here. Check your Environment Variables and make sure that you have the SDK and the Platform referenced in your PATH.
Now you can open up the Command line, browse to your Platform tools installation under the SDK and try to run the “adb devices” command to list the Android devices that are connected to your machine.If you see any device listed, then luck is in your favor and you can now deploy the application to your device. If you were unlucky like me, you will see the following:
Step 5: Stop and Start ADB Server
After looking at the android developer documentation, I realized that there is a command to kill and restart the ADB server. Simply run “adb kill-server” then “adb start-server” and now you should be able to see your device once you run “adb devices”.
Step 6: Run Your Application
At this point you are ready to run the application and let Visual Studio deploy it to your device. Just hit Run with Device mode selected and your application will be transfered to your device momentarily.
In a previous post we’ve seen how easy it is to get started building Hybrid apps using Visual Studio. Deploying the application and debugging it on your Android device turned out to be a different story. This is when you realize how invaluable platforms like the Telerik Platform are. They solve all the headache related to deploying and debugging your application on your device. It’s time to get back to working on my AppBuilder project.