React-native-firebase: Can not override notification_color in AndroidManifest.xml

Created on 27 Apr 2020  路  10Comments  路  Source: invertase/react-native-firebase

If i try to set notification icon color (according to official firebase docs https://firebase.google.com/docs/cloud-messaging/android/receive):

<meta-data
    android:name="com.google.firebase.messaging.default_notification_color"
    android:resource="@color/colorAccent" />

When building Android app I get this error:

* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute meta-data#com.google.firebase.messaging.default_notification_color@resource value=(@color/main) from AndroidManifest.xml:45:11-41
        is also present at [:react-native-firebase_messaging] AndroidManifest.xml:42:13-44 value=(@color/white).
        Suggestion: add 'tools:replace="android:resource"' to <meta-data> element at AndroidManifest.xml:43:9-45:44 to override

react-native-firebase version: 6.7.1

This option used to work with react-native-firebase v5

Most helpful comment

All 10 comments

Thanks

@Ehesp Can I use a custom color added in colors.xml (eg. @color/primary) ?

Yeah you just need to make sure the resource is accessible. Try adding it via studio.

I tried but I got this error:
AndroidManifest.xml:40: AAPT: error: resource color/primary (aka io.invertase.firebase.messaging:color/primary) not found.

My RNFirebase deps:
{ "@react-native-firebase/analytics": "^7.1.7", "@react-native-firebase/app": "^8.0.0", "@react-native-firebase/crashlytics": "^8.0.1", "@react-native-firebase/dynamic-links": "^7.2.2", "@react-native-firebase/in-app-messaging": "^7.1.7", "@react-native-firebase/messaging": "^7.2.1", "@react-native-firebase/perf": "^7.1.7", }

My colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <color name="primary">#8CC83C</color>
  <color name="dark">#000000</color>
  <color name="light">#FFFFFF</color>
  <color name="primary_dark">#000000</color>
  <color name="bootsplash_background">#8CC83C</color>
</resources>

@b3coded I'm experiencing the same. I know I was able at some point to build successfully by setting my color in firebase.json, but it is failing for me now with the same error as yours.


Deps

  "dependencies": {
    "@react-native-firebase/app": "^7.3.0",
    "@react-native-firebase/messaging": "^7.1.7"
  }

I am currently able to move past this by overriding directly in my AndroidManifest.xml as follows:

<meta-data
    android:name="com.google.firebase.messaging.default_notification_color"
    android:resource="@color/primary"
    tools:replace="android:resource"
/>

I can't use a custom colour using the firebase.json file approach either and I don't understand how it may work.

The value from firebase.json will replace a placeholder in node_modules/@react-native-firebase/messaging/android/src/main/AndroidManifest.xml as part of the build of the react-native-firebase_messaging library. But react-native-firebase_messaging library (a dependency of the application) has not idea about a resource defined in the application (and it should not). It expectedly fails during :react-native-firebase_messaging:verifyReleaseResources task (only run for Release builds) as its AndroidManifest.xml references a colour, which is not defined in resources visible to react-native-firebase_messaging package. The approach from https://github.com/invertase/react-native-firebase/issues/3559#issuecomment-654380585 looks like a correct solution to the problem.

So as I see it consumers can only use colours defined in node_modules/@react-native-firebase/messaging/android/src/main/res/values/colors.xml in the firebase.json file.

So as I see it consumers can only use colours defined in node_modules/@react-native-firebase/messaging/android/src/main/res/values/colors.xml in the firebase.json file.

@devoto13 that is what the statement on the reference page https://rnfirebase.io/messaging/usage#notification-color is supposed to mean:

The library provides a set of default HTML colors (in lowercase) for ease, for example

So if it's not in this list https://github.com/invertase/react-native-firebase/blob/master/packages/messaging/android/src/main/res/values/colors.xml you can't access it without using patch-package to patch in there

If the documentation could be made clearer (and documentation can almost always be made more clear!) please hit the edit link on the top right of that page and propose a PR :-)

@mikehardy I see. It it was not at all clear from the current text that it is not possible to use custom colour this way... Especially after reading https://github.com/invertase/react-native-firebase/issues/3559#issuecomment-652643494, which seems to claim otherwise. Let me try to add an example of how to use a custom color to the documentation page.

@b3coded I'm experiencing the same. I know I was able at some point to build successfully by setting my color in firebase.json, but it is failing for me now with the same error as yours.

Deps
I am currently able to move past this by overriding directly in my AndroidManifest.xml as follows:

<meta-data
  android:name="com.google.firebase.messaging.default_notification_color"
  android:resource="@color/primary"
  tools:replace="android:resource"
/>

I'm using this approach but still, the notification icon is colored white.

Was this page helpful?
0 / 5 - 0 ratings