Faiz
Faiz

Reputation: 6980

Flutter AndroidManifest.xml Error: package identifier or launch activity not found

I'm working on a Flutter project for Android and encountered an error related to the AndroidManifest.xml file. When trying to run my project, I receive the following error message:

package identifier or launch activity not found. Please check /Users/[user]/AndroidStudioProjects/[project]/android/app/src/main/AndroidManifest.xml for errors.
No application found for TargetPlatform.android_arm64.
Is your project missing an android/app/src/main/AndroidManifest.xml? Consider running "flutter create ." to create one.

I've checked my AndroidManifest.xml, and it seems correct. The error persists even after ensuring that the package name and target platform are set correctly.

Can someone please provide guidance on how to resolve this issue? What could be causing this error, and what steps should I take to troubleshoot and fix it?

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.webjow.hidden_gallery"
    xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="32"
        tools:ignore="ScopedStorage" />
    <uses-permission
        android:name="android.permission.READ_EXTERNAL_STORAGE"
        android:maxSdkVersion="32" />

    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

    <uses-permission android:name="android.permission.USE_BIOMETRIC" />
    <uses-permission android:name="com.google.android.gms.permission.AD_ID" />

    <application
        android:name="androidx.multidex.MultiDexApplication"
        android:allowBackup="false"
        android:fullBackupContent="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:manageSpaceActivity=".MainActivity"
        android:requestLegacyExternalStorage="true"
        android:usesCleartextTraffic="true"
        tools:replace="android:label"
        tools:targetApi="34">

        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxxx~xxxxxxxxxx"/>

        <activity
            android:name=".MainActivity"
            android:theme="@style/LaunchTheme" />

        <activity-alias
            android:name="OneLauncherAlias"
            android:enabled="true"
            android:exported="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:targetActivity=".MainActivity"
            android:theme="@style/LaunchTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity-alias>

        <activity-alias
            android:name="TwoLauncherAlias"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/calculator"
            android:label="@string/app_name_fake"
            android:targetActivity=".MainActivity"
            android:theme="@style/LaunchTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity-alias>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

Additional Information:

Flutter version: 3.13.5 and Dart version: 3.1.2

Upvotes: 5

Views: 5717

Answers (9)

M Nasir Baloch
M Nasir Baloch

Reputation: 163

My issue was resolved by adding the namespace in the app/build.gradle file under the android section, like this:

android {
    namespace "com.example.your_app_name"
}

Upvotes: 1

Felix K
Felix K

Reputation: 88

I don't know why, but the Firebase Code Generation tool destroyed my build.gradle.

The namespace was simply half empty, the generation tool made this out of my working build.gradle

enter image description here

I needed to fix it so it looks like

enter image description here

Upvotes: 1

Olasiyan Daniel
Olasiyan Daniel

Reputation: 11

try removing the android folder

then press the "flutter create ." on your terminal. this will regenerate the folder afresh and resolves the problem

flutter create .

Upvotes: 1

Abdulaziz Alnahhas
Abdulaziz Alnahhas

Reputation: 138

In my case,I've Solved this issue by adding 'package' attribute in tag 'manifest' it was missing for some reason

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.pachage.name"> <---- here
......
</manifest>

Upvotes: 4

user24757638
user24757638

Reputation: 11

This is a bug in the flutter_tools . This plugin code has NO error. You can verify it by generating an apk using flutter build apk.

The error occurs while running by flutter run. It only happens when activity-alias is used as an android.intent.category.LAUNCHER instead of an activity. flutter_tools has no logic to handle activity-alias.

And this is the only way to use multiple app icons in Android.

I am working on a PR to fix this.

Upvotes: 1

Joshua Emmanuel
Joshua Emmanuel

Reputation: 431

This worked for me.

Check if namespace "com.webjow.hidden_gallery" is in your app/build.gradle

Here essentially

android {
   namespace "com.webjow.hidden_gallery"
   compileSdkVersion flutter.compileSdkVersion
   ndkVersion flutter.ndkVersion

Upvotes: 4

Abdul Ahad
Abdul Ahad

Reputation: 540

It seems that you have added multiple aliases that are targeting your Main Activity tag.

  1. It can simply be resolved by removing both of the aliases.

  2. Add the intent filter tag in the main activity tag and add a flag of exported true. This will solve the issue.

    <activity
            android:name=".MainActivity"
            android:theme="@style/LaunchTheme">
       <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" /> 
       </intent-filter>
    </activity>
    

Upvotes: 3

Laxmi kant
Laxmi kant

Reputation: 578

Duplicate <activity-alias> Elements: you have defined two <activity-alias> elements. This is typically not required. You should only have one <activity-alias> to define the launcher activity.

Remove either the "OneLauncherAlias" or "TwoLauncherAlias" <activity-alias> based on your requirements. The launcher alias should define the entry point of your app.

after that it looks like

           <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.webjow.hidden_gallery"
            xmlns:tools="http://schemas.android.com/tools">
            
            <!-- Your permissions, application, and meta-data here -->

            <application
                android:name="androidx.multidex.MultiDexApplication"
                android:allowBackup="false"
                android:fullBackupContent="false"
                android:icon="@mipmap/ic_launcher"
                android:label="@string/app_name"
                android:manageSpaceActivity=".MainActivity"
                android:requestLegacyExternalStorage="true"
                android:usesCleartextTraffic="true"
                tools:replace="android:label"
                tools:targetApi="34">
            
                <!-- Your activities and other components here -->

                <meta-data
                    android:name="flutterEmbedding"
                    android:value="2" />
            </application>
        </manifest>


      

Upvotes: 1

Narendra Bhatt
Narendra Bhatt

Reputation: 654

Try this.

  1. Remove intent-filter from both activity-alias and add that intent-filter inside the activity.

  2. set android:exported="true" in the activity as well.

    <activity
        android:name=".MainActivity"
        android:theme="@style/LaunchTheme" 
        android:exported="true"
        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    
    <activity-alias
        android:name="OneLauncherAlias"
        android:enabled="true"
        android:exported="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:targetActivity=".MainActivity"
        android:theme="@style/LaunchTheme" />
    
    <activity-alias
        android:name="TwoLauncherAlias"
        android:enabled="false"
        android:exported="true"
        android:icon="@mipmap/calculator"
        android:label="@string/app_name_fake"
        android:targetActivity=".MainActivity"
        android:theme="@style/LaunchTheme" />
    

Upvotes: 1

Related Questions