Intl.numberformat in React native works fine when running in ios but not in android
Asked Answered
D

1

6

I am developing an app with React Native to run on IOS and Android. I use Intl.numberformat() to print currency, and it works smoothly when the app runs on IOS, but I get this error when running on Android: ReferenceError: Can't find variable: Intl.

How can I make it run in both plataforms?

Demobilize answered 10/9, 2020 at 21:20 Comment(1)
E
12

I had faced similar issue. The issue was with Javascript core which runs the react- native. There are two ways to overcome this.

1.Method 1 You'll have to integrate latest javascript core into your android build or upgrade react native to 0.59

You can find it here

  1. Method 2 Add or override the following code in your app/build.gradle

def jscFlavor = 'org.webkit:android-jsc-intl:+'

Clean build and react-native run android

Eddyede answered 11/9, 2020 at 14:47 Comment(7)
Only method 2 worked for me. Using RN 0.66Hermitage
How could we fix this if the app is using Expo?Insider
@EstebanChornet Did you find any solution for Expo?Alula
Installing the intl package solved the issue for me for expo building on android npmjs.com/package/intlInsider
I installed [email protected] with [email protected] and it doesn't work for me for some regions like pt-BR on Android. NumberFormat returns a number in the imperial format while it should be metric. On iOS it works though.Thirsty
My problem was that the library Intl wasn't formatting my numbers correctly for specific regions, All I had to do was to import every locale considered in the beginning of the file like: import "intl/locale-data/jsonp/pt-BR" and it worked. With extra steps you can import it dynamically, which then I did, probably better.Thirsty
@EstebanChornet you should place your comment as a full answer to the question.Algeria

© 2022 - 2024 — McMap. All rights reserved.