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

[0.62-rc.5] Android APK size increases after Gradle version bump #28330

Closed
robertying opened this issue Mar 17, 2020 · 8 comments
Closed

[0.62-rc.5] Android APK size increases after Gradle version bump #28330

robertying opened this issue Mar 17, 2020 · 8 comments
Labels
Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@robertying
Copy link
Contributor

Description:

This is a known issue discussed in 0.62-rc release thread: react-native-community/releases#157.

Original issue posted by @willholen and workaround provided by @ArrayZoneYour.


Issue

...

An unresolved issue that may deserve a mention somewhere:

  • Since the last Gradle upgrade, react.gradle is unable to remove unused executors and support libraries (

    def vmSelectionAction = {
    )

    • This means that apps using JSC based APKs are 600kb larger than necessary per arch in release mode, which can be can be remedied with a manual exclude "**/libhermes*.so" in packagingOptions
    • Hermes based APKs are 600kb larger than necessary. This can be remedied with exclude "**/libhermes-executor-debug.so", exclude "**/libhermes-inspector.so", exclude "**/libjsc.so" . Unfortunately, this change will also break debug builds, and I’m not aware of a workaround that works in both cases.

Workaround

I am using the workaround below for your last issue on 0.61, maybe it also works >on your case

android/app/build.gradle

def taskName = getGradle().getStartParameter().getTaskRequests().toString()

packagingOptions {
   // For Hermes, delete all the libjsc* files
   exclude "**/libjsc*.so"
   if (taskName.contains("Debug")) {
     // Release libs take precedence and must be removed
     // to allow debugging
     exclude '**/libhermes-executor-release.so'
   } else {
     // Reduce size by deleting the debugger/inspector
     exclude '**/libhermes-inspector.so'
     exclude '**/libhermes-executor-debug.so'
   }
}

React Native version:

System:
    OS: macOS 10.15.3
    CPU: (4) x64 Intel(R) Core(TM) i3-8100B CPU @ 3.60GHz
    Memory: 77.93 MB / 8.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 13.11.0 - /var/folders/zk/s0vxnzqs4fjgd3n3kycxvl0c0000gn/T/yarn--1584447329704-0.93200619086904/node
    Yarn: 1.22.4 - /var/folders/zk/s0vxnzqs4fjgd3n3kycxvl0c0000gn/T/yarn--1584447329704-0.93200619086904/yarn
    npm: 6.13.7 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
    Android SDK:
      API Levels: 29
      Build Tools: 29.0.3
      System Images: android-29 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 3.6 AI-192.7142.36.36.6200805
    Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
  npmPackages:
    @react-native-community/cli: 4.3.0 => 4.3.0 
    react: 16.13.0 => 16.13.0 
    react-native: 0.62.0-rc.4 => 0.62.0-rc.4 
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

  1. Build with or without hermes with RN 0.62
  2. See a size increase of 1-2 MB for each variant apk

Expected Results

Unused .so should be removed when packaging.

@Bardiamist
Copy link
Contributor

Bardiamist commented Apr 23, 2020

I tried this (your suggestion) on my current project.

Before:

armeabi-v7a: 27 958 792 bytes (28 MB on disk)
arm64-v8a: 29 616 411 bytes (29,6 MB on disk)
x86: 41 721 692 bytes (41,7 MB on disk)
x86_64: 52 003 181 bytes (52 MB on disk)

After:

armeabi-v7a: 27 432 761 bytes (27,4 MB on disk)
arm64-v8a: 29 051 347 bytes (29,1 MB on disk)
x86: 41 110 026 bytes (41,1 MB on disk)
x86_64: 51 391 286 bytes (51,4 MB on disk)

@Bardiamist
Copy link
Contributor

React native 0.63.1

Without:
94 266 084 bytes (94,3 MB on disk)

With:
91 818 978 bytes (91,8 MB on disk)

@alessioemireni
Copy link

I tried the workaround but without Hermes the app crash during startup (RN 0.62.2):

2020-09-16 10:38:24.940 22189-22331/? E/AndroidRuntime: FATAL EXCEPTION: create_react_context
    Process: -, PID: 22189
    java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so result: 0
        at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:825)
        at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:673)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:611)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:559)
        at com.facebook.hermes.reactexecutor.HermesExecutor.<clinit>(HermesExecutor.java:20)
        at com.facebook.hermes.reactexecutor.HermesExecutorFactory.create(HermesExecutorFactory.java:29)
        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:997)
        at java.lang.Thread.run(Thread.java:919)

@stale
Copy link

stale bot commented Dec 25, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 25, 2020
@Bardiamist
Copy link
Contributor

I'll check in 0.64.0 when it comes out

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 25, 2020
@Bardiamist
Copy link
Contributor

Bardiamist commented Mar 16, 2021

React native 0.64.0

Without workaround:
105 147 690 bytes

With workaround:
104 903 995 bytes

@Bardiamist
Copy link
Contributor

Bardiamist commented Mar 17, 2021

With that workaround I'm getting:

couldn't find DSO to load: libjscexecutor.so

when using camera

Because:

exclude "**/libjsc*.so"

Update: still have that problem and without exclude "**/libjsc*.so"

@stale
Copy link

stale bot commented Jan 9, 2022

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jan 9, 2022
@facebook facebook locked as resolved and limited conversation to collaborators Jan 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

7 participants