react-native-vector-icons: [solved] Duplicate resources android build error with v9.1.0 - [fonts were in source tree *and* using module's build.gradle font copy]

Environment

react-native 0.67.2, gradle 7.4, android gradle plugin 7.1.1, react-native-vector-icons 9.1.0 (hot off the presses!)

Description


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDevDebugAssets'.
> [fonts/Fontisto.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/src/main/assets/fonts/Fontisto.ttf    [fonts/Fontisto.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/build/intermediates/ReactNativeVectorIcons/fonts/Fontisto.ttf: Error: Duplicate resources
  [fonts/Octicons.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/src/main/assets/fonts/Octicons.ttf    [fonts/Octicons.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/build/intermediates/ReactNativeVectorIcons/fonts/Octicons.ttf: Error: Duplicate resources
  [fonts/Feather.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/src/main/assets/fonts/Feather.ttf      [fonts/Feather.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/build/intermediates/ReactNativeVectorIcons/fonts/Feather.ttf: Error: Duplicate resources
  [fonts/Entypo.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/src/main/assets/fonts/Entypo.ttf        [fonts/Entypo.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/build/intermediates/ReactNativeVectorIcons/fonts/Entypo.ttf: Error: Duplicate resources
  [fonts/FontAwesome5_Brands.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/src/main/assets/fonts/FontAwesome5_Brands.ttf      [fonts/FontAwesome5_Brands.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/build/intermediates/ReactNativeVectorIcons/fonts/FontAwesome5_Brands.ttf: Error: Duplicate resources
  [fonts/MaterialCommunityIcons.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/src/main/assets/fonts/MaterialCommunityIcons.ttf        [fonts/MaterialCommunityIcons.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/build/intermediates/ReactNativeVectorIcons/fonts/MaterialCommunityIcons.ttf: Error: Duplicate resources
  [fonts/AntDesign.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/src/main/assets/fonts/AntDesign.ttf  [fonts/AntDesign.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/build/intermediates/ReactNativeVectorIcons/fonts/AntDesign.ttf: Error: Duplicate resources
  [fonts/Foundation.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/src/main/assets/fonts/Foundation.ttf        [fonts/Foundation.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/build/intermediates/ReactNativeVectorIcons/fonts/Foundation.ttf: Error: Duplicate resources
  [fonts/Ionicons.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/src/main/assets/fonts/Ionicons.ttf    [fonts/Ionicons.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/build/intermediates/ReactNativeVectorIcons/fonts/Ionicons.ttf: Error: Duplicate resources
  [fonts/FontAwesome5_Solid.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/src/main/assets/fonts/FontAwesome5_Solid.ttf        [fonts/FontAwesome5_Solid.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/build/intermediates/ReactNativeVectorIcons/fonts/FontAwesome5_Solid.ttf: Error: Duplicate resources
  [fonts/FontAwesome5_Regular.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/src/main/assets/fonts/FontAwesome5_Regular.ttf    [fonts/FontAwesome5_Regular.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/build/intermediates/ReactNativeVectorIcons/fonts/FontAwesome5_Regular.ttf: Error: Duplicate resources
  [fonts/FontAwesome.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/src/main/assets/fonts/FontAwesome.ttf      [fonts/FontAwesome.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/build/intermediates/ReactNativeVectorIcons/fonts/FontAwesome.ttf: Error: Duplicate resources
  [fonts/Zocial.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/src/main/assets/fonts/Zocial.ttf        [fonts/Zocial.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/build/intermediates/ReactNativeVectorIcons/fonts/Zocial.ttf: Error: Duplicate resources
  [fonts/EvilIcons.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/src/main/assets/fonts/EvilIcons.ttf  [fonts/EvilIcons.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/build/intermediates/ReactNativeVectorIcons/fonts/EvilIcons.ttf: Error: Duplicate resources
  [fonts/SimpleLineIcons.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/src/main/assets/fonts/SimpleLineIcons.ttf      [fonts/SimpleLineIcons.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/build/intermediates/ReactNativeVectorIcons/fonts/SimpleLineIcons.ttf: Error: Duplicate resources
  [fonts/MaterialIcons.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/src/main/assets/fonts/MaterialIcons.ttf  [fonts/MaterialIcons.ttf] /Users/mike/work/EquityResidences/equityresidences/packages/public-app/android/app/build/intermediates/ReactNativeVectorIcons/fonts/MaterialIcons.ttf: Error: Duplicate resources

Reproducible Demo

I’m still investigating this but thought to log it quickly since rolling back to 9.0.0 does not cause a build faliure, while 9.1.0 does. I can confirm with 9.0.0 I actually do have vector icons showing up as well so by all appearances 9.0.0 is working

Likely cause #1401 but I haven’t looked into it thoroughly yet

I tried rm -fr android/build android/app/build and rebuilt, just to see if that had an effect. No effect. Only the revert to v9 is successful at the moment

I am not including specific fonts, the tail of my android/app/build.gradle is:


apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 8
  • Comments: 41 (16 by maintainers)

Commits related to this issue

Most upvoted comments

Yeah, I’m pretty confident this is the case. You should pick one approach, either manually copying them to your fonts folder, or copying on build with gradle. To fix this error simply remove the duplicates in packages/public-app/android/app/src/main/assets/fonts, they are most likely out of date anyways.

Same problem in v9.1.0, removing them will work again:

  • android/app/src/main/fonts/AntDesign.ttf
  • android/app/src/main/fonts/MaterialCommunityIcons.ttf

Update

Check your android/app/src/main/fonts directory, if the following files exist, just delete them:

  • AntDesign.ttf
  • Entypo.ttf
  • EvilIcons.ttf
  • Feather.ttf
  • FontAwesome.ttf
  • FontAwesome5_Brands.ttf
  • FontAwesome5_Regular.ttf
  • FontAwesome5_Solid.ttf
  • Fontisto.ttf
  • Foundation.ttf
  • Ionicons.ttf
  • MaterialCommunityIcons.ttf
  • MaterialIcons.ttf
  • Octicons.ttf
  • SimpleLineIcons.ttf
  • Zocial.ttf

I’ve had the same issue and react-native unlink react-native-vector-icons worked for me (I’m a noob and this was the answer I was looking for).

@mikehardy I’m happy to include my other (non react-native-vector-icons) fonts in whatever is the recommended way. I have’t found a tutorial that doesn’t use link however. What is the right way to include a regular font you downloaded nowadays? I currently put it in assets/fonts and run link.

USE npx react-native-asset

Going to close this here as double-inclusion is an integrator problem, not a module problem, but perhaps this issue existing historically will help others if they have incorrectly double-included vector icons like I/we have in those templates, I’m tracking it now in those two template repos

Thanks for the help, and for react-native-vector-icons in general @oblador - much appreciated!

I think the answer here is: never ever ever ever ever ever use react-native link

It is deprecated forever, and is specifically removed in the CLI now. No one should ever use react-native link.

Don’t use react-native link

I’m repeating myself in humor, but seriously, don’t use it 😃

https://github.com/react-native-community/cli/pull/1537

Hi. I have the same problem:

 Duplicate resources
  [fonts/MaterialCommunityIcons.ttf] /home/gitlab-runner/builds/L1s-mTeS/0//android/app/src/main/assets/fonts/MaterialCommunityIcons.ttf	[fonts/MaterialCommunityIcons.ttf] /home/gitlab-runner/builds/L1s-mTeS/0/android/app/build/intermediates/ReactNativeVectorIcons/fonts/MaterialCommunityIcons.ttf: Error: Duplicate resources

When I want to build my project on gitlab runner I have this problem. When I use this command : react-native unlink react-native-vector-icons this lead to clean all fonts in android/app/src/main/assets/fonts and the problem is disappeared and build correctly. but in , for example, Samsung A51 keyboard will not work correctly! (disappear when user wants to type) So I can not remove fonts from android/app/src/main/assets/fonts . Now my question is : Why fonts are created automatically in path android/app/build/intermediates/ReactNativeVectorIcons/fonts ? and How can I solve my problem? I really stopped on this bug. Thanks in advanced

Once again @mikehardy you saved me hours of my life. ❤️

I think you may have sniped it! I normally (that is: in all my other projects) just use the gradle file reference as I included at the bottom of the report, but in this particular one I have them in assets as well:

mike@bistromath:~/work/EquityResidences/equityresidences/packages/public-app/android (main) % find . | grep ttf
./app/src/main/assets/fonts/Octicons.ttf
./app/src/main/assets/fonts/Foundation.ttf
./app/src/main/assets/fonts/SimpleLineIcons.ttf
./app/src/main/assets/fonts/Feather.ttf
./app/src/main/assets/fonts/MaterialCommunityIcons.ttf
./app/src/main/assets/fonts/FontAwesome5_Regular.ttf
./app/src/main/assets/fonts/Entypo.ttf
./app/src/main/assets/fonts/MaterialIcons.ttf
./app/src/main/assets/fonts/FontAwesome.ttf
./app/src/main/assets/fonts/EvilIcons.ttf
./app/src/main/assets/fonts/Zocial.ttf
./app/src/main/assets/fonts/AntDesign.ttf
./app/src/main/assets/fonts/Ionicons.ttf
./app/src/main/assets/fonts/Fontisto.ttf
./app/src/main/assets/fonts/FontAwesome5_Brands.ttf
./app/src/main/assets/fonts/FontAwesome5_Solid.ttf

This project is based off a chain of templates that I attempt to keep maintained as starters for others, and they sadly suffer the same pathology: https://github.com/invertase/react-native-firebase-authentication-example/tree/main/template/android/app/src/main/assets/fonts https://github.com/plaut-ro/luna/tree/master/template/android/app/src/main/assets/fonts

So we have some fixing to do I suppose. It doesn’t appear that this is react-native-vector-icons fault, though it is kind of a build break - if I’m understanding it correctly we were just getting lucky before that the build.gradle machinery from here was effectively overwriting the fonts we were already including as source and we were just lucky before because they were in the same spot.

Not sure if I’m missing something here, but I did not have any icons duplicated in my android/ or src/ files.

I am running the following react-native-config.js to only copy over the icons I actually need:

const VECTOR_ICONS_FONTS_PATH = './node_modules/react-native-vector-icons/Fonts'
const VECTOR_FONTS = ['Ionicons.ttf']

module.exports = {
  project: {
    ios: {},
    android: {},
  },
  dependencies: {
    // Disable auto linking for `react-native-vector-icons` and link
    // the required fonts manually to avoid duplicate resources issue in iOS.
    'react-native-vector-icons': {
      platforms: {
        ios: null,
        android: null,
      },
      assets: VECTOR_FONTS.map((font) => VECTOR_ICONS_FONTS_PATH + '/' + font),
    },
  },
  assets: ['./src/assets/fonts/'], // stays the same
}

And I have this in my build.gradle:

project.ext.vectoricons = [
    iconFontNames: [
		'Ionicons.ttf',
    ]
]

…and I get the duplicate resources errors when building. When removing my custom react-native-config, all icons get copied over and I still get the build error… 🤔

Am I doing something wrong? @oblador

nodemudules> react-native-vector-icons/font.gradle

Solved by changing the path :

from : into “$buildDir/intermediates/ReactNativeVectorIcons/fonts”

to: into “$buildDir/intermediates/assets/fonts”

I’m only using the recommended gradle method and my android/app/src/main/assets/fonts is empty but I’m still getting the error:

[raw/node_modules_reactnativevectoricons_glyphmaps_fontawesome5free_meta] /Users/newuser/Desktop/Prototype/frontend/android/app/src/main/res/raw/node_modules_reactnativevectoricons_glyphmaps_fontawesome5free_meta.json     
[raw/node_modules_reactnativevectoricons_glyphmaps_fontawesome5free_meta] /Users/newuser/Desktop/Prototype/frontend/android/app/build/generated/res/react/internal/release/raw/node_modules_reactnativevectoricons_glyphmaps_fontawesome5free_meta.json: Error: Duplicate resources

Any recommendations?

Yeah, and you can probably earn all sorts of Internet Points (worth more than bitcoin right now!) if you post some updated answers on the relevant stack overflow - I just know this is going to bite a ton of people

@samaneh-kamalian try this solution

Thanks for your reply. I did it this way and this problem is solved with this solution. But the added problem is that the Samsung a51 keyboard does not work properly and the keyboard closes when the user wants to type something! The only thing that has changed is the removal of ttfs

My problem solved with this : https://github.com/facebook/react-native/issues/33164

Hi. I have the same problem:

 Duplicate resources
  [fonts/MaterialCommunityIcons.ttf] /home/gitlab-runner/builds/L1s-mTeS/0//android/app/src/main/assets/fonts/MaterialCommunityIcons.ttf	[fonts/MaterialCommunityIcons.ttf] /home/gitlab-runner/builds/L1s-mTeS/0/android/app/build/intermediates/ReactNativeVectorIcons/fonts/MaterialCommunityIcons.ttf: Error: Duplicate resources

When I want to build my project on gitlab runner I have this problem. When I use this command : react-native unlink react-native-vector-icons this lead to clean all fonts in android/app/src/main/assets/fonts and the problem is disappeared and build correctly. but in , for example, Samsung A51 keyboard will not work correctly! (disappear when user wants to type) So I can not remove fonts from android/app/src/main/assets/fonts . Now my question is : Why fonts are created automatically in path android/app/build/intermediates/ReactNativeVectorIcons/fonts ? and How can I solve my problem? I really stopped on this bug. Thanks in advanced

Anybody can not answer my question ? 😦 In my system I do not have any problem, but I do not know why git lab runner create folder ReactNativeVectorIcons in path android/app/build/intermediates and copy fonts there !!!

react-native unlink react-native-vector-icons

Thank you so much

@oblador yes, I tried only the Gradle approach (no custom RN config), as well as the custom RN config (no Gradle) approach, both with a complete nuke & clean install, but still all fonts were copied over. I’ll provide a repro once I got some time 🙏

hm, that still copies over all icons? I’ll try to build a clean reproduceable sample.