Remote Debugging has been terminated with reason: Connection lost

↘锁芯ラ 提交于 2020-01-16 08:03:52

问题


I am getting connection lost error, when try to see the realm database. here's how i am initalizing stetho and realm. i am still getting this error. I have even put withDeleteIfMigrationNeeded( true ). still didn't work.

public class ApplicationClass extends Application {

    //  Database Name...
    private static final String DB_NAME = "Cheruvu.realm";

    @Override
    public void onCreate() {
        super.onCreate();
        configureRealm();
    }

    private void configureRealm() {

        Realm.init( this );

        RealmInspectorModulesProvider realmInspectorModulesProvider = RealmInspectorModulesProvider.builder(this)
                  .withDeleteIfMigrationNeeded(true)
                  .build();

        Stetho.initialize(
                Stetho.newInitializerBuilder( this )
                        .enableDumpapp( Stetho.defaultDumperPluginsProvider( this ) )
                        .enableWebKitInspector( realmInspectorModulesProvider )
                        .build() );

        RealmConfiguration config = new RealmConfiguration.Builder()
                .name( DB_NAME )
                .deleteRealmIfMigrationNeeded()
                .encryptionKey( generateSecurityKey() )
                .build();

        Realm.deleteRealm( config );

        Realm.setDefaultConfiguration( config );
    }

   private byte[] generateSecurityKey() {
        ByteBuffer bb = ByteBuffer.wrap( new byte[64] );
        bb.putInt( UUID.randomUUID().hashCode() );
        return bb.array();
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        Realm realm = Realm.getDefaultInstance();
        if (!realm.isClosed()) {
            Realm.getDefaultInstance().close();
        }
    }
}

this is my dependencies :

//  stetho for database lookup
implementation "com.uphyca:stetho_realm:2.3.0"
implementation "com.facebook.stetho:stetho:1.5.0"

回答1:


You are missing the encryption key for the Realm.

String securityKey = generateSecurityKey();

    RealmInspectorModulesProvider realmInspectorModulesProvider = RealmInspectorModulesProvider.builder(this)
              .withDeleteIfMigrationNeeded(true)
              .withEncryptionKey(DB_NAME, securityKey)
              .build();

    Stetho.initialize(
            Stetho.newInitializerBuilder( this )
                    .enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
                    .enableWebKitInspector( realmInspectorModulesProvider )
                    .build());

    RealmConfiguration config = new RealmConfiguration.Builder()
            .name( DB_NAME )
            .deleteRealmIfMigrationNeeded()
            .encryptionKey(securityKey)
            .build();


来源:https://stackoverflow.com/questions/55957151/remote-debugging-has-been-terminated-with-reason-connection-lost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!