android - APK 大小是否受到 React Native 中未使用的包的影响?

标签 android ios react-native

我想知道未使用的软件包是否会导致 APK 大小增大?

假设我为我的项目安装了数十个 NPM 软件包,但我从不导入和使用它们。这些文件显然会增加我的项目文件夹大小,但在构建 APK 时它们会影响 APK 大小吗?

这个问题也可以回答关于.ipa的问题。

最佳答案

APK 分析器不会查找任何未使用的依赖 NPM 包,因为您的所有 javascript 代码在作为 index.android.bundle Assets 包含在您的 Android 项目中之前已由 Metro bundle :

Metro is a JavaScript bundler. It takes in an entry file and various options, and gives you back a single JavaScript file that includes all your code and its dependencies.

因此在创建 apk 之前必须删除任何未使用的依赖项。了解 Tree shaking ,正是这样做的:

Tree shaking is a process in which the bundler includes only the code that is actually used.

请注意,只有与您的代码有依赖关系的模块才会包含在包中。

关于android - APK 大小是否受到 React Native 中未使用的包的影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57466260/

相关文章:

android - Iotivity scons 构建错误(cbor)

java - 进程 'command ' C :\Program Files\Java\jdk1. 8.0_25\bin\java.exe'' 以非零退出值 2 完成

android - Xamarin.Android 在没有互联网的情况下崩溃

ios - 意外地在 tableView.datasource = self 行发现 nil

javascript - React Native 交错渲染

javascript - React-Native 将 var 添加到 View 标签中

android - Lollipop 下方的 Material Design 支持 - 崩溃

ios - 无法使用 whereKey 为 textDidChange 搜索两个字符串对象

ios - _swift_abortRetainUnowned 将@objc 类捕获为无主时

javascript - 如何使用 Promise.all 等待两个请求,然后在回调中调用其他函数?