#1 - Expo apk keeps on crashing after build

amanbhoria

amanbhoria

Posted on September 11, 2024

#1 - Expo apk keeps on crashing after build

If you’ve been working with Expo and React Native for a while, you probably know how smooth development feels—until you try to create an APK. That’s when things can go sideways, like it did for me. After hours of debugging and frustration, I finally uncovered a bizarre issue that was causing my APK build to crash, even though my app was running perfectly on Expo Go.

In this blog, I’ll walk you through what happened, the errors I encountered, and how I ultimately fixed it after months of trying. Hopefully, this saves someone else from going through the same headache as I went through!

The Setup

Everything was working fine while testing the app on Expo Go. My app was using some external libraries like expo-image-picker. The core functionality, including image uploading seemed solid. But as soon as I generated an APK and ran it on a real device, the app would crash immediately after the splash screen.

I've gone through all the workarounds that has been mentioned on web including installing necessary package such as react-native-reanimated. Installing Sentry for debugging and what not.

Then after digging even more, I've found this on reddit:

Image description

So I've started using client development build instead of normal build.

I started seeing errors that didn’t make sense at first:

isFileUploadSupported error popping up, something I hadn’t anticipated.
An error saying “no route named ‘index’ exists in nested children”.
These errors were nowhere to be found while testing the app on Expo Go. Weird, right?

The Culprit

After endless debugging, I stumbled upon the issue accidentally. It turns out that a single import in my index.tsx file was causing the crash in the APK build, but not during Expo Go testing:

Image description

The Lesson

  • Expo GoAPK Build: While Expo Go is great for quick testing, it doesn’t always give you a complete picture of what will happen when you build an APK. Some issues, especially with native modules, only surface during the build process.

  • Watch Your Imports: Even an unused import can mess up your APK build. In my case, the @msg91comm/react-native-sendotp library caused issues with native modules, leading to crashes. Since it was used in other parts of the code but not directly in the **index.tsx **file, it threw me off at first.

  • Check Native Dependencies: Some libraries rely heavily on native code. Be extra cautious when using such libraries in an Expo project that you plan to build into a standalone APK. Make sure you test them properly on an actual APK build, not just Expo Go.

Conclusion

If you’re struggling with APK builds crashing after working fine in Expo Go, I’d recommend double-checking any imports or external libraries that may have native dependencies. Sometimes, something as trivial as a single import can break your entire APK.

Keep building!

💖 💪 🙅 🚩
amanbhoria
amanbhoria

Posted on September 11, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related