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

I compare 0.72.5 and 0.74.0 react native android app size,0.74.0 is 50MB,And 0.72.5 is 21.7 MB.How to reduce 0.74.0 android app size? #44291

Closed
Hao-yiwen opened this issue Apr 26, 2024 · 14 comments
Labels
Platform: Android Android applications. Resolution: Answered When the issue is resolved with a simple answer

Comments

@Hao-yiwen
Copy link

Description

I compare 0.72.5 and 0.74.0 react native android app size,0.74.0 is 50MB,And 0.72.5 is 21.7 MB.

Steps to reproduce

  1. 0.72.5
    截屏2024-04-27 02 08 00

  2. 0.74.0
    截屏2024-04-27 02 08 42

  3. Two react-native android app all use npx react-native init xxx,and direct use ./gradlew assembleRelease in android fold.

React Native Version

0.74.0

Affected Platforms

Runtime - Android

Output of npx react-native info

0.72.5

System:
  OS: macOS 14.4.1
  CPU: (11) arm64 Apple M3 Pro
  Memory: 83.59 MB / 18.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.18.2
    path: ~/.nvm/versions/node/v18.18.2/bin/node
  Yarn:
    version: 1.22.19
    path: ~/.nvm/versions/node/v18.18.2/bin/yarn
  npm:
    version: 9.8.1
    path: ~/.nvm/versions/node/v18.18.2/bin/npm
  Watchman:
    version: 2024.01.22.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.0
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.2 AI-232.10300.40.2321.11567975
  Xcode:
    version: 15.1/15C65
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /Users/haoyiwen/Library/Java/JavaVirtualMachines/corretto-17.0.9/Contents/Home/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.5
    wanted: 0.72.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: true

0.74.0

System:
  OS: macOS 14.4.1
  CPU: (11) arm64 Apple M3 Pro
  Memory: 92.14 MB / 18.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.18.2
    path: ~/.nvm/versions/node/v18.18.2/bin/node
  Yarn:
    version: 1.22.22
    path: ~/.nvm/versions/node/v18.18.2/bin/yarn
  npm:
    version: 9.8.1
    path: ~/.nvm/versions/node/v18.18.2/bin/npm
  Watchman:
    version: 2024.01.22.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.0
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.2 AI-232.10300.40.2321.11567975
  Xcode:
    version: 15.1/15C65
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /Users/haoyiwen/Library/Java/JavaVirtualMachines/corretto-17.0.9/Contents/Home/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.0
    wanted: 0.74.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: false


### Stacktrace or Logs

```text
no err stack.

Reproducer

no url.

Screenshots and Videos

No response

@github-actions github-actions bot added Platform: Android Android applications. Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Apr 26, 2024
Copy link

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

@Hao-yiwen
Copy link
Author

I found this really is a amazing thing, so Why lead to this question.

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Apr 26, 2024
@aziyatali
Copy link

@Hao-yiwen What was the reason why other had significant difference?

@Abhisflyingsoon
Copy link

@Hao-yiwen did you figure it out? really interested in this one. Maybe it has something to do with ProGuard config?

@b1ngx
Copy link

b1ngx commented Apr 28, 2024

Same problem, apk size changed from 53.6M to 114.7M.

@1280103995
Copy link

Same here. After upgrading to 0.74, the apk size has approximately doubled.

@Hao-yiwen
Copy link
Author

@Abhisflyingsoon Demo is pure reactNative project,don't do other thing.

@Daniel3711997
Copy link

21 to 23 causes this https://stackoverflow.com/questions/66511524/react-native-changing-minsdkversion-from-21-to-23-doubled-the-app-apk-size

@1280103995
Copy link

Same here. After upgrading to 0.74, the apk size has approximately doubled.

android {
    //...
    packagingOptions {
        jniLibs {
            useLegacyPackaging true
        }
    }
}

Work for me.

@baesumin
Copy link

AndroidManifest.xml

<application
...
android:extractNativeLibs="true">

@jonasbantunes
Copy link

I did some tests with the universal APK (containing all architectures) and splitting the APKs by architecture. The APK generated by gradlew assembleRelease does indeed shows an increase in size between the two React Native versions:

  • (Universal) RN 0.72.5: 20.6 MB
  • (Universal) RN 0.74.0: 50.6 MB
  • (x86_64 only) RN 0.72.5: 8.2 MB
  • (x86_64 only) RN 0.74.0: 16.9 MB

However, once the app is installed on the device, the single-architecture APK exhibits a reduction in app size:

  • (Universal) RN 0.72.5: 43.8 MB
  • (Universal) RN 0.74.0: 62.4 MB
  • (x86_64 only) RN 0.72.5: 30.8 MB
  • (x86_64 only) RN 0.74.0: 27.1 MB

If the app is distributed through an app store like Google Play, the store may generate an "optimized APK" for the users. Using the App Analyzer tool bundled with Android Studio, the estimated "Download Size" of the APKs is basically the same:

  • (Universal) RN 0.72.5: 20.3 MB
  • (Universal) RN 0.74.0: 19.6 MB
  • (x86_64 only) RN 0.72.5: 7.9 MB
  • (x86_64 only) RN 0.74.0: 8.1 MB

So users from an app store may not notice changes in the download or installed size of the app. But the increase in the size of the APK could be noticeable for some developers and users who download the APKs directly.

@danish5454
Copy link

any solution.
APK generated in RN : 0.73.6 : 27 MB
AFTER UPGRADE
APK generated in RN : 0.74.0 : 60 MB

@danish5454
Copy link

AndroidManifest.xml

<application ... android:extractNativeLibs="true">

that's worked

@cortinico
Copy link
Contributor

I did some tests with the universal APK (containing all architectures) and splitting the APKs by architecture. The APK generated by gradlew assembleRelease does indeed shows an increase in size between the two React Native versions:

  • (Universal) RN 0.72.5: 20.6 MB
  • (Universal) RN 0.74.0: 50.6 MB
  • (x86_64 only) RN 0.72.5: 8.2 MB
  • (x86_64 only) RN 0.74.0: 16.9 MB

However, once the app is installed on the device, the single-architecture APK exhibits a reduction in app size:

  • (Universal) RN 0.72.5: 43.8 MB
  • (Universal) RN 0.74.0: 62.4 MB
  • (x86_64 only) RN 0.72.5: 30.8 MB
  • (x86_64 only) RN 0.74.0: 27.1 MB

If the app is distributed through an app store like Google Play, the store may generate an "optimized APK" for the users. Using the App Analyzer tool bundled with Android Studio, the estimated "Download Size" of the APKs is basically the same:

  • (Universal) RN 0.72.5: 20.3 MB
  • (Universal) RN 0.74.0: 19.6 MB
  • (x86_64 only) RN 0.72.5: 7.9 MB
  • (x86_64 only) RN 0.74.0: 8.1 MB

So users from an app store may not notice changes in the download or installed size of the app. But the increase in the size of the APK could be noticeable for some developers and users who download the APKs directly.

Hey all,
Nicola here from the React Native team.

@jonasbantunes shared the correct answer here.
A couple of points for folks in this discussion:

  1. Comparing the APK size on disk is not a good indicator of App size. That's especially true if you use App Bundles to distribute your app via the Play Store (as APKs will be produced from the App Bundle based on the device architecture).

  2. You should compare either the compressed APK size (shown by Android Studio if you open the APK inside Android Studio) or the app size on device (via the App Info screen).

Specifically in 0.74, we reduced the App size on device by ~13% due to minSDK bump and removal of several unnecessary dynamic libraries (see https://reactnative.dev/blog/2024/04/22/release-0.74#bonus-android-app-size-reduction).

That's the metric that @jonasbantunes mentioned here:

  • (x86_64 only) RN 0.72.5: 30.8 MB
  • (x86_64 only) RN 0.74.0: 27.1 MB

Also

So users from an app store may not notice changes in the download or installed size of the app. But the increase in the size of the APK could be noticeable for some developers and users who download the APKs directly.

Users from App Stores will benefit from a reduction on App size on device.

The increase in APK size could be noticeable if you download the APK manually and distribute it to your users/developers that way (i.e. for test users or so).

The reason why you're seeing an APK size increase on disk, it's because the dex files are uncompressed starting from AGP 8.2 + with the minSdk bump to 23, the native libs are also shipped uncompressed on the APK. Regardless of compression inside the APK, when the APK is distributed through the wire it's compressed all together (so the 30Mb you see on disk are irrelevant for the users).

<application ... android:extractNativeLibs="true">

This is also not recommended as it will make your app slower.

@cortinico cortinico added Resolution: Answered When the issue is resolved with a simple answer and removed Needs: Triage 🔍 Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Attention Issues where the author has responded to feedback. labels Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Android Android applications. Resolution: Answered When the issue is resolved with a simple answer
Projects
None yet
Development

No branches or pull requests

10 participants