Can*_*ğlu 11 android polyfills javascriptcore react-native react-intl
我正在尝试使用 的数字格式化程序Intl,它在 iOS 上完美运行,并且当调试器连接到 iOS 或 Android 时,但由于 Android 中的 JSC 过时,仅在没有连接调试器的情况下在 Android 上失败。
经过一番研究,我发现了两种可能的解决方案:
IntlpolyfillIntl在安装intl和react-intl使用纱线后,我首先像这样尝试了polyfill :
//in my app's index.js
if (!global.Intl) {
global.Intl = require('intl');
}
Run Code Online (Sandbox Code Playgroud)
虽然它仍然说ReferenceError: Can't find variable: Intl。
然后我放弃并尝试包含自定义 JSC(我已经确认正确引用了自定义 AAR),尽管我仍然遇到相同的错误。无论我做什么,我都无法Intl在没有附加调试器的情况下在 Android 上运行。
我究竟做错了什么?(我使用的是 React Native 0.59.9)
Sim*_*mon 29
小更新,从 React Native v0.60+ 开始,您可以定义 lib 的 intl+ 版本。
在您的app/build.gradle:
def jscFlavor = 'org.webkit:android-jsc-intl:+'
并在您的依赖项中实现它:
dependencies {
...
if (enableHermes) {
...
} else {
implementation jscFlavor
}
}
Run Code Online (Sandbox Code Playgroud)
小智 11
npm i intl
Run Code Online (Sandbox Code Playgroud)
之后导入
import "intl";
import "intl/locale-data/jsonp/en";
Run Code Online (Sandbox Code Playgroud)
然后使用Intl
例如
npm i intl
Run Code Online (Sandbox Code Playgroud)
如果在你的 app/build.gradle 中没有禁用 Hermes 的选项,并且你不能使用,org.webkit:android-jsc-intl:+那么Intl polyfill可以解决这个问题:
npm install intl
Run Code Online (Sandbox Code Playgroud)
在代码中:
import 'intl';
import 'intl/locale-data/jsonp/en'; // or any other locale you need
Run Code Online (Sandbox Code Playgroud)
我想删除这个问题,但我不能,因为已经有另一个答案了。
这与 JSC 无关。我的构建脚本没有正确更新 APK,而我认为是这样,而且我一遍又一遍地尝试旧的伪造 APK。否则,显然我做的一切都是正确的,因为它现在可以与新的 APK 一起使用。
| 归档时间: |
|
| 查看次数: |
9233 次 |
| 最近记录: |