0
votes

So I'm pretty psyched about the new Realm features added in 0.88 and want to use them in my project. Unfortunately, in 0.88+ it is now neccesary to use a Gradle plugin called realm-android.

I am also using Dagger 1 which requires a code generation step (I am using apt for this). When I apply the realm-android plugin, all compiles fine but I get the dreaded

Module adapter for class could not be loaded

indicating that the compiler has not properly generated the files. If I remove the realm plugin, dagger generates the files correctly. How can I get Realm and Dagger to play nice together with this new plugin mechanism?

build.gradle(project level): (edited for relevance)

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
        classpath 'io.realm:realm-gradle-plugin:0.88.2'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}

build.gradle(module level): (edited for relevance)

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'com.neenbedankt.android-apt'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.2'
    dexOptions {
        jumboMode = true
    }

defaultConfig {
    applicationId "xx.xx.xx"
    minSdkVersion 15
    targetSdkVersion 23
    multiDexEnabled true
}

def daggerVersion = '1.2.2'

dependencies {
    apt "com.squareup.dagger:dagger-compiler:$daggerVersion"
    compile "com.squareup.dagger:dagger:$daggerVersion"
}

Edit 4/2/16

Ok things are getting weird and I wonder if I'm not chasing a ghost here. I noticed that it is not just the addition of the plugin but also the existence of at least two realm models. Having two models X and Y, APT doesn't run for Dagger and I get that same error. Have 0 or 1 models (X OR Y) and it runs without error. I am not using the models in any way nor am I even instantiating a Realm. For a concrete example, here are two data models I'm using that exhibit this behavior.

import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import io.realm.annotations.Required;

public class ContactEmail extends RealmObject {
    @PrimaryKey
    private String localGuid;
    @Required
    private String email;

    public String getLocalGuid() {
        return localGuid;
    }

    public void setLocalGuid(String localGuid) {
        this.localGuid = localGuid;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
}


import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import io.realm.annotations.Required;

public class ContactPhone extends RealmObject {
    @PrimaryKey
    private String localGuid;
    @Required
    private String phone;

    public String getLocalGuid() {
        return localGuid;
    }

    public void setLocalGuid(String localGuid) {
        this.localGuid = localGuid;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
}
1
So, uh, this is an extremely wild guess, but what happens if you change the order of realm-android and com.neenbedankt.android-apt?EpicPandaForce
Heh yeah been trying all sorts of orderings there :) No go sadly. I'm super thrown off by this 'allows one object' thing!Andrew G
You should make a minimal example and post it as an issue for realm-javaEpicPandaForce
Yes, please create an Github issue with a project that can reproduce this. We already have projects combining Dagger 1 and Realm without problems , so I am suspecting something else is at play here. Have you tried disabling MultiDex?Christian Melchior
@ChristianMelchior yes I was wondering about the multidex factor given the weird multiple object behavior. I will work to set up a minimum example.Andrew G

1 Answers

0
votes

It seems like Realm is applying the APT plugin by itself (on this line). So, try to remove the android-apt plugin line.

This caught me off-guard when I was evaluating an Android project that used Butterknife 8 and did not declare the android-apt plugin but only the realm plugin.