NoSuchMethodError when using realm.io in a library
<p>I transferred the model classes of my Android app inlcuding realm.io functions into a library following the advices described in the realm.io Java docs section <a href="https://realm.io/docs/java/latest/#sharing-schemas" rel="nofollow">Sharing schemas</a>.
I'm facing a NoSuchMethodError when my app (indirectly) calls realm.io methods which are in the the library.</p>

<pre><code>java.lang.NoSuchMethodError: No static method copyOrUpdate(Lio/realm/Realm;Lmy/package/structure/MyModelClass;ZLjava/util/Map;)Lmy/package/structure/MyModelClass; in class Lio/realm/MyModelClassRealmProxy; or its super classes (declaration of 'io.realm.MyModelClassRealmProxy' appears in /data/user/0/my.name.space/files/.jrebel/load-dexes/bundle3/classes.zip) 
  at io.realm.MyModuleMediator.copyOrUpdate(MyModuleMediator.java:98)
  at io.realm.Realm.copyOrUpdate(Realm.java:1164)
  at io.realm.Realm.copyToRealmOrUpdate(Realm.java:757)
</code></pre>

<p>Here is how my library looks like:</p>

<p><strong>build.gradle (project)</strong></p>

<pre><code>buildscript {
  repositories {
      jcenter()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:2.1.2'
    classpath 'io.realm:realm-gradle-plugin:1.0.1'        
  }
}
</code></pre>

<p><strong>build.gradle (library module)</strong></p>

<pre><code>apply plugin: 'com.android.library'
apply plugin: 'realm-android'
...
buildTypes {
    release {
        minifyEnabled false
        signingConfig signingConfigs.release
        proguardFile getDefaultProguardFile('proguard-rules.pro')
    }
}
...
</code></pre>

<p><strong>proguard-rules.pro</strong></p>

<p>I used <a href="https://github.com/krschultz/android-proguard-snippets/blob/master/libraries/proguard-realm.pro" rel="nofollow">this snippet</a> as a template</p>

<pre><code>-keep class io.realm.annotations.RealmModule
-keep @io.realm.annotations.RealmModule class *
-keep class io.realm.internal.Keep
-keep @io.realm.internal.Keep class * { *; }
-keep my.package.MyModelClass
-dontwarn javax.**
-dontwarn io.realm.**
</code></pre>

<p><strong>MyModule.java</strong></p>

<pre><code>package my.package;

import io.realm.annotations.RealmModule;

@RealmModule(library = true, allClasses = true)
public class MyModule { }
</code></pre>

<p><strong>MyRealm.java</strong></p>

<pre><code>package my.package;

import ...

public class MyRealm {
    private final RealmConfiguration realmConfig;

    public MyRealm(Context context) {
        realmConfig = new RealmConfiguration.Builder(context)
                .name("name.of.my.config")
                .modules(new MyModule())
                .build();
    }

    public Realm getRealm() {
        return Realm.getInstance(realmConfig);
    }
}
</code></pre>

<p><strong>MyModelClass.class</strong></p>

<pre><code>package my.package;

import ...

public class MyModelClass extends RealmObject {

  public void save(Context context) {
    Realm realm = new MyRealm(context).getRealm();
    realm.executeTransaction(new Realm.Transaction() {
        @Override
        public void execute(Realm bgRealm) {
            bgRealm.copyToRealmOrUpdate(MyModelClass.this);
        }
    });
    realm.close();
  }
}
</code></pre>

<p>In my actual app I call something like this which is causing the Exception:</p>

<p><strong>MyActivity.java</strong></p>

<pre><code>// ...
MyModelClass c = new MyModelClass();
c.save(context);
</code></pre>

<p>The code above was working well when everything was in the app project.</p>

<p>Am I missing something general?
Is there something more I need to consider regarding the proguard settings of the lib?
May JRebel cause this kind of problem?</p>