androidandroid-tvleanback

Missing MainActivity Error when running on Android TV Emulator


I created a sample Android TV app for testing purposes. I followed the documentation at

https://developer.android.com/training/tv/start/start

This is how my manifest file looks like:


<?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" />

    <uses-feature
        android:name="android.hardware.touchscreen"
        android:required="false" />
    <uses-feature
        android:name="android.software.leanback"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.CourseViewer">
        <activity
            android:name=".MainActivity"
            android:banner="@drawable/app_icon_your_company"
            android:exported="true"
            android:icon="@drawable/app_icon_your_company"
            android:label="@string/title_activity_main"
            android:logo="@drawable/app_icon_your_company"
            android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".DetailsActivity"
            android:exported="false" />
        <activity
            android:name=".PlaybackActivity"
            android:exported="false" />
        <activity
            android:name=".BrowseErrorActivity"
            android:exported="false" />
    </application>

</manifest> 

This is what I get when I run the app on an android tv emulator. Can someone please let me know what is missing in the manifest file? I do have the MainActivity and the manifest looks fine to me.

02/20 11:38:56: Launching 'app' on Android TV (4K) API 33.
Install successfully finished in 824 ms.
$ adb shell am start -n "edu.app.courseviewer/edu.app.courseviewer.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Error while executing: am start -n "edu.app.courseviewer/edu.app.courseviewer.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=edu.app.courseviewer/.MainActivity }
Error type 3
Error: Activity class {edu.app.courseviewer/edu.app.courseviewer.MainActivity} does not exist.

Error while Launching activity
Failed to launch an application on all devices

I have tried restarting android studio, invalidating caches and restart, synced gradle files. I was hoping the app would start on Android TV emulator.


Solution

  • It seems that Android Studio is using category android.intent.category.LAUNCHER for starting your MainActivity, so you can fix your problem by adding <category android:name="android.intent.category.LAUNCHER" /> in yout manifest for your MainActivity.