远程调试已终止与理由:连接丢失(Remote Debugging has been terminat

2019-10-29 09:51发布

我正在连接丢失的错误,当尝试,看看境界数据库。 这里就是我如何initalizing stetho和境界。 我仍然得到这个错误。 我甚至已经把withDeleteIfMigrationNeeded(真)。 仍然没有奏效。

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();
        }
    }
}

这是我的依赖关系:

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

Answer 1:

你缺少该领域的加密密钥。

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();


文章来源: Remote Debugging has been terminated with reason: Connection lost