【问题标题】:Remote Debugging has been terminated with reason: Connection lost远程调试已终止,原因是:连接丢失
【发布时间】:2019-05-02 17:02:41
【问题描述】:

我在尝试查看领域数据库时遇到连接丢失错误。这就是我如何初始化 stetho 和领域。我仍然收到此错误。我什至放了 withDeleteIfMigrationNeeded(true)。仍然没有工作。

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"

【问题讨论】:

    标签: android realm stetho


    【解决方案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();
    

    【讨论】:

      猜你喜欢
      • 2017-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-10
      • 2017-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多