Your Android app is removing all shortcuts on every update?

Interesting and in some way unusual story happened last week.

We recently released major update to our Taxi app for Android.
We already had a very smooth CI which allowed us to stream builds to the Google Play Market like every day.

So we were all happy and improved the app on daily basis. Ideal, right?

Then we received these reviews:

…enough updates, please

…stop updating the app

…every update I have to re-create shortcut for your app on my Android desktop. So annoying!

Android since 2014 supports automatic app updates.
That is every time our CI releases new update, our users loose shortcuts and basically app is not visible to users and annoys them.

Great!

What is going on with this Android app

Searching for clues, we found post on reddit where users were complaining about same problem.
We also found several SO answers

http://stackoverflow.com/questions/6451064/application-icon-removed-from-home-screen-on-upgrade

http://stackoverflow.com/questions/15730119/android-app-shortcut-has-to-be-recreated-after-update

So now we knew that the launcher activity is being changed somehow.
But how? We did not change it for ever, since app birth it was SplashScreen activity 🙂

Xamarin.Android comes to play

At some point of time guys from Xamarin introduced a new feature “Android Callable Wrapper Naming”.

With the 5.0 release, the default package names for Android Callable Wrappers will be based on the MD5SUM of the assembly-qualified name of the type being exported. This allows the same fully-qualified name to be provided from two different assemblies and not get a packaging error.

Your manifest during build is changed by Xamarin from:

<activity android:name="com.dt.taxi.SplashScreen">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

to

<activity android:name="md5f2a67a226b04d2532111111111111ab616.SplashScreen">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

The problem, however, is that this MD5 stuff changes from build to build. Yep.

So next time you release the app, you will have

<activity android:name="md5f2a67a226b04d2532232323232323ab616.SplashScreen">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Clearly, users will loose their shortcuts for each of the Xamarin.Android app on each update.

Fixing the glitch

Gladly, fix is very simple.
Same Xamarin.Android documentation page tells

Then to maintain compatibility with your scripts/external code, set the ActivityAttribute.Name property:

That is you just need to add an attribute to your main activity/launcher activity. In our case, this will look like:

[Activity(Name="com.dt.taxi.SplashScreen")]
public class SplashScreen : MvxSplashScreenActivity

With that attribute, Xamarin.Android build is smart enough to understand you have that activity registered in the AndroidManifest.xml and there is nothing to do.

How to reproduce/test that scenario

In order to test that, you just need to produce two subsequent builds of the same app.

  • Download .apk files to the device
  • Install older version (version 1) by clicking the apk
  • Create shortcut
  • Install newer version (version 2) by clicking the apk – system will actually update installed app
  • If you did everything correct, shortcuts will remain on desktop. Otherwise read the post again.

Here is a video showing all these steps and reproducing the problem.

IMAGE ALT TEXT HERE

Credits

We’re thankful to the Xamarin Support team who helped us to find the root cause of this weird behavior.

Always yours, DT.