realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.46k stars 1.75k forks source link

Could not find the generated ValidationList class: Annotation processor may not have been executed. #644

Closed KamilLelonek closed 9 years ago

KamilLelonek commented 9 years ago

I get the following stacktrace:

12-05 13:02:33.310  11237-11237/com.myapplication.myproject E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.myapplication.myproject, PID: 11237
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapplication.myproject/com.myapplication.myproject.main.MainActivity}: io.realm.exceptions.RealmException: Could not find the generated ValidationList class: Annotation processor may not have been executed.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: io.realm.exceptions.RealmException: Could not find the generated ValidationList class: Annotation processor may not have been executed.
            at io.realm.Realm.createAndValidate(Realm.java:482)
            at io.realm.Realm.create(Realm.java:452)
            at io.realm.Realm.getInstance(Realm.java:403)
            at io.realm.Realm.getInstance(Realm.java:253)
            at com.myapplication.myproject.main.MainActivity.onCreate(MainActivity.scala:29)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Realm version: compile 'io.realm:realm-android:0.75.1' Java 8 Android Studio 1.0.0-rc4

kneth commented 9 years ago

I'll have to upgrade Android Studio before answering - RC4 was released yesterday so I'm falling behind ;-)

kneth commented 9 years ago

I have created a minimal app (blank activity) using Android Studio 1.0.0-rc4, and I am not able to reproduce the issue.

KamilLelonek commented 9 years ago

So what do you recommend? I've cleaned my project already..

kneth commented 9 years ago

Can you share your build.gradle?

kneth commented 9 years ago

By the way, did you create a new project or did you upgrade from an earlier version of Realm?

KamilLelonek commented 9 years ago

It's a brand new project. Never used realm.io

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath "com.android.tools.build:gradle:0.14.1"
        classpath "jp.leafytree.gradle:gradle-android-scala-plugin:1.3.1"
    }
}

repositories {
    mavenCentral()
    jcenter()
}

apply plugin: "com.android.application"
apply plugin: "jp.leafytree.android-scala"

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        multiDexEnabled true
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'decoder.properties'
        exclude 'rootdoc.txt'
    }

    dexOptions {
        preDexLibraries false
    }

    sourceSets {
        main.res.srcDirs = [
                'src/main/res/main',
                'src/main/res/common',
                'src/main/res/brands',
                'src/main/res/retailers_list',
                'src/main/res/single_retailer',
                'src/main/res/scanning'
        ]
    }

    dependencies {
        compile fileTree(dir: 'libs', include: '*.jar')
        compile 'com.android.support:multidex:1.0.0'
        compile 'org.scala-lang:scala-library:2.11.4'
        compile 'org.scaloid:scaloid_2.11:3.5-10+'
        compile 'com.android.support:support-v4:21.+'
        compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
        compile 'me.dm7.barcodescanner:zbar:1.5'
        compile 'de.greenrobot:eventbus:2.4.0'
        compile 'io.realm:realm-android:0.75.1'
    }
}
kneth commented 9 years ago

I have uploaded my minimal app at https://www.dropbox.com/s/8md7iomb08bqqv8/rc4test.tar.gz?dl=0. Can you try it and see if it works?

KamilLelonek commented 9 years ago

For Java it's OK, for Scala it's not working at all..

bmunkholm commented 9 years ago

Hi, We havn't really done anything yet to verify that it works with Scala or other similar languages. Until then we can't really assume that it does. So I'll just update the issue title a bit to reflect this, and then we will treat this as a Feature request to properly support Scala.

KamilLelonek commented 9 years ago

I believe that it's a matter of precompilation process and not Scala itself.

bmunkholm commented 9 years ago

Would it be possible for you to provide us with a minimal sample that illustrates the issue?

On Mon, Dec 8, 2014 at 9:17 AM, Kamil Lelonek notifications@github.com wrote:

I believe that it's a matter of precompilation process and not Scala itself.

— Reply to this email directly or view it on GitHub https://github.com/realm/realm-java/issues/644#issuecomment-66036150.

KamilLelonek commented 9 years ago

Here it is: https://copy.com/YpeQLchdkk30U8a3

benjaminprakash88 commented 9 years ago

Hello @KamilLelonek the problem seems to be that you have no model. Can you try and make this.

public class User extends RealmObject {

private String          name;

public String getName() { return name; }
public void   setName(String name) { this.name = name; }

}

Hope this solves your issue.

bmunkholm commented 9 years ago

Feel free to reopen if you can't get this to work.

KamilLelonek commented 9 years ago

Oh, so many hours wasted on finding the solution, which was so simple.

class User(val name: String) extends RealmObject

was enough!

aafa commented 9 years ago

I'm having similar problem running realm with SBT + android-plugin.

What I have

  1. Annotated scala class that extends RealmObject
  2. javacOptions ++= Seq("-processor", "io.realm.processor.RealmProcessor", "-proc:only") That I added just in case
  3. compileOrder := CompileOrder.JavaThenScala

What I see

  1. META-INF/services/javax.annotation.processing.Processor
  2. But at runtime I got
java.lang.IllegalArgumentException: Class is not part of the schema for this Realm

Important - the problem is only with scala classes, with java classes it works fine

I'm not very familiar with annotation processing, what should I look for to get this working?

upd. According to this example https://github.com/retronym/annotation-processor java annotation processing + scala classes = should work

cmelchior commented 9 years ago

Hi @aafa This is most likely not related to this issue, so I copied it to a new issue so we can take the discussion there https://github.com/realm/realm-java/issues/1531

aafa commented 9 years ago

@cmelchior sure, thank you