4

This is not a duplicate of Android Application creating two launcher icons (I don't have multiple LAUNCHER definitions in my manifest), nor Android Application Creating Two Launcher Icons instead of One (a restart of the device does not remove the second launcher icon).

My android application is creating two launcher icons, but one of them seems to be coming from the application itself, rather than any activity. I've cropped my AndroidManifest.xml to the smallest it can be (plus clean and rebuild and reinstall), and I am still getting two icons (on both my HTC One M8 physical phone and my Nexus 5 emulator):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity
            android:name=".SplashActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

There is nothing else in my manifest.

...does the application itself as I've defined it create an icon somehow? Or is there some other way that I'm ending up with multiple launcher icons?

If I move the android:label and android:icon features into the .SplashActivity definition, one of the launcher icons created is replaced with the default little green robot icon.

Community
  • 1
  • 1
Valkyrie Savage
  • 575
  • 2
  • 6
  • 21
  • 1
    It feels like you are picking up an activity from some library that you are using. If you are on Android Studio 2.2 or higher, open your manifest and switch to the "Merged Manifest" sub-tab at the bottom, and see if there is another activity showing up there. – CommonsWare Jan 24 '17 at 21:41
  • I never knew about that view! I did indeed find another `LAUNCHER` activity in there. Thanks @CommonsWare . :) – Valkyrie Savage Jan 24 '17 at 21:44

2 Answers2

7

Activities and other bits of manifest-y goodness come from a variety of sources:

  • the manifest in your main sourceset
  • the manifest in any build type or product flavor sourceset
  • the manifest in any library module or AAR
  • Gradle (e.g., minSdkVersion)

Android Studio 2.2 gave us a convenient tool to examine the real manifest that goes into our APKs, merged from all those sources. If you open the manifest in Android Studio, click over on the "Manifest Merger" sub-tab (towards the bottom of the IDE). That will show what is in the merged manifest and who is to blame for it where it came from.

If you see other activities in there besides the one in your manifest, that is the source of your launcher icon. Then, you'll need to decide:

  • is that activity something you really want?
  • if not, is the source of that activity something that you really want? (if not, nuke it)
  • if you want the source but not the activity, you can rig up another activity element in your manifest, with a tools:replace attribute, to override the one from the library and suppress the <intent-filter>
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I have action "android.intent.action.MAIN" defined for 2 activities but I want to show one of them only. Can I use tools:replace to override the action Main of the 1st activity (read only as coming from a lib) – Tushar Gogna Sep 25 '20 at 08:28
  • 1
    @TusharGogna: "Can I use tools:replace to override the action Main of the 1st activity (read only as coming from a lib) " -- yes. Create an `` element whose `android:name` matches that of the activity from the library, and you can then control that particular activity's manifest entry from there. – CommonsWare Sep 25 '20 at 11:15
  • 1
    I tried it by adding `` in the activity tag keeping the same name but it doesn't seem to be working. I did same with `` ! The name of the activities are same: basically the whole path.ActiivtyName. Do I need to do anything else as well? – Tushar Gogna Sep 25 '20 at 13:22
  • @TusharGogna: I recommend that you ask a separate Stack Overflow question, where you can provide a [mcve] showing your manifest attempts, along with details of the activity that you are trying to suppress. – CommonsWare Sep 25 '20 at 14:40
  • Yes, here is the question: https://stackoverflow.com/questions/64066594/android-manifest-merger-warning-related-to-no-other-declaration-present – Tushar Gogna Sep 25 '20 at 14:57
5

My problem was, that I've added the following intent-filter to multiple Activities. Configured it for one Activity fixed the issue for me.

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
Manuel Schmitzberger
  • 5,162
  • 3
  • 36
  • 45