android - React-native Hermes 生产构建失败
问题描述
react@17.0.1
react-native@0.63.4
没有 Hermes 的构建工作正常。
使用 Hermes 进行开发构建工作正常。
如果我注释掉所有代码并仅使用<Text>Works</Text>
.
如果我放回所有依赖项:Redux、React-navigation、react-native-paper 等 - 构建过程会卡在 34%:
...
info Done writing bundle output
info Done writing sourcemap output
info Copying 32 asset files
info Done copying assets
/Users/main/git/my-app/app/android/app/build/generated/assets/react/release/index.android.bundle:13:134: warning: the variable "Promise" was not declared in function "isBoldTextEnabled"
...
其余日志遵循相同的模式:
the variable "SOMETHING" was not declared in function "SOMETHING"
react-native run-android --variant=release
不会发出警告,但它与生产构建相同:
...
info Done copying assets
<=====--------> 41% EXECUTING [3m 20s]
> :app:bundleReleaseJsAndAssets
据我了解,这意味着问题是由我的 npm 依赖项之一引起的。有没有一种简单的方法可以解决这个问题,而无需手动逐个查看每个依赖项?
我已经解决了有关 StackOverflow 和 react-native Github 问题的所有相关问题。
解决方案
我通过只用一个视图构建一个空的 APK,然后插入我的部分代码并一次又一次地构建,找到了根本原因。原来这个问题是由我的源代码中的一个大 JSON 文件引起的。
Hermes 有一个已知的错误。而不是加载.json
文件,我必须加载一个字符串和JSON.parse()
它。
推荐阅读
- ssl - PyOpenSSL - 使用自签名证书验证子证书
- jquery - jQuery 代码 - 这可以改进吗?
- scala - 如何在多行中实现步骤定义?
- angular - 必须在 @ngtools/webpack 的配置中指定“tsConfigPath”,从 Angular 4 迁移到 6
- sql-server - 我想写从 postgresql 到 SQL Server 的精确查询
- c++ - c ++用另一个名称重命名STL向量
- linux - per_cpu 变量的 kallsyms_lookup_name
- azure - 添加新集合时对 Azure Cosmos DB 模拟器的高需求
- mysql - 根据另外两个表(MySQL)更新列值
- r - 对列中的一组相似值进行分组