10

Ever since I started programming in React Native with Expo, I have been using an ios physical device together with Expo app. I never had any major issues.

Now i wanted to start fixing any bugs on android, but when running the Expo app on my android physical device the Expo app crashes (shuts down) while downloading bundle. It doesn't print any errors into my console, so i don't even know where to start...

Here is my app.json:

{
  "expo": {
    "name": "PointoUserApp",
    "slug": "PointoUserApp",
    "version": "1.0.0",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "orientation": "portrait",
    "icon": "./assets/Images/icon.png",
    "splash": {
      "image": "./assets/Images/splash.png",
      "resizeMode":"contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "bundleIdentifier": "com.meretc23.PointoUserApp"
    },
    "android":{
      
    },
    "web": {
      "favicon": "./assets/Images/favicon.png"
    }
  }
}

notice it is empty under android because i dont know what is required.

Below is my package.json file as well.

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@expo-google-fonts/inter": "^0.1.0",
    "@fortawesome/fontawesome-svg-core": "^1.2.30",
    "@fortawesome/free-brands-svg-icons": "^5.14.0",
    "@fortawesome/free-solid-svg-icons": "^5.14.0",
    "@fortawesome/react-native-fontawesome": "^0.2.5",
    "@ionic/react": "^5.3.1",
    "@react-native-community/art": "^1.2.0",
    "@react-native-community/async-storage": "~1.11.0",
    "@react-native-community/datetimepicker": "2.4.0",
    "@react-native-community/masked-view": "0.1.10",
    "@react-navigation/bottom-tabs": "^5.7.3",
    "@react-navigation/material-top-tabs": "^5.2.16",
    "@react-navigation/native": "^5.7.2",
    "@react-navigation/stack": "^5.8.0",
    "@types/react-native-snap-carousel": "^3.8.2",
    "core-js": "^3.6.5",
    "expo": "^38.0.0",
    "expo-constants": "~9.1.1",
    "expo-font": "~8.2.1",
    "expo-linking": "^1.0.3",
    "expo-localization": "~8.2.1",
    "expo-location": "~8.2.1",
    "expo-permissions": "~9.0.1",
    "expo-status-bar": "^1.0.0",
    "firebase": "^7.21.1",
    "geolib": "^3.3.1",
    "i18n-js": "^3.7.1",
    "react": "16.11.0",
    "react-dom": "16.11.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz",
    "react-native-check-box": "^2.1.7",
    "react-native-gesture-handler": "~1.6.0",
    "react-native-localize": "^1.4.1",
    "react-native-map-clustering": "^3.3.9",
    "react-native-map-link": "^2.7.17",
    "react-native-maps": "0.27.1",
    "react-native-modal": "^11.5.6",
    "react-native-picker-select": "^8.0.0",
    "react-native-progress": "^4.1.2",
    "react-native-progress-circle": "^2.1.0",
    "react-native-qrcode-svg": "^6.0.6",
    "react-native-reanimated": "~1.9.0",
    "react-native-restart": "0.0.17",
    "react-native-safe-area-context": "^3.0.7",
    "react-native-screens": "~2.9.0",
    "react-native-snap-carousel": "^4.0.0-beta.5",
    "react-native-svg": "12.1.0",
    "react-native-tab-view": "^2.15.1",
    "react-native-web": "~0.11.7",
    "react-navigation": "^4.4.0",
    "react-navigation-stack": "^2.8.2",
    "react-redux": "^7.2.1",
    "redux": "^4.0.5",
    "redux-thunk": "^2.3.0",
    "yargs-parser": "^18.1.3"
  },
  "devDependencies": {
    "@babel/core": "^7.8.6",
    "babel-preset-expo": "^8.2.3"
  },
  "private": true
}

Lesson learned: if you want to run an app on both ios and android, always monitor on both simultaneously before your app is too big to know where the issue is coming from....

Help appreciated

Mireia
  • 143
  • 1
  • 2
  • 10

5 Answers5

6

I'm running into the same issue right now. In my situation I've narrowed it down to the android adaptiveIcon configuration. If I use a path to a real png, the app crashes on bundle download. If I don't include adaptiveIcon under android, the app crashes. The only way it won't crash is to include adaptiveIcon linked to a file that doesn't even exist. This logs an error that Expo can't find the file, but the app will actually load. Extremely strange. Try adding this to your app.json file.

"android": {
  "adaptiveIcon": {
    "foregroundImage": "./assets/anImageThatDoesNotExist.png",
    "backgroundColor": "#FFFFFF"
   }
 },
addisonian
  • 69
  • 1
  • 3
2

I had this issue as well. Trying to find the solution on the internet and seems there is not one answer. So what I did, I installed android emulator (I don't own android devices). I installed the app on the emulator. I run adb logcat -v threadtime then I found this error

12-07 22:28:43.724  5441  5441 E AndroidRuntime: FATAL EXCEPTION: main
12-07 22:28:43.724  5441  5441 E AndroidRuntime: Process: com.danggrianto.eggies, PID: 5441
12-07 22:28:43.724  5441  5441 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.horcrux.svg.SvgView.setTintColor(SvgView.java:189)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.horcrux.svg.SvgViewManager.setTintColor(SvgViewManager.java:98)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.horcrux.svg.SvgViewManager.setTintColor(SvgViewManager.java:32)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.viewmanagers.RNSVGSvgViewManagerDelegate.setProperty(RNSVGSvgViewManagerDelegate.java:62)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.ViewManagerPropertyUpdater.updateProps(ViewManagerPropertyUpdater.java:46)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.ViewManager.updateProperties(ViewManager.java:84)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.ViewManager.createViewInstance(ViewManager.java:188)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.ViewManager.createView(ViewManager.java:115)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.NativeViewHierarchyManager.createView(NativeViewHierarchyManager.java:281)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute(UIViewOperationQueue.java:194)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:909)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:1026)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.UIViewOperationQueue.access$2600(UIViewOperationQueue.java:47)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:1086)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:29)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:175)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:85)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1229)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1239)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.view.Choreographer.doCallbacks(Choreographer.java:899)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.view.Choreographer.doFrame(Choreographer.java:827)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1214)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.os.Handler.handleCallback(Handler.java:942)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:99)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.os.Looper.loopOnce(Looper.java:201)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:288)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:7898)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Turn out the issue is at com.horcrux.svg.SvgView.setTintColor(SvgView.java:189)

I checked the code and then I upgraded react-native-svg to the latest version and this fix my issue.

1

My last expo project did not even have an android property, and my ios property only has supportsTablet as true. Try removing the android property altogether

PhantomSpooks
  • 2,877
  • 2
  • 8
  • 13
  • Also take a look at [this](https://docs.expo.io/versions/latest/config/app/) – PhantomSpooks Nov 21 '20 at 18:05
  • I’ve had my app crash with no warning a few times. Sometimes it was that i needed to reset the metro cache. Nearly all the time there was an error I hadn’t noticed. Could you post your app.is and the last file you were working on? – PhantomSpooks Nov 22 '20 at 01:32
1

I just learnt the very hard way! I found that android is less tolerant of react native StyleSheet discrepancies. If your Expo Go app crashes on android and works well with ios, check at what navigation stage it is crashing. Then take a look closely at your StyleSheet props. In my case I had this causing the error:

container: {
    flex: 1,
    backgroundColor: '#3f3939',
    alignItems: 'left' // this made my android app crash but not on ios
  },

so changed to

container: {
    flex: 1,
    backgroundColor: '#3f3939',
    alignItems: 'center'
  },

and it works just fine. I think I made the mistake of this in my early learning of StyleSheet

Oao
  • 121
  • 7
  • I just hit a similar problem on Android, in my case any value for alignItems causes it to crash. I just have to remove that style for it to not crash. Very strange. – cakidnyc Jan 20 '23 at 18:33
0

I ran into this exact same problem. Changing your foregroundImage to a non-existent location works but it's not a good solution as you have to use a real image for your play store build. When you use the real image some of your users will experience the same immediate crashes you're seeing on the emulator.

// Not a good solution
"android": {
  "adaptiveIcon": {
    "foregroundImage": "./assets/adaptive-icon.png", // use for release build
    // "foregroundImage": "./assets/anImageThatDoesNotExist.png", // use for development build
    "backgroundColor": "#FFFFFF"
  },

The real problem turned out to be that my splash screen image was much too large (~13MB). I replaced it with a smaller image (~750KB) and that fixed the seemingly unrelated adaptive-icon.png crash. It couldn't hurt to check the sizes of all your app images as well.

T. Neff
  • 15
  • 3