0

I have single activity, Mainactivity.java. And I want to run it on both, phones and TVs. I have created 2 separate layout files for both devices.

enter image description here

And I have changed my Manifest file according to this answer.

AndroidManifest.xml  
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.currencyrates"
    android:theme="@style/Theme.AppCompat"
    tools:ignore="MissingLeanbackLauncher">

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.Leanback"
        android:banner="@drawable/lb_search_orb">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:exported="true">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:screenOrientation="landscape"
            android:label="@string/app_name"
            android:theme="@style/Theme.Leanback"
            android:exported="true"
            tools:ignore="DuplicateActivity">

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

        </activity>
    </application>

</manifest>  
  

But the app crashes with below errors:

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:processDebugMainManifest'. Manifest merger failed with multiple errors, see logs

  • Try: Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:processDebugMainManifest'.

casper
  • 259
  • 4
  • 18
  • 1
    As far as I know you have to have one class per activity. If you want to use the same class for two activities, you can create a new class, let to extend `MainActivity` and the use it for the second activity. This should work. – Robert Mar 05 '22 at 12:39
  • 1
    Have one activity with both `` elements. Or, as Robert suggests, have two separate activity classes, each with their own `` element. – CommonsWare Mar 05 '22 at 13:33

0 Answers0