Apps from developer.android.com code paths fail to run with "Activity class not found" error


EDIT - I got this to work by deleting my existing Pixel 8 Pro emulator device and creating a new one. I have no idea why it wasn't working, but this fixed it. Thanks to tyg, Morrison Chang, and Sasi Kumar for taking a look!

I have worked on several of the code paths from developer.android.com, but it's been a month or so since I've worked on them and there have been several Android Studio updates. Now I am seeing "Activity class not found" in this and my old projects that used to work (no new code was pulled).

Here are the steps to reproduce:

Clone a fresh copy of "dessert clicker" from git.

git clone https://github.com/google-developer-training/basic-android-kotlin-compose-training-dessert-clicker

cd .\basic-android-kotlin-compose-training-dessert-clicker

git checkout starter

Open the project in Android Studio, wait for it to load, and click build. That works, but if I try to run it, it fails with

Error running 'app' Activity class {com.example.dessertclicker/com.example.dessertclicker.MainActivity} does not exist

From what I can see from searching, this is due to a bad manifest file, but as far as I can tell the manifest file is fine.

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

    <application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.DessertClicker"
        tools:targetApi="33">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:theme="@style/Theme.DessertClicker">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

There is a MainActivity file in the proper location.

screenshot showing project structure

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        enableEdgeToEdge()
        super.onCreate(savedInstanceState)
        setContent {
            DessertClickerTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier
                        .fillMaxSize()
                        .statusBarsPadding(),
                ) {
                    DessertClickerApp(desserts = Datasource.dessertList)
                }
            }
        }
    }
}

I am running Android Studio Panda 1 | 2025.3.1

Can anyone help? Thanks.

2
Feb 12 at 9:56 PM
User Avatarsyndicatedragon
#android

Accepted Answer

Remove

tools:targetApi="33"

or make sure you device APi level 33 and above

Note

The tools:targetApi="33" attribute is a lint instruction for Android Studio and the build tools, indicating that you are aware the annotated element or its children should only be used on API level 33 or higher.

User AvatarSasi Kumar
Feb 13 at 4:58 AM
0