Reputation: 1005
I have main android project that uses another android module. In main android project am getting real instance with some configuration like as.
realm = Realm.getInstance(someConfig());
Am initing Realm from main app Application class, as follows
Realm.init(Context);
In my module when I try to call following line it shows error.
Realm db = Realm.getDefaultInstance();
Error:
error Wrong key used to decrypt Realm.
W/System.err:
java.lang.IllegalArgumentException: Wrong key used to decrypt Realm.
Upvotes: 0
Views: 261
Reputation: 173
Add below code to parent class which extends Application/MutlidexApplication class or where ur intializing Realm:
Realm.init(Parent.this);
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder()
.name(AppConstants.DATABASE_NAME)
.schemaVersion(2)
// .migration(new DBMigration())
// .migration(new Migration())
.deleteRealmIfMigrationNeeded()
.build();
Realm.setDefaultConfiguration(realmConfiguration);
Realm.getInstance(realmConfiguration);
Upvotes: 1
Reputation: 81539
1.) I genuinely think that a library that relies on having its own RealmConfiguration to be set as the "default configuration" is heavily intrusive. So library code should use Realm.getInstance(configuration)
.
2.) If you want the configurations to refer to different files, you might want to set a different name using new RealmConfiguration.Builder().name("somename.realm")/*...*/
.
Upvotes: 2