Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APK Size is doubled #23575

Closed
seriiix opened this issue Feb 21, 2019 · 26 comments
Closed

APK Size is doubled #23575

seriiix opened this issue Feb 21, 2019 · 26 comments
Labels
Bug Platform: Android Android applications. Resolution: Locked This issue was locked by the bot. Type: Docs Issues concerning the docs are tracked elsewhere: https://github.com/facebook/react-native-website

Comments

@seriiix
Copy link

seriiix commented Feb 21, 2019

🐛 Bug Report

The APK size is almost doubled in RN 58. In RN 57 the release build of the app was about ~8mb. Now it's ~16mb.

To Reproduce

Create a new project with react-native init and then generate a signed APK using this.

Expected Behavior

~8mb APK size.

Environment

React Native Environment Info:
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i5 CPU 760 @ 2.80GHz
Memory: 1.58 GB / 7.99 GB
Binaries:
Yarn: 1.13.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.2.0.0 AI-181.5540.7.32.5014246

@zenz
Copy link

zenz commented Feb 22, 2019

is that because 0.58 support arm64-v8a?
try to remove arm64-v8a support in build.gradle and compile your project again to see the result?

@creambyemute
Copy link

creambyemute commented Feb 22, 2019

Was the JSC updated on Android? That'd increase the appSize by ~4mb even with abi splitting.

2x 4 = 8mb increase in universal apk I'd guess.

@darekg11
Copy link

darekg11 commented Feb 22, 2019

@creambyemute This is the MB growth in my case, RN 0.57.8 app size was around 12.5MB and in 0.58.4 it is at around 20MB

@erennyuksell
Copy link

it's about using JSC

@radeno
Copy link
Contributor

radeno commented Mar 4, 2019

If you can use Android App Bundle.
Its extract every platform from APK and user just download what is needed by platform (ARM/X86 32/64bit) and display resolution.

@darekg11
Copy link

darekg11 commented Mar 4, 2019

Well, it's not really a bug then. Should this be an issue at all?

@radeno
Copy link
Contributor

radeno commented Mar 4, 2019

@darekg11 it is not issue. RN 0.58 adds support for ARM v8. RN 0.59 adding x86_64.
By gradle tools 3.2 (what is default in RN 0.58) is supported new Android App bundling.
In final our new production app based on RN 0.58 is slimmer than on RN 0.57.

@elMuso
Copy link

elMuso commented Mar 4, 2019

Damn i was wondering why the debug apk was <13 mb since when i used RN 0.56 it was 6 mb.. 6 MB! . I guess its time to generate separate apk files for google play . This should be somewhere in the docs. It was driving me insane, i thought it was my build tools version

@radeno
Copy link
Contributor

radeno commented Mar 4, 2019

Just choose this. It is not APK anymore. But .aab
image

EDIT:

Google Play console must have App key signing enabled.

@dxhung87
Copy link

I create a new project with react-native init (RN 0.59) and then generate a signed APK. The APK size is ~30MB what happend??

@radeno
Copy link
Contributor

radeno commented Mar 14, 2019

APK always contains support for 3 platforms (ARM, ARM64, X86, X86_64 is not bundled for 0.59.0) and includes new JSC (javascript core). Use AAP (Android App Bundle).

It is not a bug.

@darekg11
Copy link

This is because of JavaScript Core update.
Just change:
def enableSeparateBuildPerCPUArchitecture = false to def enableSeparateBuildPerCPUArchitecture = true in your android/app/build.gradle so APK file will be splitted per architecture resulting in smaller APK files that all should be updated to Google Play and Store will automatically pick up the correct version for user.

@dulmandakh dulmandakh added the Platform: Android Android applications. label Mar 17, 2019
@Salakar Salakar added the Type: Docs Issues concerning the docs are tracked elsewhere: https://github.com/facebook/react-native-website label Mar 19, 2019
@Salakar
Copy link
Contributor

Salakar commented Mar 19, 2019

Hey all 👋thanks for sending this issue over.

The solution provided by @darekg11 is the correct approach. This is also now documented here in a bit more detail.

@Salakar Salakar closed this as completed Mar 19, 2019
@elMuso
Copy link

elMuso commented Apr 16, 2019

Thanks for the documentation. However i think that there should also be documentation of the usage of Android app bundle with android studio and without android studio [using only the command line]

@Salakar
Copy link
Contributor

Salakar commented Apr 19, 2019

@LiteKat thanks for the feedback, could you send a PR to the docs with the changes you think are needed as mentioned above

@TrustDec
Copy link

TrustDec commented May 8, 2019

Thanks

@AmyrAhmady
Copy link

The thing is, universal apk file is like 27mb now, which was around 7mb before for a clean react-native project.
even they added new architectures support such as arm64-v8a and x86_64, that doesnt mean it should go this much high.

Before latest updates it was around 7mb while it was supporting both armeabi-v7a and x86. and for separated apk files, they were only 3mb and 5mb. but now after these latest updates they all changed and now even x86 and armeabi-v7a are more than 7mb (which was the universal apk file size!)

@Schabaani
Copy link

Same issue. RN 57 app size was 9mb and now (RN 59.9) around 20mb. What should I do?

@alikazemkhanloo
Copy link

when upgrading to rn 59 I removed this code from app/build.gradle:

ndk {
     abiFilters ...
}

my app size went up to 54MB.
Using

zipinfo -1 YOUR_APK_FILE.apk | grep \.so$

I found out there are lots of platforms that I don't want, including mips.
So I decided to use abiFilters as below

ndk {
    abiFilters "armeabi-v7a","arm64-v8a"
}

then app size reduced to 22MB.
if you want to support emulators you can add "x86", "x86_64" to filters. And it will cost you with extra app size.

@arjun-mavonic
Copy link

Hi,
Created a new app using
react-native init AwesomeProject (react-native version is 0.60.4)
cd AwesomeProject
generated the aab file using ./gradlew bundleRelease
App size is 22mb
set the enableSeparateBuildPerCPUArchitecture and enableProguardInReleaseBuilds to true in android/app/build.gradle.
generated the aab file using ./gradlew bundleRelease
App size is 22mb

I followed this document

App size is huge. This is not acceptable.
My actual app on which I have worked upon is around 46 mb after optimization.
Not acceptable. My business team with throw me away.

We have developed a True Native App on android which has lots of features and the app size is 7mb.

@radeno
Copy link
Contributor

radeno commented Jul 18, 2019

@arjun-livquik what do you measure? File size of generated aab file? Wrong.

Only right measurement is looking for final size after shrining in Google Play.
You can check it through Release Management -> Artifact Library and Explore build you want.

@arjun-mavonic
Copy link

@radeno,
Sorry, I am new to .aab. I generated APKs and file size looks reasonable. That's a huge relief.

➜ du -h app/build/outputs/apk/release/app-arm64-v8a-release.apk
6.2M	app/build/outputs/apk/release/app-arm64-v8a-release.apk
➜ du -h app/build/outputs/apk/release/app-armeabi-v7a-release.apk
5.9M	app/build/outputs/apk/release/app-armeabi-v7a-release.apk
➜ du -h app/build/outputs/apk/release/app-x86-release.apk
5.9M	app/build/outputs/apk/release/app-x86-release.apk
➜ du -h app/build/outputs/apk/release/app-x86_64-release.apk
6.5M	app/build/outputs/apk/release/app-x86_64-release.apk

Thanks @radeno

@sijad
Copy link

sijad commented Jul 18, 2019

You can also give hermes engine a try.

@arjun-mavonic
Copy link

@sijad

After enabling Hermes. This is great. I checked my new apk of actual app. It's reduced significantly.

➜ du -h app/build/outputs/apk/release/app-arm64-v8a-release.apk
3.8M	app/build/outputs/apk/release/app-arm64-v8a-release.apk
➜ du -h app/build/outputs/apk/release/app-armeabi-v7a-release.apk
3.6M	app/build/outputs/apk/release/app-armeabi-v7a-release.apk
➜ du -h app/build/outputs/apk/release/app-x86-release.apk
4.0M	app/build/outputs/apk/release/app-x86-release.apk
➜ du -h app/build/outputs/apk/release/app-x86_64-release.apk
4.0M	app/build/outputs/apk/release/app-x86_64-release.apk

@arlovip
Copy link

arlovip commented Aug 8, 2019

Publishing to other stores

By default, the generated APK has the native code for both x86 and ARMv7a CPU architectures. This makes it easier to share APKs that run on almost all Android devices. However, this has the downside that there will be some unused native code on any device, leading to unnecessarily bigger APKs.

You can create an APK for each CPU by changing the following line in android/app/build.gradle:

- def enableSeparateBuildPerCPUArchitecture = false
+ def enableSeparateBuildPerCPUArchitecture = true

Upload both these files to markets which support device targeting, such as Google Play and Amazon AppStore, and the users will automatically get the appropriate APK. If you want to upload to other markets, such as APKFiles, which do not support multiple APKs for a single app, change the following line as well to create the default universal APK with binaries for both CPUs.

- universalApk false  // If true, also generate a universal APK
+ universalApk true  // If true, also generate a universal APK

Enabling Proguard to reduce the size of the APK (optional)

Proguard is a tool that can slightly reduce the size of the APK. It does this by stripping parts of the React Native Java bytecode (and its dependencies) that your app is not using.

IMPORTANT: Make sure to thoroughly test your app if you've enabled Proguard. Proguard often requires configuration specific to each native library you're using. See app/proguard-rules.pro.

To enable Proguard, edit android/app/build.gradle:

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = true

All details see Official file

Hope it can help you.

@dori871992
Copy link

dori871992 commented Mar 1, 2020

Enabling Hermes will significantly reduce app bundle size.

@facebook facebook locked as resolved and limited conversation to collaborators Mar 19, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Mar 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Platform: Android Android applications. Resolution: Locked This issue was locked by the bot. Type: Docs Issues concerning the docs are tracked elsewhere: https://github.com/facebook/react-native-website
Projects
None yet
Development

No branches or pull requests