reactjsreact-nativeexpo-cameraexpo-core-modules

React App (Bare Native) crashes as soon as launched on Android. Installed Expo-core-modules, works OK. Installed Expo-camera, crashes


The app crashes as soon as it starts on the Android emulator, before it even displays the app.tsx page content.

App build is successful, but Logcat shows some fatal exception:

FATAL EXCEPTION: main Process: com.valhalla, PID: 26240 java.lang.RuntimeException: Unable to get provider com.google.mlkit.common.internal.MlKitInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.mlkit.common.internal.MlKitInitProvider" on path: DexPathList[[zip file "/data/app/~~A7kyXyor_Na1MF7n5uEUNg==/com.valhalla-GpphL_ikUmkO2EFehLIkSQ==/base.apk"]

My app is a bare native react app and recently I installed expo-core-modules it still was working but as soon as I installed expo-camera, the crash issue has started.

dependencies:

"react": "18.2.0",
"react-native": "0.74.5",
"expo": "^51.0.0",
"expo-camera": "\~15.0.16"

devdependencies:

"@types/react": "\~18.2.79",
"typescript": "\~5.3.3"

engines:

"node": "\>=18"

Exact expo version: 51.0.38

I've noticed on other forums, folks mentioned updating the dependencies worked for them. I have updated all Expo dependencies to latest version.

I have tried the app build on Android Emulator API 34 and 35 on 2 different laptops with same versions and dependencies. Also tried it on a old physical Android device API 28 (Oneplus 3 working condition). The behavior is exactly the same for all 3 cases i.e the app opens and crashes immediately.

As soon as I revert the source code to the state before installing expo-camera i.e back to expo-core-modules, the app again works for all the 3 cases (emulator/physical device) mentioned above.


Solution

  • After trying through below troubleshooting, I was able to resolve the issue. Solution listed at number (4).

    1. Ensure all the Expo dependencies are updated to latest version. $ npx expo install --fix
    2. Capture "exceptions" via Android Studio Logcat.
    3. Referred the link below, which was exhibiting the same crash behavior seen in my case, which was after installing expo-camera module. However, in this case the build was failing while my app build was successful. expo-camera module breaks bare React Native app

    Note that I did implement the steps mentioned by @G26bandit in the above link, since they were already a part of the "app build tutorial" i was following. They are still in place.

    1. Run ./gradlew clean in your "Project/android" folder ( Uses your project's gradle wrapper to execute your project's clean task. Usually, this just means the deletion of the build directory i.e Project/android/app/build directory. )

    Now, simply run the node server

    $ npm start reset-cache

    And run the app, during which it recreates the build directory

    $ npm run android

    I am glad that the issue has been resolved. Hope this is helpful to others.