jackomo
jackomo

Reputation: 375

Xamarin Forms Android project causes two app icons

I have a PCL-based Xamarin Forms solution using Xamarin.Forms version 2.3.4.270.

When building the Xamarin android project in Visual Studio 2017, in the autogenerated "...\obj\Debug\android\AndroidManifest.xml" file of the android project there is a mysterious activity added that causes two app icons to be deployed when running the app on a phone:

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

I made sure that none of the projects in the whole solution is marked with "Enable Code Analysis on Build" and I have only one main activity with "MainLauncher = true"...

When starting the first app icon, only a blank empty view is shown. When starting the second app icon, the real app is started.

How can I get rid of the aditional app icon on android?

EDIT: This is the MainActivity:

[Activity(Label = "@string/app_name", Theme = "@style/MyTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity

And this is the SplashScreen-Activity with MainLauncher=true:

[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)]
public class SplashActivity : AppCompatActivity

I have used this approach in various other xamarin.forms applications with no issues yet.

Here is the Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="@string/package_name" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
    <uses-sdk android:minSdkVersion="15" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:label="@string/app_name" android:icon="@drawable/icon"></application>
</manifest>

Upvotes: 2

Views: 2423

Answers (1)

jackomo
jackomo

Reputation: 375

This issue was due to a pcl dependency that wanted to fix a code analysis issue by adding a new activity with MainLauncher = true.

See https://bugzilla.xamarin.com/show_bug.cgi?id=43553.

The Android implementation of the pcl library added an additional activity. In the main xamarin android project, Visual Studio included this activity in the manifest file.

So all in all the solution for the code analysis issue for android pcl libraries as described in the link, causes two app icons.

To remove the second app icon, just set the "MainLauncher" of the pseudo activity property to false. This will still let you run the code analysis but will not add a second app icon.

Upvotes: 7

Related Questions