Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Expo Config Plugin for Notification Controls adds duplicate <service> tag to AndroidManifest on every prebuild #4167

Closed
aminmeshk opened this issue Sep 12, 2024 · 5 comments
Labels
Accepted Issue is confirmed and accepted by maintainers team bug Platform: Android Repro Provided

Comments

@aminmeshk
Copy link
Contributor

Version

6.5.0

What platforms are you having the problem on?

Android

System Version

macOs 14.1

On what device are you experiencing the issue?

Simulator

Architecture

Old architecture

What happened?

When I set "enableNotificationControls": true in my app.json and run npx expo prebuild, it adds the code below to the AndroidManifest.xml file:

    <service android:name="com.brentvatne.exoplayer.VideoPlaybackService" android:exported="false" android:foregroundServiceType="mediaPlayback">
      <intent-filter>
        <action android:name="androidx.media3.session.MediaSessionService"/>
      </intent-filter>
    </service>

which is the expected behavior. The issue is that if I run npx expo prebuild again, it adds the full tag to the manifest once more! It adds it every time I run prebuild without cleaning.

Reproduction Link

No response

Reproduction

Step to reproduce this bug are:

  1. Add react-native-video package to a Expo project that uses Prebuild
  2. In app.json file, add "react-native-video" to the plugins array like with "enableNotificationControls": true parameter.
"plugins": [
      [
        "react-native-video",
        {
          "enableNotificationControls": true
        }
      ]
]
  1. Run npx expo prebuild
  2. Check AndroidManifest.xml. The code below should be added to the manifest:
    <service android:name="com.brentvatne.exoplayer.VideoPlaybackService" android:exported="false" android:foregroundServiceType="mediaPlayback">
      <intent-filter>
        <action android:name="androidx.media3.session.MediaSessionService"/>
      </intent-filter>
    </service>
  1. Run npx expo prebuild again.
  2. Check AndroidManifest.xml. You can see there are now two of the exact same tag:
    <service android:name="com.brentvatne.exoplayer.VideoPlaybackService" android:exported="false" android:foregroundServiceType="mediaPlayback">
      <intent-filter>
        <action android:name="androidx.media3.session.MediaSessionService"/>
      </intent-filter>
    </service>
    <service android:name="com.brentvatne.exoplayer.VideoPlaybackService" android:exported="false" android:foregroundServiceType="mediaPlayback">
      <intent-filter>
        <action android:name="androidx.media3.session.MediaSessionService"/>
      </intent-filter>
    </service>
  1. If you run prebuild again the tag gets added again.
@aminmeshk aminmeshk added the bug label Sep 12, 2024
Copy link

Thank you for your bug report. We will review it and get back to you if we need more information.

@freeboub
Copy link
Collaborator

@KrzysztofMoch maybe you have some good clue on this issue ?!

@aminmeshk
Copy link
Contributor Author

I suppose the issue comes from this block of code in src/expo-plugins/withNotificationControls.ts file:

    manifest.application.map((application) => {
      if (!application.service) {
        application.service = [];
      }

      application.service.push({
        $: {
          'android:name': 'com.brentvatne.exoplayer.VideoPlaybackService',
          'android:exported': 'false',
          // @ts-expect-error: 'android:foregroundServiceType' does not exist in type 'ManifestServiceAttributes'.
          'android:foregroundServiceType': 'mediaPlayback',
        },
        'intent-filter': [
          {
            action: [
              {
                $: {
                  'android:name': 'androidx.media3.session.MediaSessionService',
                },
              },
            ],
          },
        ],
      });

      return application;
    });

As you can see in the code above, it pushes the service to the application.service array without checking first. I can make a PR to fix that

@freeboub
Copy link
Collaborator

@aminmeshk yes you are right, you're pointing the good code. I don't think the fix is difficult to implement, if you can open a PR, I would be happy to review it !

@freeboub
Copy link
Collaborator

Linked PR has been merged, let's close the ticket, thank you @aminmeshk !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Issue is confirmed and accepted by maintainers team bug Platform: Android Repro Provided
Projects
None yet
Development

No branches or pull requests

2 participants