react-native
react-native copied to clipboard
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?
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
-
0.72.5
-
0.74.0
-
Two react-native android app all use
npx react-native init xxx,and direct use./gradlew assembleReleasein 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
| :warning: | Missing Reproducible Example |
|---|---|
| :information_source: | We could not detect a reproducible example in your issue report. Please provide either:
|
I found this really is a amazing thing, so Why lead to this question.
@Hao-yiwen What was the reason why other had significant difference?
@Hao-yiwen did you figure it out? really interested in this one. Maybe it has something to do with ProGuard config?
Same problem, apk size changed from 53.6M to 114.7M.
Same here. After upgrading to 0.74, the apk size has approximately doubled.
@Abhisflyingsoon Demo is pure reactNative project,don't do other thing.
21 to 23 causes this https://stackoverflow.com/questions/66511524/react-native-changing-minsdkversion-from-21-to-23-doubled-the-app-apk-size
Same here. After upgrading to 0.74, the apk size has approximately doubled.
android {
//...
packagingOptions {
jniLibs {
useLegacyPackaging true
}
}
}
Work for me.
AndroidManifest.xml
<application ... android:extractNativeLibs="true">
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.
any solution. APK generated in RN : 0.73.6 : 27 MB AFTER UPGRADE APK generated in RN : 0.74.0 : 60 MB
AndroidManifest.xml
<application ... android:extractNativeLibs="true">
that's worked
I did some tests with the universal APK (containing all architectures) and splitting the APKs by architecture. The APK generated by
gradlew assembleReleasedoes 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:
-
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).
-
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.
any solution. APK generated in RN : 0.73.6 : 27 MB AFTER UPGRADE APK generated in RN : 0.74.0 : 60 MB
This is a big addon to app size. I miss the day I can release armv7a apk for <7MB
yes same problem