Open tran-simon opened 9 months ago
It is hard to tell exactly but our best guess is that it is related to your ProGuard configuration. Please take a look at https://www.mongodb.com/docs/realm/sdk/react-native/install/#extend-android-proguard-configuration
I managed to get some more information on the issue
The line that caused the crash is name.toLowerCase()
when name
is a string that contains an accent "é" or an emoji (😀).
I can also cause a crash by using Intl.NumberFormat().format()
, similar to @FN-FAL113's issue #5393
I've spent some time investigating, and it seems like realm is responsible somehow.
As soon as a realm object listener fires, I can't use toLowerCase()
on strings with accents or emojis
const thing = realm?.objects('Thing')?.[0]
thing?.addListener(()=>{
console.log('CRASHES 😀'.toLowerCase());
})
It will crash for the rest of the lifetime of the app, no matter where the toLowerCase()
is
const [state, setState] = useState(false)
useEffect(() => {
const thing = realm?.objects('Thing')?.[0]
thing?.addListener(()=>{
setState(true)
})
}, []);
useEffect(() => {
if (state) {
console.log('2 CRASHES 😀'.toLowerCase());
}
}, [state]);
If I use toLowerCase()
before the listener fires, it will not crash anywhere else
const [state, setState] = useState(false)
useEffect(() => {
console.log('PREVENT CRASH 😀'.toLowerCase());
}, []);
useEffect(() => {
const thing = PreferenceRealm.realm?.objects(Preferences.schema.name)?.[0]
thing?.addListener(()=>{
console.log('DOES NOT CRASH 😀'.toLowerCase());
setState(true)
})
}, []);
useEffect(() => {
if (state) {
console.log('DOES NOT CRASH 😀'.toLowerCase());
}
}, [state]);
It might be related to atlas device sync? In my original app, I could not make it crash if I did a new Realm.open()
with no sync configs.
const defaultConfig = {
path: 'synced-realm',
schema: [Thing],
sync: {
user: realmUser,
partitionValue: realmUser.id,
clientReset: {
mode: Realm.ClientResetMode.RecoverOrDiscardUnsyncedChanges,
onRecovery: () => {
return;
},
onDiscard: () => {
console.warn('Discarding unsynced changes.');
},
onFallback: onSyncedFallback,
},
},
}
// This will cause the crash later when we call `toLowerCase()`
const { ...config } = defaultConfig;
const realm = await Realm.open(config);
// This will *not* cause the crash later when we call `toLowerCase()`
const { sync, ...config } = defaultConfig;
const realm = await Realm.open(config);
I tried to create a new project with the same dependencies, but could not manage to make it crash. I did not try to enable sync.
I added these lines at the top of my index.js
'é'.toLowerCase();
Intl.NumberFormat().format(0)
This seems to prevent the crash everywhere else
Hopefully this can help
We are running into similar issues in our app. We recently switched to using @realm/react
for one of the screens and some of the users are facing the following crashes. This is happening on Android only.
java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
at toLocaleString (native)
at [redacted] (address at index.android.bundle:1)
at [redacted] (address at index.android.bundle:1)
at renderWithHooks (address at index.android.bundle:1)
at beginWork$1 (address at index.android.bundle:1)
at performUnitOfWork (address at index.android.bundle:1)
at workLoopSync (address at index.android.bundle:1)
at renderRootSync (address at index.android.bundle:1)
at performSyncWorkOnRoot (address at index.android.bundle:1)
at flushSyncCallbacks (address at index.android.bundle:1)
at scheduleUpdateOnFiber (address at index.android.bundle:1)
at dispatchReducerAction (address at index.android.bundle:1)
at listenerCallback (address at index.android.bundle:1)
at anonymous (address at index.android.bundle:1)
We temporarily fixed the issue by using a custom function to format numbers. We don't have any clue why this is happening. The code was working fine before introducing @realm/react
to make the screen reactive.
I just ran into a similar problem with a similar fix (happening in my dev and prod builds). Specifically relating to https://github.com/realm/realm-js/issues/5393 as it works again every time once the app reloads. One difference is that just calling create() didn't cause the app to crash, but nesting create() calls (adding the objects that just have the text "(Exception)" to another new realm object.
const item = realm.create(ItemRealm, {...}, Realm.UpdateMode.Modified) // console logs will show "(Exception)" on each attribute
const container = realm.create(ContainerRealm, {..., item: item, ...}, Realm.UpdateMode.Modified) // this line is what kills the app
My use case is calling the useQuery hook to return a list of realms followed by a useMemo which sorts them using a.localCompare(b) and similar to others adding "a".localCompare("b") to my index fixes the issue. It took me longer to find the issue as my logs never actually mention the localCompare anywhere.
const useMyItems = (id: number) => {
const _items = useQuery(
ItemRealm,
() => collection.filtered("parentId = $0", id),
[id]
)
// this is what kills the app
return useMemo(() => {
return _items.map((item) => nonRealmItem(item)).sort((a,b) => .... a.name.localCompare(b,name) ....)
}, [_items])
}
08-28 13:41:23.076 12969 13338 E ReactNativeJS: RangeError: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
08-28 13:41:23.076 12969 13338 E ReactNativeJS:
08-28 13:41:23.076 12969 13338 E ReactNativeJS: This error is located at:
08-28 13:41:23.076 12969 13338 E ReactNativeJS: in Unknown (created by CellRenderer)
08-28 13:41:23.076 12969 13338 E ReactNativeJS: in RCTView (created by View)
08-28 13:41:23.076 12969 13338 E ReactNativeJS: in View
08-28 13:41:23.076 12969 13338 E ReactNativeJS: in Unknown (created by TouchableOpacity)
08-28 13:41:23.076 12969 13338 E ReactNativeJS: in TouchableOpacity (created by TouchableOpacity)
08-28 13:41:23.076 12969 13338 E ReactNativeJS: in TouchableOpacity (created by CellRenderer)
08-28 13:41:23.076 12969 13338 E ReactNativeJS: in RCTView (created by View)
08-28 13:41:23.076 12969 13338 E ReactNativeJS: in View (created by CellRenderer)
08-28 13:41:23.076 12969 13338 E ReactNativeJS: in RCTView (created by View)
08-28 13:41:23.076 12969 13338 E ReactNativeJS: in View (created by CellRenderer)
08-28 13:41:23.076 12969 13338 E ReactNativeJS: in VirtualizedListCellContextProvider (created by CellRenderer)
08-28 13:41:23.076 12969 13338 E ReactNativeJS: in CellRenderer (created by VirtualizedList)
08-28 13:41:23.076 12969 13338 E ReactNativeJS: in RCTView (created by View)
08-28 13:41:23.076 12969 13338 E ReactNativeJS: in View (created by ScrollView)
08-28 13:41:23.076 12969 13338 E ReactNativeJS: in RCTScrollView (created by ScrollView)
08-28 13:41:23.076 12969 13338 E ReactNativeJS: in AndroidSwipeRefreshLayout (created by RefreshControl)
some values from my package.json that might be relevant based on other posts
"@react-navigation/native": "^6.1.18",
"@react-navigation/native-stack": "^6.11.0",
"expo": "^49.0.0",
"react-native": "0.72.10",
"react-native-gesture-handler": "~2.12.0",
"react-native-reanimated": "~3.5.4",
"react-native-screens": "~3.22.0",
"@realm/react": "^0.6.2",
"realm": "^11.10.2",
How frequently does the bug occur?
Once
Description
Crash happens only in production on one device. We do not have access to the device and could not reproduce on our personnal devices, but we asked the person to reinstall our app and they still get the same crash as soon as they open the app and Realm finishes syncing.
Relevant package versions:
nativereanimatednavigation/bottomtabsnavigation/nativestacknativevector-iconsWe are not using @realm-react
The issue seems similar to #5393, but @FN-FAL113 's fix is not applicable for us (we never use "new Intl.NumberFormat(...)")
Stacktrace & log output
Can you reproduce the bug?
No
Reproduction Steps
No response
Version
11.3.1
What services are you using?
Both Atlas Device Sync and Atlas App Services
Are you using encryption?
No
Platform OS and version(s)
Android 13 (SDK 33)
Build environment
Release version on the play store running on a samsung phone
Cocoapods version
No response