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 got increased almost double after upgrading to RN 0.66.0 #32463

Closed
ursnj opened this issue Oct 22, 2021 · 19 comments
Closed

APK size got increased almost double after upgrading to RN 0.66.0 #32463

ursnj opened this issue Oct 22, 2021 · 19 comments
Labels
Needs: Attention Issues where the author has responded to feedback. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Resolution: Locked This issue was locked by the bot. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Comments

@ursnj
Copy link

ursnj commented Oct 22, 2021

Description

APK Size got increased almost double after upgrading to React Native 0.66.0

OLD APK Size: 18Mb
NEW APK Size: 41Mb

Version

0.66.0

Output of react-native info

info Fetching system and libraries information...
System:
OS: macOS 10.15.6
CPU: (4) x64 Intel(R) Core(TM) i5-5350U CPU @ 1.80GHz
Memory: 33.75 MB / 8.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 14.15.0 - /usr/local/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 7.16.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: Not Found
SDKs:
iOS SDK: Not Found
Android SDK:
API Levels: 23, 25, 26, 27, 28, 29, 30
Build Tools: 23.0.1, 25.0.3, 26.0.1, 28.0.2, 28.0.3, 29.0.2, 29.0.3, 30.0.2
System Images: android-26 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 4.1 AI-201.8743.12.41.6953283
Xcode: /undefined - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_201 - /usr/bin/javac
Python: 3.8.5 - /Users/nj/opt/anaconda3/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.66.0 => 0.66.0
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

Upgrade to react native latest version

Build APK.

Snack, code example, screenshot, or link to a repository

Screenshot 2021-10-22 at 11 25 43 PM

@react-native-bot react-native-bot added Needs: Author Feedback Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. and removed Needs: Triage 🔍 labels Oct 22, 2021
@github-actions
Copy link

⚠️ Missing Environment Information
ℹ️ Your issue may be missing information about your development environment. You can obtain the missing information by running react-native info in a console.

@Smiche
Copy link

Smiche commented Nov 9, 2021

Similar experience here after upgrading from react-native 0.64 to 0.66
image

@react-native-bot react-native-bot removed the Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. label Nov 9, 2021
@cortinico
Copy link
Contributor

What's your minSdkVersion? By any chance have you bumped from 21 to 23?

@Smiche
Copy link

Smiche commented Nov 9, 2021

minSdkVersion 24 and have not changed it while upgrading react-native.

@shubhamdeol
Copy link

I am also facing similar issue. App size on Playstore increased from 12 mb to 25 mb.

@shubhamdeol
Copy link

@cortinico can it be due to all libraries staring to support api 30 from 29 ?

@cortinico
Copy link
Contributor

So what could have happened is that in your bump, the minSdk version got moved from 21 to 23 (or above).
The change could have been imposed by one of the transitive dependency in your project.

React Native is specifying minSdkVersion 21, but if any of your library or your project is specifying a higher number, that will prevail.

Specifically with api lvl 23, the native libraries are uncompressed in the APK, resulting in the an apparent bigger size of the APK (see here https://stackoverflow.com/a/63417612).

The best to investigate this is if someone could create a reproduce on Github, adding a base commit on RN 0.64 and a subsequent commit with the bump to 0.66. That would greatly help investigate what happened.

@cortinico cortinico added Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Nov 12, 2021
@github-actions
Copy link

⚠️ Missing Reproducible Example
ℹ️ It looks like your issue is missing a reproducible example. Please provide a Snack or a repository that demonstrates the issue you are reporting in a minimal, complete, and reproducible manner.

@anirudhagarwal1
Copy link

To help better debug, attaching the screenshot of the diff in the size increase of libs.

Screenshot 2022-01-05 at 11 40 07 PM

@cortinico
Copy link
Contributor

To help better debug, attaching the screenshot of the diff in the size increase of libs.

Screenshot 2022-01-05 at 11 40 07 PM

From which version are you migrating from @anirudhagarwal1

@anirudhagarwal1
Copy link

To help better debug, attaching the screenshot of the diff in the size increase of libs.
Screenshot 2022-01-05 at 11 40 07 PM

From which version are you migrating from @anirudhagarwal1

I am upgrading from 0.63.4.

Also one more question. The above screenshot is of a release build, then why do I see some debug .so files(for ex: libhermes-executor-common-debug.so)? Is that expected?

@liamjones
Copy link
Contributor

This is also what we experienced upgrading from 0.63.4 to 0.66.3 too - about 6MB of new libs (including hermes/debug ones in non-Hermes release builds).

@cortinico
Copy link
Contributor

The above screenshot is of a release build, then why do I see some debug .so files(for ex: libhermes-executor-common-debug.so)? Is that expected?

Nope is not. The react.gradle script has a specific section for removing the .so that are not relevant to your build. Specifically:

react-native/react.gradle

Lines 360 to 379 in a03bd2f

if (enableHermes) {
// For Hermes, delete all the libjsc* files
include "**/libjsc*.so"
if (cleanup) {
// Reduce size by deleting the debugger/inspector
include '**/libhermes-executor-debug.so'
} else {
// Release libs take precedence and must be removed
// to allow debugging
include '**/libhermes-executor-release.so'
}
} else {
// For JSC, delete all the libhermes* files
include "**/libhermes*.so"
// Delete the libjscexecutor from release build
if (cleanup) {
include "**/libjscexecutor.so"
}
}

The best would be to try on an empty project on RN 0.66.0 and verify if it's working correctly or not.

@liamjones
Copy link
Contributor

Yep, doesn't look like it's working:

 ~/code  npx react-native init RNReleaseTest                                                                                                                                                                                                                    ∞
Need to install the following packages:
  react-native
Ok to proceed? (y) y
[snip]
 ~/code  cd RNReleaseTest                                                                                                                                                                                                                                           ∞
 ~/code/RNReleaseTest  cd android                                                                                                                                                                                                                                   ∞
 ~/code/RNReleaseTest/android  ./gradlew assembleRelease                                                                                                                                                                                                            ∞
Starting a Gradle Daemon (subsequent builds will be faster)
[snip]
BUILD SUCCESSFUL in 1m 6s
38 actionable tasks: 38 executed
 ~/code/RNReleaseTest/android  grep "enableHermes:" app/build.gradle                                                                                                                                                                                                ∞
    enableHermes: false,  // clean and rebuild if changing
 ~/code/RNReleaseTest/android  zip -sf app/build/outputs/apk/release/app-release.apk | grep libhermes                                                                                                                                                               ∞
  lib/arm64-v8a/libhermes-executor-common-debug.so
  lib/arm64-v8a/libhermes-executor-common-release.so
  lib/arm64-v8a/libhermes-executor-debug.so
  lib/arm64-v8a/libhermes-executor-release.so
  lib/arm64-v8a/libhermes-inspector.so
  lib/armeabi-v7a/libhermes-executor-common-debug.so
  lib/armeabi-v7a/libhermes-executor-common-release.so
  lib/armeabi-v7a/libhermes-executor-debug.so
  lib/armeabi-v7a/libhermes-executor-release.so
  lib/armeabi-v7a/libhermes-inspector.so
  lib/x86/libhermes-executor-common-debug.so
  lib/x86/libhermes-executor-common-release.so
  lib/x86/libhermes-executor-debug.so
  lib/x86/libhermes-executor-release.so
  lib/x86/libhermes-inspector.so
  lib/x86_64/libhermes-executor-common-debug.so
  lib/x86_64/libhermes-executor-common-release.so
  lib/x86_64/libhermes-executor-debug.so
  lib/x86_64/libhermes-executor-release.so
  lib/x86_64/libhermes-inspector.so
 ~/code/RNReleaseTest/android  zip -sf app/build/outputs/apk/release/app-release.apk | grep libjscexecutor                                                                                                                                                          ∞
  lib/arm64-v8a/libjscexecutor.so
  lib/armeabi-v7a/libjscexecutor.so
  lib/x86/libjscexecutor.so
  lib/x86_64/libjscexecutor.so

@anirudhagarwal1
Copy link

@cortinico Do you need anything else from my end to help you debug the issue?

@cortinico
Copy link
Contributor

cortinico commented Jan 7, 2022

@cortinico Do you need anything else from my end to help you debug the issue?

Nope, thanks for the input 👍. I was able to reproduce, and the bug is effectively there on 0.66.0. I've also tested on 0.67.0-rc.6 and the regression got already fixed.

From @liamjones command, running on 0.67:

$ zip -sf android/app/build/outputs/apk/release/app-release.apk | grep libhermes
  lib/arm64-v8a/libhermes-executor-common-release.so
  lib/arm64-v8a/libhermes-executor-release.so
  lib/arm64-v8a/libhermes.so
  lib/armeabi-v7a/libhermes-executor-common-release.so
  lib/armeabi-v7a/libhermes-executor-release.so
  lib/armeabi-v7a/libhermes.so
  lib/x86/libhermes-executor-common-release.so
  lib/x86/libhermes-executor-release.so
  lib/x86/libhermes.so
  lib/x86_64/libhermes-executor-common-release.so
  lib/x86_64/libhermes-executor-release.so
  lib/x86_64/libhermes.so

The fix is most likely this #32257 which haven't been included in 0.66.0. Given that 0.67 is really close to be released, I think we should be good to go with that.

Should there be blockers for 0.67.0, we can consider backporting #32257 to a point release for 0.66.x

Closing as this was essentially resolved. Feel free to re-open or comment if needed 👍

EDIT: typo

@ursnj
Copy link
Author

ursnj commented Feb 12, 2022

This issue not resolved in 0.67 also, im seeing same bundle size with newer version also.

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Feb 12, 2022
@weihangChen
Copy link

weihangChen commented Feb 15, 2022

after upgrading from 0.66 to 0.67 it went down for 30MB, but there is still a 40MB up compared to previous version. But I did have android minsdk bumped from 21 to 23, as others suggested, it also contributes to the increases of size

@mokshmodi96
Copy link

mokshmodi96 commented Jun 6, 2022

I bumped my minSdkVersion to 23 from 21 and apk size doubled but i found a workaround-ish on stackoverflow linked below here

@facebook facebook locked as resolved and limited conversation to collaborators Jan 7, 2023
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jan 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs: Attention Issues where the author has responded to feedback. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Resolution: Locked This issue was locked by the bot. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

No branches or pull requests

9 participants