简体   繁体   English

如何减小 android 的 expo apk 大小?

[英]How to reduce expo apk size for android?

I have built an app using expo cli and when I run expo build:android its size is 65 mb.我已经使用 expo cli 构建了一个应用程序,当我运行 expo build:android 时,它的大小为 65 mb。 My app consist of only 7-8 screens.I have tried building.aab file but its size is also 62.5 mb.我的应用程序只包含 7-8 个屏幕。我尝试过 building.aab 文件,但它的大小也是 62.5 mb。 Is there any way to get my app <10mb?有什么方法可以让我的应用程序 <10mb?

Yes, you can reduce the size, but not with the expo .是的,您可以减小尺寸,但不能使用expo
The expo is a development tool, for production, you should use react-native. expo是开发工具,生产时应使用 react-native。

Migrating to React Native迁移到 React Native

  • react-native init a new project with the same name react-native 初始化一个新的同名项目
  • Copy the source files over from the Expo project从 Expo 项目复制源文件
  • Install all dependencies of the Expo project except Expo-specific libraries.安装 Expo 项目的所有依赖项,除了 Expo 特定的库。
  • Make necessary adjustments to the app.json file对 app.json 文件进行必要的调整
  • Copy over your.git folder into the new project.将您的.git 文件夹复制到新项目中。
  • Download the signing key of your Android app from Expo using exp使用 exp 从 Expo 下载 Android 应用程序的签名密钥
  • fetch:android:keystore and set it up fetch:android:keystore 并设置它
  • Build and test your app构建和测试您的应用

Reducing the size of React Native App (Android)减小 React Native App (Android) 的大小

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

Set def enableSeparateBuildPerCPUArchitecture = true.设置 def enableSeparateBuildPerCPUArchitecture = true。 Android devices support two major device architectures armebi and x86. Android 器件支持两种主要的器件架构 armebi 和 x86。 By default, RN builds the native libraries for both these architectures into the same apk.默认情况下,RN 将这两种架构的原生库构建到同一个 apk 中。

Reference:参考:
For more information, you can see this tutorial.有关更多信息,您可以查看本教程。 https://medium.com/@aswinmohanme/how-i-reduced-the-size-of-my-react-native-app-by-86-27be72bba640 https://medium.com/@aswinmohanme/how-i-reduced-the-size-of-my-react-native-app-by-86-27be72bba640

You can still achieve a much smaller build size without moving away from Expo, but you will need to use EAS (Expo Application Services) to build your project instead of Expo build.您仍然可以在不离开 Expo 的情况下实现更小的构建大小,但是您需要使用 EAS(Expo Application Services)来构建您的项目,而不是 Expo 构建。

You can find the documentation here: https://docs.expo.dev/build/introduction/ .您可以在此处找到文档: https://docs.expo.dev/build/introduction/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM