如何在 react-native 中减少 Android APK 大小? [英] How to reduce Android APK size in react-native?

查看:30
本文介绍了如何在 react-native 中减少 Android APK 大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 react native 项目,但是每当我构建 Apk 文件时,它都会给我 47MB 的 Apk.我尝试了所有在 google 上发现有用的文档,但对我没有任何作用,有什么方法可以将我的应用程序大小减少到 10MB 以下,因为该应用程序只包含三到四页.任何帮助将不胜感激

I am working on react native project , but whenever i am building an Apk file , it give me Apk of 47MB. I tried every documentation which i found useful on google but nothing works for me, Is there any way to reduce my App size below 10MB as the app only contain three or four pages. Any help would be appreciated

推荐答案

您可以尝试以下步骤

  • 打开android/app/build.gradle
  • 设置 def enableProguardInReleaseBuilds = true 这将使 Progaurd 能够压缩 Java 字节码.这稍微减少了应用程序的大小
  • 设置 def enableSeparateBuildPerCPUArchitecture = true .Android 设备支持两种主要的设备架构 armebi 和 x86.默认情况下,RN 将这两种架构的原生库构建到同一个 apk 中.
  • Open up android/app/build.gradle
  • Set def enableProguardInReleaseBuilds = true this would enable Progaurd to compress the Java Bytecode. This reduces the app size by a tad bit
  • Set def enableSeparateBuildPerCPUArchitecture = true . Android devices support two major device artitectures armebi and x86. By default RN builds the native librariers for both these artitectures into the same apk.

设置最后一个函数会在 build 文件夹中创建两个不同的 apk.您必须将这两个 apk 都上传到 Play 商店,Google 会负责将应用程序分发到正确的架构.使用此拆分按 104856 等顺序为两个 apk 生成版本号.这是由构建自动生成的,以避免版本冲突,所以不要害怕(我做到了).此次拆分将 apk 大小从 arm 的 7MB 左右减少到 3.5MB,x86 的 5MB.

Setting the last function creates two distinct apk in the build folder. You have to upload both of this apk to Play Store and Google would take care of distributing the app to the correct architectures. Using this split generates version numbers for both apks in the order of 104856 and such. This is auto-generated by the build to avoid version conflicts, so don’t freak out (I did). This split reduced the apk size from around 7MB to 3.5MB for arm and 5MB for x86 respectively.

您可以在这篇文章中找到更多信息 https://medium.com/@aswinmohanme/how-i-reduced-the-size-of-my-react-native-app-by-86-27be72bba640

You can find more information in this article https://medium.com/@aswinmohanme/how-i-reduced-the-size-of-my-react-native-app-by-86-27be72bba640

这篇关于如何在 react-native 中减少 Android APK 大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆