From UWP development to using Xamarin Forms to release an application to the Android Play Store [Part 5]

Delaire Damien
4 min readJan 2, 2020

In my previous articles I went over my journey of building an application that runs on multiple platforms. My original application was a classic UWP application, I tried to build the same application on different platforms to in a 4 hours time box.

Also in the previous articles we went over the different steps/issues/bugs that I encountered and now I tried to over come them, in the end because I am a XAML/C# developer going with Xamarin Forms XAML was my best bet to try and get a working application going. I am sure that someone with a different skill set would a have taken another path, as they say all roads lead to Rome.

This story was broken into 5 parts:

As must of you know building an MVP is easy however releasing it to production is harder :)

Here is the list of the features that I needed to add before I could release it to the Google Play Store:

  • Audio player
  • db for cache, and saved favorite radios from user
  • Settings view
  • Search
  • Tracking
  • Ads
  • Build for Release

Getting the rest of the application working:

Audio for Android XF

Being able to read a stream was not as easy as I would have hoped, but the Xamarin Team has created a MediaManager Plugin for Xamarin which can be found here. I also played with Google ExoPlayer library for Xamarin which can be found here. (FYI MediaManager is based on top of ExoPlayer for Android).

I ended up using Google ExoPlayer library for Xamarin as I only needed it to work for my Android application, I did not need to extra layer that was added by the MediaManager Plugin for Xamarin.

Database

My UWP app was using Entity framework, getting it to work for Xamarin Android Forms was strait forward. In my DbStorageContext which is located in my MyAudio.Common (.Net Standard library) I just reworked the OnConfiguring method and added a service using dependency injection to get the correct db path depending on which platform I was on (in other words nothing crazy) .

Here is the GetDatabasePath method that returns the correct path for Android (I have not tested for IOS). The DatabaseService class is located in my shared Xamarin solution.

Tracking — Xamarin.Firebase.Analytics

After adding the Xamarin plugin to correctly use Firebase Analytics in my Android app I had to use the Xamarin dependency injector and not MVVMLight because this needed to be initialized in the MainActivity.cs file as follows:

DependencyService.Get<IAnalyticsService>().SendInitData(FirebaseAnalytics.GetInstance(this));

In the CS of my views on the method OnAppearing I also had to use the classic Xamarin Forms dependency as follow to log a page view:

protected override void OnAppearing()
{
base.OnAppearing();
DependencyService.Get<IAnalyticsService>()
.LogPageView(AppConstants.Pages.MainPage);
}

Ads — ViewRenderer

Adding ads allowed me to create custom ViewRenderer which I had not done before. Here is quick view of what my AdMobViewRenderer.cs file looks like.

Which was base on this one.

And here is the View which allows me to show ads in my app

by calling this:

<ads:AdMobView Grid.Row="0" AdUnitId="ca-app-pub-6723289/1423225" />

Build for Release — DEX / code shrinker / linking — wait/what?!?

Google Play Store does not allow you to upload an application that is more then 100 MB which is an AWESOME idea, however for me it means that my tiny Radio app was to fat by 20 MB.

And here is were it got quite complicated me, R8 / DEX / Progard/ code shrinker / linker are my new horror words… After a lot of reading and testing I am just starting to understand how these work.

It was a lot of trial and error to see which best configuration worked for me but long story short activating the code shrinker would always generate an error when launching the app in release mode.

Here is a screenshot of what works for me and my application:

By generating one package per ABI (armeabi-v7a/arm64-v8a/x86/x86_64) I was able to create smaller packages (of about 70MB) that I could upload to the store.

And this is my story of how I started porting my audio application to other platforms. However the story will not end here as this has given me lots of new idea and things that I wish to test. Now that my audio application is the the Google Play Store can I build a Release version of the same application but with Xamarin Android (not Forms) and what about Blazor?

[Update 21 jan 2020] App Bundle

Ask and you shall be served here is another way to reduce your application size by as much as 50% by using Android App Bundle on App Center, you can fidn the full post here:

More

Here is the full list of what I plan on working on and writing about:

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Delaire Damien
Delaire Damien

Written by Delaire Damien

Technical Lead on (Windows & Smart TV apps) @Dailymotion, Windows Mobile/ Xbox/ Desktop Lover. Entrepreneur in spirit, I love working on side projects

No responses yet

Write a response