Back to Realm Java

Debugging - Java SDK

docs/guides/test-and-debug/debugging.md

10.19.01.9 KB
Original Source

Debugging - Java SDK

Android Studio Debugging

Important: The Android Studio debugger can provide misleading values for Realm object fields. For correct values, you can watch accessor values instead, or use the Realm object toString() method to see the latest field values.

This section details information you should keep in mind when debugging Realm applications with Android Studio to avoid incorrect value reporting. When you watch a Realm object, you'll see values displayed in the object's fields. These values are incorrect because the field values themselves are not used. This is because Realm creates a proxy object behind the scenes, overriding the getters and setters to access the persisted data in the realm. To see the correct values, add a watch on the accessors.

In the image above, the debugger has stopped on line 113. There are three watch values:

  • The person variable
  • The person.getName() accessor
  • The person.getAge() accessor

The code from lines 107 to 111 alters the person instance by changing the name and age in a write transaction. On line 113, the person watch instance reports incorrect values for the field watch values. The watch values that use the accessors report values that are correct.

NDK Debugging

The Realm Java SDK library contains native code. Debugging NDK crashes can be cumbersome, as the default stack trace provides minimal information.

We recommend you use a crash reporting tool such as Crashlytics. This gives you the ability to track native errors and gather other valuable information. We can help with your issues faster if you have this information.

To enable NDK crash reporting in Crashlytics for your project, add the following to the root of your application build.gradle file:

groovy
crashlytics {
   enableNdk true
}

Note: The values androidNdkOut and androidNdkLibsOut are not needed.