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

Messaging - Expo EAS build failed (Android) #8165

Open
1 of 5 tasks
WhidRubeld opened this issue Nov 27, 2024 · 12 comments
Open
1 of 5 tasks

Messaging - Expo EAS build failed (Android) #8165

WhidRubeld opened this issue Nov 27, 2024 · 12 comments
Labels
help: android Needs help implementing a PR relating to Android code. impact: build-error Behaviour causing build failure Needs Attention platform: expo plugin: messaging FCM only - ( messaging() ) - do not use for Notifications type: bug New bug report

Comments

@WhidRubeld
Copy link

WhidRubeld commented Nov 27, 2024

Issue

Expo-managed Android project build error using EAS.
The error is due to a conflict with the expo-notifications library when setting a manifest parameter.

> Task :app:processDebugMainManifest FAILED
See https://developer.android.com/r/studio-ui/build/manifest-merger for more information about the manifest merger.
/home/expo/workingdir/build/android/app/src/debug/AndroidManifest.xml:17:88-137 Error:
	Attribute meta-data#com.google.firebase.messaging.default_notification_color@resource value=(@color/notification_icon_color) from AndroidManifest.xml:17:88-137
	is also present at [:react-native-firebase_messaging] AndroidManifest.xml:40:13-44 value=(@color/white).
	Suggestion: add 'tools:replace="android:resource"' to <meta-data> element at AndroidManifest.xml to override.
> Task :react-native-firebase_crashlytics:compileDebugJavaWithJavac
Note: /home/expo/workingdir/build/node_modules/@react-native-firebase/crashlytics/android/src/main/java/io/invertase/firebase/crashlytics/ReactNativeFirebaseCrashlyticsModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
> Task :react-native-firebase_analytics:compileDebugJavaWithJavac
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
>
Manifest merger failed : Attribute meta-data#com.google.firebase.messaging.default_notification_color@resource value=(@color/notification_icon_color) from AndroidManifest.xml:17:88-137
  	is also present at [:react-native-firebase_messaging] AndroidManifest.xml:40:13-44 value=(@color/white).
  	Suggestion: add 'tools:replace="android:resource"' to <meta-data> element at AndroidManifest.xml to override.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org/.

Old problem #7841


Project Files

Javascript

Click To Expand

package.json:

{
   ...
  "dependencies": {
    ...
    "@react-native-firebase/analytics": "^21.0.0",
    "@react-native-firebase/app": "^21.0.0",
    "@react-native-firebase/crashlytics": "^21.0.0",
    "@react-native-firebase/in-app-messaging": "^21.0.0",
    "@react-native-firebase/installations": "^21.0.0",
    "@react-native-firebase/messaging": "^21.0.0",
    ...
    "expo": "~52.0.7",
    ...
    "expo-notifications": "~0.29.8",
    ...
    "react-native": "0.76.3",
    ...
  },
  ...
}

firebase.json for react-native-firebase v6:

{
  "react-native": {}
}

Environment

Click To Expand

react-native info output:

System:
  OS: macOS 15.0.1
  CPU: (11) arm64 Apple M3 Pro
  Memory: 87.75 MB / 18.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.9.0
    path: ~/.nvm/versions/node/v20.9.0/bin/node
  Yarn:
    version: 1.22.22
    path: ~/.nvm/versions/node/v20.9.0/bin/yarn
  npm:
    version: 10.1.0
    path: ~/.nvm/versions/node/v20.9.0/bin/npm
  Watchman:
    version: 2022.07.04.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.11.3
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.1
      - iOS 18.1
      - macOS 15.1
      - tvOS 18.1
      - visionOS 2.1
      - watchOS 11.1
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.2 AI-242.23339.11.2421.12483815
  Xcode:
    version: 16.1/16B40
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.17
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.1.2
    wanted: ^15.1.2
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.3
    wanted: 0.76.3
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found
  • Platform that you're experiencing the issue on:
    • iOS
    • Android
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • react-native-firebase version you're using that has this issue:
    • @react-native-firebase/app": "^21.0.0"
  • Firebase module(s) you're using that has the issue:
    • "@react-native-firebase/messaging": "^21.0.0"
  • Are you using TypeScript?
    • "typescript": "~5.3.3"


@mikehardy
Copy link
Collaborator

You'll need to either alter the config plugin here for messaging or there for expo-notifications to do as it says: add the tools XML namespace to the AndroidManifest file (if not there already) and mark that property as tools:replace

The Expo plugins here are community maintained by interested Expo users, none of the maintainers use Expo so we rely on Expo users to keep them working. Bearing that in mind we'll need a PR from someone that uses it so they test it well and know it works. We can merge and release easily if someone proposes a PR

@mikehardy mikehardy added plugin: messaging FCM only - ( messaging() ) - do not use for Notifications impact: build-error Behaviour causing build failure platform: expo help: android Needs help implementing a PR relating to Android code. labels Nov 27, 2024
@WhidRubeld
Copy link
Author

I was able to solve the problem in the following way

const { withAndroidManifest } = require('@expo/config-plugins');

/**
 * Custom Expo plugin to resolve manifest conflicts with Firebase Messaging.
 * Specifically, this plugin ensures that the meta-data for 
 * `com.google.firebase.messaging.default_notification_color` is correctly 
 * configured with `tools:replace="android:resource"` to prevent build errors.
 */
module.exports = function withNotificationToolsReplace(config) {
  return withAndroidManifest(config, (config) => {
    const androidManifest = config.modResults;

    // Ensure the namespace 'tools' is added to the manifest to support 'tools:replace' attributes
    if (!androidManifest.manifest.$['xmlns:tools']) {
      androidManifest.manifest.$['xmlns:tools'] = 'http://schemas.android.com/tools';
    }

    const application = androidManifest.manifest.application[0];
    application['meta-data'] ??= []; // Ensure 'meta-data' exists in the application node

    // Check if the meta-data for `default_notification_color` already exists
    const metaData = application['meta-data'].find(
      (item) =>
        item['$']['android:name'] ===
        'com.google.firebase.messaging.default_notification_color'
    );

    if (metaData) {
      // If it exists, add or update the 'tools:replace' attribute to resolve conflicts
      metaData['$']['tools:replace'] = 'android:resource';
    } else {
      // If it does not exist, create the meta-data entry with the required attributes
      application['meta-data'].push({
        $: {
          'android:name': 'com.google.firebase.messaging.default_notification_color',
          'android:resource': '@color/notification_icon_color',
          'tools:replace': 'android:resource',
        },
      });
    }

    // Return the updated config
    return config;
  });
};

Similar logic is defined in the library plugin. Apparently, it does not work correctly.

@mikehardy
Copy link
Collaborator

@WhidRubeld - ah! I just looked at the plugin. In fact it does add the tools namespace and the tools replace, or at least it intends to

Similar logic is defined in the library plugin. Apparently, it does not work correctly.

I cannot understand why - with an existing plugin that has this specific purpose and is hosted here for community use such that you may eventually benefit from others' work as well, you did not propose a fix to the plugin, but made a new one? If you proposed a PR to the plugin, I'd merge it without question...

@WhidRubeld
Copy link
Author

@mikehardy Yes, I will do PR this week

@mikehardy
Copy link
Collaborator

Fantastic! Hopefully it's not too awful, I mean...it existed! It used to work? AndroidManifest hasn't changed that much, it's XML after all... strange it's not working now

@WhidRubeld
Copy link
Author

Yep, the problem was previously solved as described in the old Issue. With the following dependencies combined:

"@react-native-firebase/messaging": "^20.5.0",
"expo-notifications": "0.28.3",

After updating to the latest versions - the problem has returned. It would be nice to identify the root of the problem...

@sylv1ah
Copy link

sylv1ah commented Dec 5, 2024

Hi I am also getting this error with my expo managed android builds, is there any update on this?

@mikehardy
Copy link
Collaborator

@sylv1ah no update, I imagine if someone (could be you!) examines the expo config plugin here to see why it's not doing it's job and fixes it by submitting a PR, we'll see comments here indicating the same or the issue will close as the linked PR is merged+released

We need a motivated expo person to submit a PR though as expo plugins support is community maintained

Future folks looking for updates, please use the subscribe button and/or add a reaction to the issue, +1s or asking for updates vs posting a PR isn't progress, only posting a PR is progress. Thanks

@sylv1ah
Copy link

sylv1ah commented Dec 6, 2024

Managed to resolve this issue by updating all the react-native-firebase dependencies to:

    "@react-native-firebase/analytics": "^21.0",
    "@react-native-firebase/app": "^21.0",
    "@react-native-firebase/auth": "^21.0",
    "@react-native-firebase/database": "^21.0",
    "@react-native-firebase/messaging": "^21.0",
    "@react-native-firebase/storage": "^21.0",

@itajenglish
Copy link

+1

1 similar comment
@ktanoooo
Copy link

+1

@WhidRubeld
Copy link
Author

Managed to resolve this issue by updating all the react-native-firebase dependencies to:

    "@react-native-firebase/analytics": "^21.0",
    "@react-native-firebase/app": "^21.0",
    "@react-native-firebase/auth": "^21.0",
    "@react-native-firebase/database": "^21.0",
    "@react-native-firebase/messaging": "^21.0",
    "@react-native-firebase/storage": "^21.0",

The problem persists for versions 21.6.0 inclusive. I'll try to make MR in the coming days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help: android Needs help implementing a PR relating to Android code. impact: build-error Behaviour causing build failure Needs Attention platform: expo plugin: messaging FCM only - ( messaging() ) - do not use for Notifications type: bug New bug report
Projects
None yet
Development

No branches or pull requests

5 participants