How to decrease React-Native android App Size

梦想的初衷 提交于 2021-02-07 03:07:30

问题


For my react native android app, size of codes I have written is only 12KB

But package generated is of size 7.9MB. How can i decrease that.

As per Documentation for react native, I have already enbabled proguard on file app_root/android/app/proguard-rules.pro but size of didn't decrease

...
android {
    ...
    buildTypes {
        release {
            ...
            minifyEnabled true
        }
    }
}
...

Is there a solution available for this?


回答1:


React Native app APKs include JSCore binaries for x86 and ARM. If you don't need x86 you could reduce the size to 3-4 MB.

1)In your app/build.gradle set

def enableSeparateBuildPerCPUArchitecture = true

2)remove x86 from abiFilters

this helped me in reducing size from 7.8 mb to 4.5MB




回答2:


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.

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 lil bit

And,

Set def enableSeparateBuildPerCPUArchitecture = true .

And check in android/app/build/outputs/apk/ - you will receive two apk files for armebi and x86 with approx half size of original apk.




回答3:


There are a couple of techniques in order to reduce your APK size:

  1. Split your app by architecture, you can split your APK by a list of well-known architectures: armeabi-v7a, x86, arm64-v8a, x86_64

    if you're distributing your application, using the play store it's a good idea to do it with the Android app bundle.

  2. Enabling prodguard will result in a lower size of the APK.

  3. Optimize your image assets, and if there's a chance try using SVG assets as much a possible.

There have been a change in the size of the resulted APK in React-Native 0.62 by enabling the new JavaScript engine which reduce the size of the native libs almost 40% Hermes Engine

These stats below are from Hermes engine and also mention the APK size reduction.



来源:https://stackoverflow.com/questions/35940957/how-to-decrease-react-native-android-app-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!