Android ClassNotFoundException for MainActivity despite correct manifest and class path

38 Views Asked by At

I'm encountering an issue with my Android application where I'm getting a ClassNotFoundException for the MainActivity despite having a correct manifest configuration and the class being in the correct package.

Manifest file (AndroidManifest.xml):

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

    <!-- Permissions and other configurations -->

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

        <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>

    </application>

</manifest>

Gradle file (build.gradle):

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 34
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.assingment2b"
        minSdkVersion 21
        targetSdkVersion 34
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    namespace 'com.example.namespace'
}

dependencies {
    // Other dependencies
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'androidx.annotation:annotation:1.7.0'
    implementation 'androidx.recyclerview:recyclerview:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation 'com.google.firebase:firebase-common:20.4.2'
    implementation 'com.google.firebase:firebase-storage:20.3.0'
}

Despite ensuring that the MainActivity class is present in the correct package (com.example.namespace), and the manifest is properly configured, the app still throws a ClassNotFoundException during runtime.

I have checked the following:

Verified the package name and class path in the manifest. Ensured the correct configuration of the Gradle file. Confirmed the presence of the MainActivity class in the correct package. Are there any other potential reasons for this issue? Could it be related to the build configuration, ProGuard, or any other factors that I might be overlooking?

Any insights or guidance on resolving this issue would be greatly appreciated.

0

There are 0 best solutions below