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

查看:140
本文介绍了如何在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

推荐答案

您可以尝试执行以下步骤

You can try following steps

  • 打开 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会负责将应用分发到正确的体系结构.使用此拆分将为两个apk生成版本号,依次为104856.它是由构建自动生成的,以避免版本冲突,所以请不要害怕(我这样做了).拆分后,apk的apk大小分别从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.

您可以在本文中找到更多信息

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天全站免登陆