Programming

Publishing Xamarin.Forms.Android Application to Google Play

So, I recently had to publish a Xamarin.Forms.Android Application to Google Play. I experienced a few bumps along the way, but finally succeeded this very evening.

Preparing the .APK

First of all, you want to make sure that you disable debugging, specifiy an application icon, version the application and configure your linker.

Afterwards, you’ll need to build the package in Release mode. No problem, right?

Well, I personally experienced a “COMPILETODALVIK : UNEXPECTED TOP-LEVEL” error while doing so, which, apparently was related to Xamarin.Forms.Maps.

If you experience this issue, it can either be due to missing permissions in your Android Manifest or the Heap Size. This is all explained in the previous forum discussion.

After resolving the error, I was finally able to clean & rebuild the solution.

Signing the .APK

Now, for signing the .APK, instead of using the command line tools, you can simply use the tools provided in Visual Studio.

Simply navigate to “Tools” –> Android” –> “Publish Android App…” in the Visual Studio menu, and select “Create new keystore”.

After you have created your keystore, select where you want your signed .apk to be built to and click “Publish”.

Publishing the .APK

Now, in your “bin/Release” folder, you will have two .apk files generated.

So, here I was, thinking to myself, that I could simply upload the signed version of the .APK.

But alas, when I tried to do so, I was told (no matter what I did) that the .APK was, to my amazement, not zipaligned correctly.

I also did try to upload the aligned .APK which was generated from the publishing process, but to no avail.

So, before I was able to publish, I needed to zipalign the signed version of the .APK.

So, what I did was to grab a copy of the .APK which said “Signed” under “bin/Release”.

I then navigated to where my Androd SDK was located, and jumped into “android-sdk\build-tools\<version>” and for ease, pasted my .APK here.

Note: if you are unable to locate this folder, you probably havn’t insstalled the build tools. You can install the build tools in Visual Studio under the Android SDK Manager.

I then popped open a terminal and navigated to the build tools folder, and typed in the followng command (I, ofcourse, replaced “helloworld” with the name of my application):

Afterwards, I was finally able to upload my .APK to the Google Play Store.

Victory!

// Dave

Standard
Programming

OxyPlot and Xamarin.Forms Unified API

I finally figured out what was wrong with my references in my iOS project!

Once I uninstalled OxyPlot.Xamarin.Forms, and installed the new 707-alpha PR, it was for “some reason” (actually a very good one, which you’ll see later) still referencing the Classic iOS OxyPlot.Xamarin.Forms API.

I was frustrated by this fact, since, when I created a new project, this was not an issue at all. This got me thinking.

Once upon a time, when I started my project, I was running Xamarin.Forms 1.2.3, and I have by now simply upgraded to the newest version (1.3.1.6296). I did some refactoring of my classes based on the post below, and thought that I was now running the Unified API:
http://www.infinite-x.net/2014/10/09/xamarin-forms-1-3-0-preview-formapplication/

Alas, upon further investigation, I found , that I had in fact NOT upgraded to the Unified API in my .csproj file:
http://developer.xamarin.com/guides/cross-platform/macios/updating_ios_apps/#Steps_to_Update_Manually

I followed the steps, removed OxyPlot, re-installed the 707 OxyPlot.Xamarin.Forms PR from the NuGet Package Manager Console.

Hereafter, everything worked as expected, and I could finally include the OxyPlot.Xamarin.Forms package for the Unified iOS project as described in the OxyPlot documentation: http://oxyplot.org/documentation/hello-xamarin-forms

// David

Standard
Xamarin, Android and Virtualbox
Programming

Deploying to Xamarin Android Player from VirtualBox

Everyone who has ever developed an Android application is aware that the Android Emulator available in the Android SDK is currently awfully slow. You can boot up an emulator when you arrive at work, and later that month you will be lucky if the emulator has started (obviously exaggerated, but you get the point).

To accomdate for the performance issue just mentioned, other tools such as Genymotion (paid) or the newly introduced Xamarin Android Player (free) can be utilised, where this guide will focus on the ladder. The problem is meanwhile, that none of the two will work if you use a virtual environment for development purposes, as they are virtual images themselves, running in VirtualBox by Oracle.

So, for that reason, this guide will explain how you can deploy your application, developed in any given IDE running on your Guest OS, to Xamarin Android Player running on a Host.

Prerequisites

Before walking you through the configuration, it is important that you have the following items installed:

  • VirtualBox – or any other virtual environment (this guide was written using Windows as a Guest OS)
  • The Android SDK (on both your Host and Guest OS)
  • Xamarin Android Player (on your Host OS)

Step 1) Configuring Xamarin Android Player

To start with, several different actions are required to be performed on your Host OS which are explained in detail in the following sections.

Step 1.1) Adding Environment Variables

OS X

  1. Open a terminal, and write “touch ~/.bash_profile; open ~/.bash_profile”
    1. This opens a text editor with your .bash_profile page
  2. In this file, add your android installation path
    1. export ANDROID_HOME=/Users/<user>/Library/Developer/Xamarin/android-sdk-macosx/android-sdk-macosx
    2. export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
  3. Save and close the file
  4. To execute the changes immediately, type “source ~/.bash_profile”
  5. Lastly, in the terminal, type “adb”
    1. If this works, then the environment variables are set up correctly

Windows

  1. Right-click on “Computer” and click ”Properties”
  2. Next, click on “Advanced system settings” on the left hand side of the window
  3. Now click “Environment Variables” in the window that pops up
  4. Add a new “System variable” called “ADB_HOME”, with the value as the path to the platform-tools folder for your android sdk normally located at:
    1. C:\Users\<user>\AppData\Local\Android\android-sdk\platform-tools
  5. Now, find the “Path” variable in “System variables” and add “%ADB_HOME%” to the end of the string
  6. Open a terminal and write “adb”
    1. If you see the list of available actions, the path is now set up correctly

Step 1.2) Retrieve the IP

Having set up the environment variables, but before connecting to the Android Emulator from your Guest OS, it is required to obtain the IP adress of the Emulated Device. To do so, simply follow the steps below:

  1. Launch an Android Emulator in Xamarin Android Player
  2. Open a terminal window and write “adb devices”
  3. Note down the IP address of the Emulated Android Device

 Step 2) Configuring the Guest OS

Having retrieved the IP from the Emulated Android Device, you can now move on to actually establish a connection between your Guest and Host OS to deploy applications to Xamarin Android Player.

Step 2.1) Configure your network settings

First, it is required to configure the network settings in VirtualBox, as the emulator otherwise not will be reachable:

  1. In the menu of VirtualBox, navigate to “Devices” → “Networks” → “Network Settings”
    1. In this window, under the “Network” settings, choose the “Adapter 1” tab
    2. In the  “Attached to” dropdown list, choose “NAT” (Network Access Tunnel)
    3. Click “OK

Note that, before procedding to the next section, you should wait untill your connection has been established anew, as the tunnel is essential for the next step.

Step 2.2) Test the connection

Since you have reached this section, your progress indicates that your internet connection has been re-established, and so has the connection to your the Host OS from the Guest.

This means, that you by now should have the possibility to deploy applications written in your Guest OS to your Android Emulator running on your Host OS.

To test whether or not that is actually the case, simply follow the steps below:

  1. Open a terminal
  2. Type “adb connect <ip>”
    1. “<ip>” is the ip and the port of the Emulated Android Device from Xamarin Android Player
    2. Now, if everything is set up correctly, the terminal will state “connected to <ip>:5555”

Now, independently of which IDE you utilse, you should be able to choose the Emulated Android Device from Xamarin Android Player running on your Host OS as your Target Device in the IDE of your Guest OS.

// David

Standard