title: Using realm in the main app and a library
body: <p>I'm trying to use Realm in a library and in the main app and it keeps complaining that the models in the main app are not part of the schema. I've basically implemented everything in a similar manner to the example provided by Realm <a href="https://github.com/realm/realm-java/tree/master/examples/moduleExample" rel="nofollow noreferrer">https://github.com/realm/realm-java/tree/master/examples/moduleExample</a> and I've got exactly the same issue.</p>
  
  <p>Error:</p>
  
  <pre><code>io.realm.exceptions.RealmException: class package.models.User is not part of the schema for this Realm.
  at io.realm.internal.RealmProxyMediator.getMissingProxyClassException(RealmProxyMediator.java:241)
  at io.realm.RealmModuleMediator.getTableName(RealmModuleMediator.java:107)
  at io.realm.RealmSchema.getTable(RealmSchema.java:296)
  at io.realm.Realm.checkHasPrimaryKey(Realm.java:1469)
  at io.realm.Realm.copyToRealmOrUpdate(Realm.java:902)      
  </code></pre>
  
  <p>The error is triggered as soon as I try to save something to Realm - i.e. after log in I'm trying to save the user's details and it crashes.</p>
  
  <p>In my application class for the main app I've got this code</p>
  
  <pre><code>   @Override
  public void onCreate() {
      super.onCreate();
      this.mPrefs = getSharedPreferences(Constants.SHARED_PREFERENCES, 0);
  
      instance = this;
  
      // initialisations
      Realm.init(this);
      config = new AppConfig(mPrefs);
  
      this.realm = Realm.getInstance(getRealmConfig());
  }
  
  public Realm getLibraryRealm(Object module, String name){
      RealmConfiguration config = new RealmConfiguration.Builder()
              .name(name)
              .schemaVersion(1)
              .modules(module)
              .build();
      return Realm.getInstance(config);
  }
  
  public RealmConfiguration getRealmConfig(){
      return new RealmConfiguration.Builder()
              .name(getPackageName())
              .schemaVersion(1)
              .modules(new RealmModule())
              .build();
  }
  </code></pre>
  
  <p>Then in the library I try to get a Realm instance as follows:</p>
  
  <pre><code> AppDataAccessor app = (AppDataAccessor) getApplication();
   Realm realm = app.getRealm(new RealmModule(), Constants.REALM_NAME);
  </code></pre>
  
  <p>Worth mentioning that AppDataAccessor is an interface which is implemented by my application class. </p>
  
  <p>Also, both the main app and the library have Realm Modules defined as follows:</p>
  
  <pre><code>@io.realm.annotations.RealmModule(library = true, classes = { DataSet.class, Field.class, Form.class })
  public class RealmModule {
  }
  </code></pre>
  
  <p>and for the main app:</p>
  
  <pre><code>@io.realm.annotations.RealmModule(classes = {Notification.class, User.class})
  public class RealmModule {
  }
  </code></pre>
  
  <p>Any help would be much appreciated, thanks!</p>