'MongoDB Realm React Native SDK with Expo - Missing Realm Constructor error

According to the latest documentation for MongoDB Realm React Native, it states that their SDK is compatible with Expo...

Expo now supports Realm with the Expo SDK version 44. To use Realm with Expo, upgrade to Expo SDK version 44. Realm does not work with earlier versions of Expo.

We have installed Expo and have the latest version of their SDK, however no matter what we try we get an error stating "Missing Ream Constructor":

enter image description here

We require the project to be in the Expo managed workflow and not the bare workflow. When we setup in bare workflow, it works.

Are we missing something??



Solution 1:[1]

Some of the settings I made to fix:

REMEMBER: react-native-reanimated doesn't work with Realm & Expo

Following the documentation

  • Rather than run with expo start or npx react-native [platform] run yarn android for iOS or yarn ios
  • Install Java SDK version 8
  • Uninstall react-native: npm uninstall -g react-native and run npx react-native run-android

If you got this error:

A problem occurred configuring project ':realm'.

Could not create task ':realm:compileDebugJavaWithJavac'. Could not create task ':realm:forwardDebugPort'. > SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at 'C:\Users\yourUser\Desktop\Projects\MyAwesomeRealmApp\android\local.properties'. `

To fix this:

  • Create a file with the name local.properties in android directory
  • Open the file and paste your Android SDK path like below: sdk.dir=C:\\Users\\UserName\\AppData\\Local\\Android\\sdk

Solution 2:[2]

You can make a new array ($tab2) and loop through the previous array ($tab) and add the piece of text ($value) per value.

<?php

$tab = ['10', '11', '12', '12','14'];
$tab2 = [];

$value = '4a';

for ($i = 0; $i < count($tab); $i++) {
    array_push($tab2, $tab[$i] . $value);
}

The output will look like this:

$tab2 = ['104a', '114a', '124a', '124a', '144a'];

It is also possible to change the existing array. It has the same output.

<?php

$tab = ['10', '11', '12', '12','14'];

$value = '4a';

for ($i = 0; $i < count($tab); $i++) {
    $tab[$i] = $tab[$i] . $value;
}

Solution 3:[3]

You can add value to array like this.

$tab[] = "4a";

or array_push($tab, "4a");

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 Wang YinXing