flutterandroid-manifestjust-audio

flutter just_audio_background error: Execution failed for task ':app:processDebugMainManifest'


Am trying to set up just_audio_background but get a bunch of errors (as per screenshot), when I follow the amendments to the main/AndroidManifest.xml and not sure why as appears to follow the steps exactly as the plugin outlines.

The warnings I get are:

warnings

And the exception reason I get when I run the app is:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> com.android.manifmerger.ManifestMerger2$MergeFailureException: Error parsing /Users/mac/Documents/flutter_projects/zense_timer_project/zense_timer/android/app/src/main/AndroidManifest.xml

And here is the AndroidManifest.xml


<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    <application
        android:label="zense_timer"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name="com.ryanheise.audioservice.AudioServiceActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->

        <service android:name="com.ryanheise.audioservice.AudioService"
            android:foregroundServiceType="mediaPlayback"
            android:exported="true" tools:ignore="Instantiatable">
            <intent-filter>
                <action android:name="android.media.browse.MediaBrowserService" />
            </intent-filter>
        </service>

        <!-- ADD THIS "RECEIVER" element -->
        <receiver android:name="com.ryanheise.audioservice.MediaButtonReceiver"
            android:exported="true" tools:ignore="Instantiatable">
            <intent-filter>
                <action android:name="android.intent.action.MEDIA_BUTTON" />
            </intent-filter>
        </receiver>
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
        <!-- ADD THIS "SERVICE" element -->

    </application>
</manifest>

I have run flutter clean and restarted but still can't fix these errrors.

Note possibly related, my AndroidManifest does have these warnings before I make amendments for just_audio_background, but my app still compiles fine and from what I read might be related to a bug in the IDE.

Unresolved class '{applicationName}'
Unresolved class '{applicationName}'
Cannot resolve symbol '@style/NormalTheme'

Here is a screenshot of manifest (before add plugin changes)

And screenshot with the plugin changes


Solution

  • In your AndroidManifest file,

    Change this:

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

    To this:

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