The activity 'MainActivity' is not declared in AndroidManifest.xm

44 views Asked by At

I'm a complete beginner in programming, and I'm struggling with how to declare a variable in the language I'm learning. I've attempted various methods, but none seem to work, and I've even turned to ChatGPT for assistance, but unfortunately, I haven't found a solution yet. It's frustrating because I feel like I've exhausted all my options and tried everything possible

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"> <uses-permission android:name="android.permission.INTERNET" />
<application
    android:allowBackup="true"
    android:dataExtractionRules="@xml/data_extraction_rules"
    android:fullBackupContent="@xml/backup_rules"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.MadeByBlitzedzzcookieLogin"
    tools:targetApi="31">

    <activity
        android:name="MainActivity"
        android:exported="true"
        android:label="@string/app_name"
        android:theme="@style/Theme.MadeByBlitzedzzcookieLogin">


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

    </activity>

</application>
</manifest>
3

There are 3 answers

2
Manjeet deswal On

put a dot before MainActivity like this .MainActivity or if its in another folder write down whole path

<activity android:name=".test.MainActivity  "/>
1
Aniket Chauhan On

See below attached screen shot. There is small mistake in your code. Here is the proper way to declare MainActivity in your AndroidManifest file.

    <activity
        android:name=".MainActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
1
Awa93 On

Any Activity you created in App and not declared in the manifest can cause this Issue To declare the Activity in Manifest <activity> tag is used inside <application> tag In <activity> tag android:name attribute is used and value of name should include the package detail like com.example.MainActivity / .MainActivity

<activity
 android:name=".MainActivity">
</activity>

OR

<activity
 android:name=".xyz.MainActivity">
</activity>