Idea: keep React Native native libraries to the processors you ship #3
AmineYagoub
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
The problem. React Native's Gradle plugin adds
pickFirstsrules such as**/libreactnative.so,**/libjsi.so,**/libfbjni.so,**/libc++_shared.soand**/libhermesvm.so. In Android's packaging, a pick-first rule wins over an exclude. So an app that limits its processors still ships every prebuilt library for all four:armeabi-v7a,arm64-v8a,x86andx86_64.What it cost us. In Minhajna (djazairdev/minhajna#105), the universal APK meant for ARM phones came out at 65,053,601 bytes, with x86 and x86_64 code inside.
packaging.jniLibs.excludesdid nothing, and reading the rules inonVariantsfailed with "configuration not completed".The fix, in
apps/android/android/app/build.gradle:androidComponents.onVariants;lib/<abi>/<lib>for the processors actually built;The universal APK dropped to 34,443,995 bytes. A check in CI (
tools/android/release-apks.js) now rejects any APK that carries a processor it shouldn't.Who else it hits. Any React Native app that ships ARM only, splits its APKs by processor, or watches its download size, which matters most where data is expensive. Most apps never notice: the APK installs and runs, and is simply twice as big.
What to build
@react-native/gradle-plugin.Size: small. The logic is about 15 lines of Gradle, plus tests on a sample app. MIT or Apache-2.0, to match React Native.
From Minhajna's work; drafted with Claude Code.
All reactions