Remove Javascript Bundle from APK and IPA apps (React Native and/or Expo)

Viewed 399

After building the APK of my React native app, I realized that the APK could be opened just like an archive and that there was inside of it a file named index.android.bundle which is the JavaScript bundle of the React Native app!

I don't understand why this file has been included there since the Android app works with compiled .dex files.

My question

  • Is there a way to make sure this file (JS bundle) is not included in the final application (APK for android and IPA for iOS) when creating it using either React Native or Expo ?
1 Answers

there is no way of not including the JS bundle in a react native app.

React native relies on that index.android.bundle, on android for example, in order to load your code. Basically all the JS that you've developed is inside these files and that's the main concept of React native.

A react native project is a regular native project (iOS or Android), that has a special view inside, on Android it's called ReactRootView and on iOS RCTRootView , these views are responsible for loading your JS bundle, in your case index.android.bundle, and then they communicate across the JS bridge in order to instantiate views and components.

I'll link you some articles explaining in more details how react native works and what's the concept of a JS bridge

https://hackernoon.com/understanding-react-native-bridge-concept-e9526066ddb8 https://formidable.com/blog/2019/react-codegen-part-1/

Related