Expo app crashes when attempting to write a new record with Realm SDK

I created an Expo React Native app using the “Quick start with Expo” documentation. I modified the schema and variable names to match my data structure and set up the backend in App Services, also by following the Realm documentation. I set up Flexible device sync as well as the user authentication stuff.

Everything looks good (including log ins) until I try to add a record. The app running in an Android emulator crashes when the code gets to these lines: ('Entry is the name of my schema)

realm.write(() => {
        realm.create('Entry', Entry.generate(newEntry, userId));

I get no error messages in console nor in the Realm logs. The schema definition in the app matches that in the Realm backend.

The following is my package.json dependencies:

    "@realm/react": "^0.3.1",
    "expo": "^44.0.6",
    "expo-dev-client": "~0.8.4",
    "expo-splash-screen": "~0.14.2",
    "expo-status-bar": "~1.2.0",
    "expo-updates": "~0.11.6",
    "react": "17.0.1",
    "react-dom": "17.0.2",
    "react-native": "0.64.3",
    "react-native-get-random-values": "~1.8.0",
    "react-native-web": "0.17.1",
    "realm": "^10.19.0"

I tried upgrading the packages to the latest version with the same results:

    "@realm/react": "^0.3.2",
    "expo": "^46.0.2",
    "expo-dev-client": "~1.1.1",
    "expo-splash-screen": "~0.16.1",
    "expo-status-bar": "~1.4.0",
    "expo-updates": "~0.14.3",
    "react": "18.0.0",
    "react-dom": "18.0.0",
    "react-native": "0.69.3",
    "react-native-get-random-values": "~1.8.0",
    "react-native-web": "0.18.7",
    "realm": "^10.19.5"

I’ve tried simplifying the schema, creating a new app in the Realm backend, and furious web searches with no luck

Thank you!

Just to follow up, I created a new Realm Expo React Native app with the template and ran it without modifying. It crashes at the same point (writing a newly created record)

Hi @Nick_Martin,

Can you please set the log level to trace (Realm.App.Sync.setLogLevel(app, 'trace'))? The messages you get leading to the crash may clarify what the SDK is doing/expecting, and give hints of what may be wrong there.

1 Like

Thanks for the suggestion!

I added that line to the AppSync file like so:

import Realm from 'realm';
import { useApp, useUser } from '@realm/react';
{other imports}

export function AppSync() {
  const app = useApp();
  Realm.App.Sync.setLogLevel(app, 'trace');

I didn’t see any additional logging in the console or the Realm app logs. Did I implement this correctly? Where should I expect to see additional logging?

Just as an update, I’ve recreated the app by following the React Native tutorial. It connects to my Realm backend without crashing.

I would still like to solve the crashing issue with Expo since that’s how I’d prefer to develop the app. I’m open to suggestions

Thanks @Nick_Martin ,

If we understood correctly, then, the “regular” React Native tutorial works as expected, but the Expo variant crashes on write operations, is that the case?

That’s correct. I was not able to write to a synced realm with an app built with the Expo template and the app crashed consistently on the write function. I was on an android emulator

The same setup was used for an app built with the React Native template (same emulated device and same Realm backend) and it is working as expected with no crashes

Hi @Nick_Martin ,

I’ve just noticed that the data structure for the Expo sample code doesn’t match the one in the React Native sample, so that the sample app would work locally (and indeed I checked that it does), but would clash with the existing setup on the backend, that matches the RN sample instead.

Have you tried to correct Task.ts so that the model matches the React Native sample?

To further elaborate on this, I’ve been able to fully run the Expo tutorial with Sync on iOS, providing that the App Services app it connects to

  • Is a new one (i.e. not set up starting from a tutorial for a different SDK - they’re not compatible)
  • Is set in Development Mode, so that the data structure is dictated by the app
  • Device Sync is set for Flexible (most other tutorials use Partition)

I’ve only tried Android (since I’m on Linux).

What are the specs of the device you’re using? If it’s not an Android-related issue, I suspected it might have to do with not having enough ram or something

to address the points you brought up:

  • I’ve verified that the schema on the app and on the backend match. I’ve even simplified them so that it’s a single field (other searching indicated that schema mismatches might cause a crash of the dev client)
  • I’m generating the project from the template, so the SDK should be compatible
  • The Expo tutorial mentions Flexible sync and turning on Dev Mode

A few other things that might help

  • I generated every version of the Expo project using the following command: expo init <ProjectName> --template @realm/expo-template-js
  • I’m testing exclusively on Android. I’ve tried the latest 2 Pixel models with the same behavior. I even increased RAM and storage allocations with no difference
  • The expo development app crashes on write operation even when not attempting to sync (in sync.config, { enabled: false }
  • Sometimes when it crashes, I see a brief flash of an error dialog on the device but I can’t actually see what it says

Hi I would like to add my experience to this conversion as I’m in the same boat.

Created a new project using the Expo template code only, ran the command: expo run:android with the Android Studio Emulator open, the development build opens no problem but as soon as I try to add a new entry, the app crashes without error.

Logcat gives a ton of information but I’m able to get the following error (I can provide a more detailed log if this isn’t helpful):
: Can't get WAA status for Mavatar! : java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference : at com.google.apps.tiktok.dataservice.z.b(PG:1) : at com.google.apps.tiktok.dataservice.at.a(PG:1) : at com.google.apps.tiktok.tracing.ed.a(PG:2) : at com.google.common.util.concurrent.aj.a(PG:2) : at com.google.common.util.concurrent.ac.apply(PG:1) : at com.google.common.util.concurrent.h.e(PG:2) : at com.google.common.util.concurrent.j.run(PG:9) : at com.google.common.util.concurrent.bf.execute(PG:1) : at com.google.common.util.concurrent.d.i(PG:1) : at com.google.common.util.concurrent.d.l(PG:12) : at com.google.common.util.concurrent.d.n(PG:2) : at com.google.common.util.concurrent.i.f(PG:1) : at com.google.common.util.concurrent.j.run(PG:13) : at com.google.android.libraries.i.af.run(PG:1) : at com.google.android.libraries.i.an.run(PG:23) : at com.google.android.libraries.i.l.run(PG:2) : at com.google.android.libraries.i.q.run(PG:4) : at java.lang.Thread.run(Thread.java:923)

It’s worth mentioning that running a standalone build - eas build - doesn’t have any problem running on the emulator or physical device, only the expo-dev-client seems to have trouble.

1 Like

Thanks @Ben_Ujdur ,

That’s indeed useful information: it’s interesting to notice that nowhere in the stack trace there’s a sign of the Realm SDK, it’s a TikTok (?) library that crashes instead.

This seems to reinforce the hypothesis that’s not a Realm SDK issue in itself, but more an environment conflict, almost certainly limited to Android (it’s a Google library) and to the expo-dev-client (it works with eas). At this time, we don’t know if it’s just Linux, either, but I’d assume it may be, as we’d likely have many more occurrences reported otherwise.

I’ve almost enough to put together an internal ticket to investigate: could you please specify

  • The Linux distribution/version you’re using
  • The IDE and its version.
  • Same for Android SDK, Realm SDK, Expo, React Native, …
  • Yes, as many logs as possible, please: as specified above, ideally we need the trace level for Realm logs, if it’s difficult to collect in the standard console, you can use a custom class, as I did in our sample code.

Thank you both for your patience and collaboration to get to the bottom here!

Thank you @Ben_Ujdur for chiming in! Nice to see I’m not the only one experiencing this

As for the “TikTok” library, this stack exchange answer indicates that it’s just an internal Google app and is unrelated to the social media app of the same name.

When I can get access to my dev environment, I’ll provide as much version information as I can get for the different tools and SDKs. My read of the error logs points to an issue with either the JDK version or the Android SDK. The error is a Java exception but it seems like it’s breaking on a missing dependency coming from the Android environment

1 Like

I am also facing the same issue with android, but in iOS, the dev client does not have this crashing issue. Even for the android if I do a release build this issue is not there. Is there a workaround for this ?

1 Like

Hi @lakshan_karunathilake

If you’ve been following this thread, you know that we’re trying to find the reason of the crash: as asked above, if you could please provide

  • The Linux distribution/version you’re using
  • The IDE and its version.
  • Same for Android SDK, Java JDK, Realm SDK, Expo, React Native, …
  • As many logs as possible, ideally trace logs, to understand what Realm is doing (even though it may not be too relevant).

Until we’re able to consistently reproduce the issue, and have the exact reason, we cannot suggest a workaround (or, better, provide a solution)

1 Like

Hi @Paolo_Manna

Sure I can provide the details

I am using
OS : windows 10 (19044.1766 build version)
IDE: Webstorm ( I don’t believe this actually matters)
Android API 30, Java 11.0.4, realm : 10.19.5, expo-dev-client: 1.2.1, react-native: 0.68.2

I have captured a bug report from the emulator, I hope that helps. I checked for traces but I could not find any.

Please find the bug report WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free
The bundle id of my testing app is (com.fitsmiles.app)

1 Like

Furthermore the following log is found when crashing the app

2022-08-16 22:38:58.948 21481-21599/com.fitsmiles.app A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 21599 (mqt_js), pid 21481 (m.fitsmiles.app)

Thanks Paolo, I agree it does appear to be an Android SDK or local Java related issue, I don’t have much experience at all with native development so I was unsure if it was Android-library specific or RealmDB/Expo related.

I will look at reinstalling my Android Studio and SDKs to see if that helps.
Here’s my system info

  • System: Kubuntu 20.04
  • IDE: PHPStorm 2022.2
  • SDKs: Android (33.0.2) (lower for older device coverage), Realm (10.19.5) Expo (44.0.6 originally, upgrading to 46.0.7 didn’t help) React Native (0.69.4)
  • Java: openjdk 11.0.16 2022-07-19
    I’ll try to gather more logs.

The default RealmDB template app uses Expo 44 with the locked RN 0.64.3 mind you though the problem persisted there.

1 Like

My dev environment:

  • OS: Zorin OS 16.1 (64 bit)
  • IDE: VS Code 1.69.2
  • Android SDK: API 33
  • JDK: openjdk version “11.0.12”
  • Realm SDK: 10.19.0
  • Expo: 44.0.6
  • React Native: 0.64.3

Trace didn’t work for me when I tried earlier (as suggested up thread)