Realm-java: Not a Realm file and Native exception

Created on 13 Feb 2017  ·  34Comments  ·  Source: realm/realm-java

Hi,
My crash report keeps receiving these exceptions from some users.
But it never happened on my test device or emulator.
What is the possible cause?

Here's how I write data to Realm:

realm.executeTransactionAsync(new Realm.Transaction() {
            @Override
            public void execute(Realm realm) {
                autoIncrement ++;
                MyRealmObject data = realm.createObject(MyRealmObject.class, id);
                data.setContent( gson.toJson( myData ) ); // String, length range: 7000 ~ 60000
                data.setPage( page ); // int
            }
        });

Here's how I read data from Realm:

RealmQuery<MyRealmObject> query = realm.where(MyRealmObject.class);
query.findAllSorted( MyRealmObject.PAGE, Sort.ASCENDING );

It looks like the user has to remove the app or clear all data to make realm works again.
Is this means the Realm database is crashed?

Firebase Crash Report:

Exception java.lang.RuntimeException: Unable to create application com.ihad.ptt.App: io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/com.ihad.ptt/files/default.realm': Not a Realm file. (Not a Realm file) in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 87 Kind: ACCESS_ERROR.
android.app.ActivityThread.handleBindApplication (ActivityThread.java:5665)
android.app.ActivityThread.-wrap2 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1573)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:173)
android.app.ActivityThread.main (ActivityThread.java:6459)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:938)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:828)
arrow_drop_down
Caused by io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/com.ihad.ptt/files/default.realm': Not a Realm file. (Not a Realm file) in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 87
io.realm.internal.SharedRealm.nativeGetSharedRealm (SharedRealm.java)
io.realm.internal.SharedRealm.getInstance (SharedRealm.java:208)
io.realm.internal.SharedRealm.getInstance (SharedRealm.java:186)
io.realm.BaseRealm.compactRealm (BaseRealm.java:586)
io.realm.Realm.compactRealm (Realm.java:1565)
com.ihad.ptt.domain.dao.realm.impl.RealmMigration.init (RealmMigration.java:29)
com.ihad.ptt.App.onCreate (App.java:95)
android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1037)
android.app.ActivityThread.handleBindApplication (ActivityThread.java:5662)
android.app.ActivityThread.-wrap2 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1573)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:173)
android.app.ActivityThread.main (ActivityThread.java:6459)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:938)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:828)

Native Exception:


Build fingerprint: 'htc/pmeuhl_00709/htc_pmeuhl:6.0.1/MMB29M/801953.5:user/release-keys'
Revision: '0'
ABI: 'arm64'
pid: 13207, tid: 13207, name: com.ihad.ptt >>> com.ihad.ptt <<<
signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x7f62978008
x0 0000000000000000 x1 0000007f62908ca0 x2 0000000000000008 x3 0000000000014b00
x4 0000000000ffffff x5 000000000000003f x6 0000000000000040 x7 0000007f62978008
x8 000000000000006d x9 0000000000000000 x10 0000000000000000 x11 0000000000000040
x12 0000000000000010 x13 0000007f84b37a90 x14 000000559a211000 x15 0000007f84b37ad8
x16 0000007f84b30a58 x17 0000000000000000 x18 0000000000000001 x19 000000559a563900
x20 0000000000000000 x21 0000007fdafd3230 x22 0000007fdafd3540 x23 000000559a5634f0
x24 0000007fdafd3640 x25 0000007f62995000 x26 000000559a563700 x27 0000007fdafd3440
x28 000000559a563710 x29 0000007fdafd3160 x30 0000007f627f87d8
sp 0000007fdafd3160 pc 0000007f627b346c pstate 0000000020000000

backtrace:

00 pc 00000000000e746c /data/app/com.ihad.ptt-1/lib/arm64/librealm-jni.so

01 pc 000000000012c7d4 /data/app/com.ihad.ptt-1/lib/arm64/librealm-jni.so

02 pc 00000000000a530c /data/app/com.ihad.ptt-1/lib/arm64/librealm-jni.so

03 pc 00000000000be754 /data/app/com.ihad.ptt-1/lib/arm64/librealm-jni.so

04 pc 00000000000c26ec /data/app/com.ihad.ptt-1/lib/arm64/librealm-jni.so

05 pc 00000000000bbcd0 /data/app/com.ihad.ptt-1/lib/arm64/librealm-jni.so

06 pc 000000000004d2c0 /data/app/com.ihad.ptt-1/lib/arm64/librealm-jni.so (Java_io_realm_internal_SharedRealm_nativeGetSharedRealm+384)

07 pc 000000000220c74c /data/app/com.ihad.ptt-1/oat/arm64/base.odex (offset 0x1051000)

Version of Realm and tooling

Realm version(s): 2.2.2

Realm sync feature enabled: no

Android Studio version: IntelliJ IDEA 2016.3.4

Which Android version and device: Android 6.0 HTC 10

O-Community Pipeline-On-Hold Reproduction-Required T-Bug-Crash

Most helpful comment

@MariusBoepple is the Realm encrypted in your case?

All 34 comments

Did you use encryption?

No, I don't.
Forgot the realm configuration.

Realm.init( context ); // ApplicationContext
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder()
    .schemaVersion( REALM_DATABASE_VERSION ) // Must be bumped when the schema changes
    .migration( this ) // Migration to run instead of throwing an exception
    .build();
Realm.compactRealm( realmConfiguration );
Realm.setDefaultConfiguration(realmConfiguration);

Might be the same problem with compactRealm. Checking ...

It is possible to test the fix by using the 2.4.0-SNAPSHOT.

Thanks!
I'll wait for the release version.

@KimiChiu The release is supposed to come out soon. If it doesn't solved your issue, don't hesitate to either reopen or create new issue.

Hi,
I'm now using Realm 3.0.0 but still receiving these errors.

Exception java.lang.RuntimeException: Unable to create application com.ihad.ptt.App: io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/com.ihad.ptt/files/default.realm': Bad Realm file header (#1). (Bad Realm file header (#1)) (/data/data/com.ihad.ptt/files/default.realm) in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 109 Kind: ACCESS_ERROR.
android.app.ActivityThread.handleBindApplication (ActivityThread.java:4664)
android.app.ActivityThread.access$1500 (ActivityThread.java:156)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1412)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:211)
android.app.ActivityThread.main (ActivityThread.java:5373)
java.lang.reflect.Method.invoke (Method.java)
java.lang.reflect.Method.invoke (Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1020)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:815)

Caused by io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/com.ihad.ptt/files/default.realm': Bad Realm file header (#1). (Bad Realm file header (#1)) (/data/data/com.ihad.ptt/files/default.realm) in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 109
io.realm.internal.SharedRealm.nativeGetSharedRealm (SharedRealm.java)
io.realm.internal.SharedRealm. (SharedRealm.java:187)
io.realm.internal.SharedRealm.getInstance (SharedRealm.java:229)
io.realm.internal.SharedRealm.getInstance (SharedRealm.java:204)
io.realm.BaseRealm.compactRealm (BaseRealm.java:574)
io.realm.Realm.compactRealm (Realm.java:1627)
com.ihad.ptt.domain.dao.realm.impl.RealmMigration.init (RealmMigration.java:29)
com.ihad.ptt.App.onCreate (App.java:97)
android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1012)
android.app.ActivityThread.handleBindApplication (ActivityThread.java:4661)
android.app.ActivityThread.access$1500 (ActivityThread.java:156)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1412)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:211)
android.app.ActivityThread.main (ActivityThread.java:5373)
java.lang.reflect.Method.invoke (Method.java)
java.lang.reflect.Method.invoke (Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1020)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:815)

Another one:

Exception io.realm.exceptions.RealmError: Unrecoverable error. Permission denied in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 109
io.realm.internal.SharedRealm.nativeGetSharedRealm (SharedRealm.java)
io.realm.internal.SharedRealm. (SharedRealm.java:187)
io.realm.internal.SharedRealm.getInstance (SharedRealm.java:229)
io.realm.internal.SharedRealm.getInstance (SharedRealm.java:204)
io.realm.BaseRealm.compactRealm (BaseRealm.java:574)
io.realm.Realm.compactRealm (Realm.java:1627)
com.ihad.ptt.domain.dao.realm.impl.RealmMigration.init (RealmMigration.java:29)
com.ihad.ptt.App.onCreate (App.java:97)
android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1015)
android.app.ActivityThread.handleBindApplication (ActivityThread.java:4786)
android.app.ActivityThread.access$1600 (ActivityThread.java:165)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1430)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:150)
android.app.ActivityThread.main (ActivityThread.java:5546)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:792)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:682)

I just remembered that I have another problem before and it's not solved.
That is sometimes the realm initialization is ignored in my Application's onCreate.
So I have to check if it's needed to initialize it again in the Activity's onCreate.

protected RealmHelper getRealmHelper() {
  if (realmHelper == null) {
  realmHelper = RealmHelper.getInstance();
  }

  try {
  if (realm == null) {
  realm = Realm.getDefaultInstance();
  }
  }
  // while Realm.init failed in Application's onCreate
  catch ( IllegalStateException e ){
  new RealmMigration().init(getApplicationContext());
  realm = Realm.getDefaultInstance();
  }

  return realmHelper;
}

The RealmHelper is a singleton class which holds all the instances of the realm operation classes.

Is it caused by the user restores application data by them self?

<application
            android:name=".App"
            android:allowBackup="true"
            android:allowClearUserData="true"
            android:allowTaskReparenting="false"
            android:hardwareAccelerated="true"
            android:icon="@mipmap/ic_launcher_mr"
            android:label="@string/app_name"
            android:largeHeap="true"
            android:theme="@style/AppTheme">
    ...
</application>

Should I just add a try-catch to prevent my application crash?

Version of Realm and tooling

Realm version(s): 3.0.0

Realm sync feature enabled: no

Android Studio version: IntelliJ IDEA 2016.3.4

Which Android version and device:
API 23 HTC 10
API 22 Sony D6503
API 23 HUAWEI GEM-702L
API 23 HTC HTC_M8x

  1. Are you sure the below exception still happens to realm-java 3.0.0? Since it should be fixed. See #4140

Exception io.realm.exceptions.RealmError: Unrecoverable error. Permission denied in
/Users/cm/Realm/realm-java/realm/realm-library
...
/src/mainio.realm.BaseRealm.compactRealm (BaseRealm.java:574)

  1. Can you please share the source code of com.ihad.ptt.domain.dao.realm.impl.RealmMigration.init?

  2. Are you using multi-processes in your app?

  1. Yes, it still happens. Is it possible that it's a legacy from the previous version?

  2. Here's the RealmMIgration.

import android.content.Context;
import com.ihad.ptt.domain.entity.realm.Message;
import com.ihad.ptt.domain.entity.realm.NewTopicCache;
import com.ihad.ptt.domain.entity.realm.People;
import com.ihad.ptt.domain.entity.realm.UserPreference;
import io.realm.*;

import java.util.Date;

public class RealmMigration implements io.realm.RealmMigration {

  // realm 資料庫當前版本
  public static final int REALM_DATABASE_VERSION = 9;

  /**
  * Call this in the UI Thread
  * @param context
  */
  public void init(Context context){
  Realm.init( context );
  RealmConfiguration realmConfiguration = new RealmConfiguration.Builder()
  .schemaVersion( REALM_DATABASE_VERSION ) // Must be bumped when the schema changes
  .migration( this ) // Migration to run instead of throwing an exception
// .deleteRealmIfMigrationNeeded()
  .build();

  Realm.compactRealm( realmConfiguration );

  Realm.setDefaultConfiguration(realmConfiguration);
  }

  @Override
  public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
  // DynamicRealm exposes an editable schema
  RealmSchema schema = realm.getSchema();

  // Migrate to version 1: Add a new class.
  // Example:
  // public Person extends RealmObject {
  // private String name;
  // private int age;
  // // getters and setters left out for brevity
  // }
  if (oldVersion == 2) {
  schema.create( UserPreference.TABLE )
  .addField( UserPreference.PRIMARY_KEY, int.class, FieldAttribute.PRIMARY_KEY )
  .addField( UserPreference.NAME , String.class )
  .addField( UserPreference.VALUE, String.class )
  .addField( UserPreference.ENCRYPTED, boolean.class )
  .addField( UserPreference.OWNER, String.class )
  .addField( UserPreference.CREATED_DATE, Date.class )
  .addField( UserPreference.LAST_UPDATE_DATE, Date.class );
  oldVersion++;
  }

  if (oldVersion == 3) {
  schema.create( NewTopicCache.TABLE )
  .addField( NewTopicCache.PRIMARY_KEY, int.class, FieldAttribute.PRIMARY_KEY )
  .addField( NewTopicCache.JSON , String.class );
  oldVersion++;
  oldVersion++;
  }

  if (oldVersion == 5) {
  schema.create( People.TABLE )
  .addField( People.PRIMARY_KEY, int.class, FieldAttribute.PRIMARY_KEY )
  .addField( People.LAST_UPDATE_DATE , long.class )
  .addField( People.USERNAME , String.class )
  .addField( People.NICKNAME , String.class )
  .addField( People.LAST_MESSAGE , String.class );
  oldVersion++;
  }

  if (oldVersion == 6) {
  schema.get( People.TABLE )
  .addField( People.UNREAD_MESSAGES, int.class);
  oldVersion++;
  }

  if (oldVersion == 7) {
  schema.get( People.TABLE )
  .addField( People.OWNER, String.class);
  oldVersion++;
  }

  if (oldVersion == 8) {
  schema.create( Message.TABLE )
  .addField( Message.PRIMARY_KEY, int.class, FieldAttribute.PRIMARY_KEY )
  .addField( Message.CREATED_DATE , Date.class )
  .addField( Message.PEOPLE_ID , int.class )
  .addField( Message.MESSAGE , String.class )
  .addField( Message.MINE , boolean.class )
  .addField( Message.READ_OR_SENT , boolean.class );
  oldVersion++;
  }

  // Migrate to version 2: Add a primary key + object references
  // Example:
  // public Person extends RealmObject {
  // private String name;
  // @PrimaryKey
  // private int age;
  // private Dog favoriteDog;
  // private RealmList<Dog> dogs;
  // // getters and setters left out for brevity
  // }
// if (oldVersion == 1) {
// schema.get("Person")
// .addField("id", long.class, FieldAttribute.PRIMARY_KEY)
// .addRealmObjectField("favoriteDog", schema.get("Dog"))
// .addRealmListField("dogs", schema.get("Dog"));
// oldVersion++;
// }
}
  1. I have a thread handles messaging.
    The instance is created from the MainActivity, but stored in a Service.
    So the user can still receive messages even the Activity has been killed.
    And it uses a Handler to communicate with the main thread.

Add to queue in another thread.

private void sendServiceMessage(int msg){
        if( serviceHandler == null ){
            Timber.i("ServiceHandler is null");
            return;
        }

        MessageBean messageBean = MessageBean.Builder.aMessageBean()
                .withMessage( message.clone() )
                .build();

        Message message = new Message();
        message.what = waterPoloNotification;
        message.obj = messageBean;

        serviceHandler.sendMessage(message);
}

The handler in Service.

private static class ThreadHandler extends Handler {

        private WeakReference<Service> refService;

        public ThreadHandler(Service service) {
            refService = new WeakReference<>(service);
        }

        @Override
        public void handleMessage(Message message) {
            if (refService == null) return;

            Service service = refService.get();

            if (service == null || service.isRestricted() ) return;

            MessageBean messageBean = (MessageBean) message.obj;
            messageBean.setPending(false);

            switch (message.what) {
                ...
                case waterPoloNotification:
                    service.waterPoloNotification(messageBean);
                    break;
                ...
            }

            messageBean.release();
        }
}

Then it'll write the message to Realm database and show the notification.

private void waterPoloNotification(MessageBean messageBean){
        String owner = getUsername();
        if( owner.isEmpty() ) return;

        WaterPoloBean waterPoloBean = messageBean.getMessage();

        switch ( waterPoloBean.getWaterPoloType().getValue() ){
            case WaterPoloType._ON_LINE:{
                onlineNotification( waterPoloBean.getUsername() );
                break;
            }

            case WaterPoloType._MESSAGE:{

                boolean chatting = isChatting( waterPoloBean.getUsername() );

                Realm realm = null;
                try{
                    realm = getRealm();

                    getRealmHelper().getMessageService(realm).insert( realm, owner, waterPoloBean.getUsername(),
                            waterPoloBean.getMessage(), chatting, false );
                }
                finally {
                    if( realm != null ){
                        realm.close();
                    }
                }

                if( !chatting ) {
                    messageNotification(waterPoloBean.getUsername(), waterPoloBean.getMessage());
                }
                break;
            }
        }
}

The getRealm().

protected Realm getRealm(){

        try {
            return Realm.getDefaultInstance();
        }
        // while Realm.init failed in Application's onCreate
        catch ( IllegalStateException e ){
            new RealmMigration().init( getApplicationContext() );

            return Realm.getDefaultInstance();
        }
}

Is your service running in another process? Means do you have something like android: process =":remote" in your manifest file?

No, I don't have android: process =":remote" in my manifest file.
But this service can use startForeground() if the user wants to.

<service
    android:name=".Service"
    android:exported="false"/>

Another service is for Firebase messaging, but it only uses SQLite.

<service android:name=".MessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>

allowBackup = true will enable the adb backup/restore. but I am wondering how many users will do that through adb. What kind of your app is? Is it targeted to developers? If you can share you apk somewhere, i can try to verify my hypothesis. You can send it to [email protected] if you want to share it privately.

I just released a new version with allowBackup = false in the AndroidManifest.xml.
This app is targeting to Taiwanese, it doesn't use i18n.
So it's hard to use for you, especially when you do the signup process.
If this new version still has this issue, I will write you a tutorial later to show you how to register on the site.(it has to be done on the PC and use the terminal).
Here's the Google Play link, maybe it can help you understand what it is:
https://play.google.com/store/apps/details?id=com.ihad.ptt&hl=zh_TW

@KimiChiu no worries, i can totally read traditional Chinese :P

That's awesome. Didn't see that coming.
So you can click the "想註冊?" on the login page to see the tutorial if you want to test it.
If you download the v3.6.1 then it's still using allowBackup = true.

Yes, I will try it and let you know the results.

I'm getting some native crashs, like the following. I'm using Realm in a remote service.

Native crash at /data/app/com.example.app-2/lib/arm64/librealm-jni.so
in /data/app/com.example.app-2/lib/arm64/librealm-jni.so, /data/app/com.example.app-2/lib/arm64/librealm-jni.so (Java_io_realm_internal_SharedRealm_nativeGetSharedRealm+400)

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'lge/p1_global_com/p1:6.0/MRA58K/1620215065b6f:user/release-keys'
Revision: '11'
ABI: 'arm64'
pid: 2459, tid: 2542, name: Worker  >>> com.example.app:remote <<<
signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x7f7e1f6008
    x0   0000000000000000  x1   0000007f7d6d00b0  x2   0000000000000008  x3   0000000000000780
    x4   0000000000ffffff  x5   000000000000003f  x6   0000000000000040  x7   0000007f7e1f6008
    x8   000000000000006d  x9   0000000000000000  x10  0000000000000000  x11  0000000000000040
    x12  0000007f9d833fc0  x13  0000000000000011  x14  0000000000000012  x15  000000000000008e
    x16  0000007f9d866010  x17  0000000000000000  x18  0000007f7e435860  x19  0000007f7cb31010
    x20  0000000000000000  x21  0000007f93de0fa0  x22  0000007f7cdff758  x23  0000000000000000
    x24  0000007f7d75e000  x25  0000007f7e183770  x26  0000007f7cdff910  x27  0000007f7cdff860
    x28  0000007f7cdff758  x29  0000007f7cdff5f0  x30  0000007f7d5bd108
    sp   0000007f7cdff5f0  pc   0000007f7d577e94  pstate 0000000020000000

backtrace:
    #00 pc 00000000000ede94  /data/app/com.example.app-2/lib/arm64/librealm-jni.so
    #01 pc 0000000000133104  /data/app/com.example.app-2/lib/arm64/librealm-jni.so
    #02 pc 00000000000acba4  /data/app/com.example.app-2/lib/arm64/librealm-jni.so
    #03 pc 00000000000c10f8  /data/app/com.example.app-2/lib/arm64/librealm-jni.so
    #04 pc 00000000000cee48  /data/app/com.example.app-2/lib/arm64/librealm-jni.so
    #05 pc 00000000000bf730  /data/app/com.example.app-2/lib/arm64/librealm-jni.so
    #06 pc 000000000004e4b8  /data/app/com.example.app-2/lib/arm64/librealm-jni.so (Java_io_realm_internal_SharedRealm_nativeGetSharedRealm+400)
    #07 pc 0000000001bfd3bc  /data/app/com.example.app-2/oat/arm64/base.odex (offset 0xe9c000)
Native crash at /data/app/com.example.app-1/lib/arm64/librealm-jni.so
in /data/app/com.example.app-1/lib/arm64/librealm-jni.so, /data/app/com.example.app-1/lib/arm64/librealm-jni.so (Java_io_realm_internal_UncheckedRow_nativeGetString+72)

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'samsung/zerofltexx/zeroflte:6.0.1/MMB29K/G920FXXS5DQA1:user/release-keys'
Revision: '11'
ABI: 'arm64'
pid: 5766, tid: 5776, name: Binder_1  >>> com.example.app:remote <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x69
    x0   0000000000000000  x1   0000000000000003  x2   0000000000000003  x3   0000000000000003
    x4   0000000000000000  x5   0000007f91dac1dc  x6   0000007fa94fa000  x7   0000007fa94fc9a0
    x8   0000000000000036  x9   0000007f9e6c95b0  x10  0000000000000000  x11  0000000000000036
    x12  0000000000000001  x13  0000000000000000  x14  0000007fa951a68c  x15  0000000000000000
    x16  0000007fa951a688  x17  0000000000000000  x18  0000007f9e6c9400  x19  0000007f91b0e0a0
    x20  0000007f8feea000  x21  0000000000000007  x22  0000000000000007  x23  0000000000000000
    x24  0000000013114880  x25  0000000058cbb66a  x26  000000001312ca80  x27  00000000131199e0
    x28  00000000131c3400  x29  0000007fa843f250  x30  0000007f91e29510
    sp   0000007fa843f250  pc   0000007f91cfc58c  pstate 0000000020000000

backtrace:
    #00 pc 000000000003958c  /data/app/com.example.app-1/lib/arm64/librealm-jni.so
    #01 pc 000000000016650c  /data/app/com.example.app-1/lib/arm64/librealm-jni.so
    #02 pc 000000000016656c  /data/app/com.example.app-1/lib/arm64/librealm-jni.so
    #03 pc 000000000009b188  /data/app/com.example.app-1/lib/arm64/librealm-jni.so (Java_io_realm_internal_UncheckedRow_nativeGetString+72)
    #04 pc 0000000001c75aac  /data/app/com.example.app-1/oat/arm64/base.odex (offset 0xed5000)
Native crash at /data/app/com.example.app-1/lib/arm64/librealm-jni.so
in /data/app/com.example.app-1/lib/arm64/librealm-jni.so, /data/app/com.example.app-1/lib/arm64/librealm-jni.so (Java_io_realm_internal_SharedRealm_nativeCommitTransaction+76)

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'samsung/hero2ltexx/hero2lte:6.0.1/MMB29K/G935FXXU1BPLL:user/release-keys'
Revision: '9'
ABI: 'arm64'
pid: 13350, tid: 18058, name: SyncAdapterThre  >>> com.example.app:remote <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x7f34b0a623
    x0   0000007f866562d0  x1   0000007f6e17ea60  x2   0000000000000001  x3   0000000000057fb8
    x4   0000007f6de7a684  x5   0000000000000000  x6   0000007f6cf1d018  x7   0000000000000000
    x8   0000000007f81768  x9   0000007f6dfdec10  x10  0000007f6dfde410  x11  0000007f6dfde810
    x12  00000000000000ac  x13  000000000000000e  x14  00000000000000dc  x15  0000000000000073
    x16  0000007f6e065860  x17  0000000000000000  x18  00000000000000d4  x19  0000007f34b0a61f
    x20  0000007f866562d0  x21  0000007f6e17ea60  x22  0000007f6cf285e8  x23  0000007f6cf1e000
    x24  0000007f6cf1d018  x25  0000000000019a05  x26  000000003301b370  x27  000000003328af40
    x28  000000003330ea20  x29  0000007f6e17ea00  x30  0000007f6de846c8
    sp   0000007f6e17ea00  pc   0000007f6de82624  pstate 0000000080000000

backtrace:
    #00 pc 00000000000f1624  /data/app/com.example.app-1/lib/arm64/librealm-jni.so
    #01 pc 00000000000f36c4  /data/app/com.example.app-1/lib/arm64/librealm-jni.so
    #02 pc 000000000016f92c  /data/app/com.example.app-1/lib/arm64/librealm-jni.so
    #03 pc 000000000012bd20  /data/app/com.example.app-1/lib/arm64/librealm-jni.so
    #04 pc 00000000000cb454  /data/app/com.example.app-1/lib/arm64/librealm-jni.so
    #05 pc 00000000000be8dc  /data/app/com.example.app-1/lib/arm64/librealm-jni.so
    #06 pc 000000000004a80c  /data/app/com.example.app-1/lib/arm64/librealm-jni.so (Java_io_realm_internal_SharedRealm_nativeCommitTransaction+76)
    #07 pc 00000000019dcef0  /data/app/com.example.app-1/oat/arm64/base.odex (offset 0xed5000)

Realm version: 2.3.0

@MariusBoepple is the Realm encrypted in your case?

Yes, it's encrypted.

@MariusBoepple Realm 2.3.2 fixed an issue in Realm-Core related to multi-thread / multi-process access of encrypted Realms

Encrypted realms can end up corrupted if many threads are reading and writing at the same time (#4128).

And Realm-Core also fixed https://github.com/realm/realm-core/pull/2426 (another similar issue)

Yes, as @Zhuinden said, please update to 2.3.2 , it should solve most encryption related crashes.

However, there is a new crash related with encryption reported #4343 and we are working on it.

It looks like this problem still not be solved.
The apk with allowBackup = false has been released for a week.
And I'm still receiving this error report from new devices.
Sony D2533 API 21
Sony D6653 API 23
But it rarely happens, only three different devices report this issue in this version.
Maybe there's someone trying to do something on a rooted device?
Because one of them sent 39 reports in 3 hours.

@KimiChiu What is the device reports 39 crashes in 3 hours?

It's a Sony D6653 API 23.

@KimiChiu I have played your apk with my Xiaomi Mi5 for a while, but still not able to reproduce the issue :(
Can you see what is the rom version of Sony D6653 which reports this problem?
How is the recent crash rate about this issue? I doubt #4140 could be related with this which is fixed in v2.3.2. Also please be noticed, if this is caused by a corrupted db file, updating will not fix it unless user clear the data cache (to delete the corrupted db file).

No, Firebase Crash didn't include the rom version.
The crash rate is always under 0.1%.
9 users report these crashes in 7 days and 23 in 30 days.
I got several reports from two devices recently, Samsung SM-N910U API 23 and Asus ASUS_T00J API 19.
But there's no any user contact to me directly, so I'm not sure whether they have these issues before.
However, I just found that these devices did report these crashes from the previous versions.
Maybe you are right, it is caused by a corrupted database.

This is exactly my case #2984 . Crash reported in less than .1% cases. 13 crashes today out of 19.8K sessions.
Also, the line number is different based on realm versions. The one with line 217 is with realm 3.1.2.

  1. /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 109 Kind: ACCESS_ERROR.

  2. Bad Realm file header (#3). in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 92 Kind: ACCESS_ERROR.

  3. Bad Realm file header (#3). (Bad Realm file header (#3)) (/data/data/com.conem.app.pocketthesaurus/files/dictionary.realm) in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 217 Kind: ACCESS_ERROR.

  4. Bad Realm file header (#3). in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 81

Same crash through ages 😲. I still don't know how to resolve it 😞.

Any updates for this issue?

@hmedat2008 many, so it depends on your Realm version and whether your Realm is encrypted or not and whether you compact Realm

Realm Version: 4.2.0
Realm is encrypted: No

I also encountered the same problem in Realm 5.1.0
stacktrace 2018-05-29 05-32 (UTC).log

Сonfiguration:

new RealmConfiguration
                .Builder()
                .name(realmName)
                .schemaVersion(Constants.DB_VERSION)
                .directory(dbDir)
                .encryptionKey(key)
                .migration(MIGRATION)
                .initialData(INIT_REALM_TX)
                .build();

I use several threads to access the database.

What's weird is that i've heard that someone wrapping getInstance() call with synchronized(LOCK) could fix the problem

But that is just heresay I heard like 1.5 years ago

Closing due to being outdated. The underlying code has changed quite a lot by now. If this is still a problem feel free to re-open.

Was this page helpful?
0 / 5 - 0 ratings