Android 2.3: Could not find validateTable method in generated proxy class
I've recently changed my app's minimum API level to 9 and when testing on Android 2.3 I always get this exception:
java.lang.RuntimeException: Unable to create application com.tbilisi.bus.App: io.realm.exceptions.RealmException: Could not find the validateTable method in the generated io.realm.HistoryItemRealmProxy class: Annotation processor may not have been executed.
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3413)
at android.app.ActivityThread.access$2200(ActivityThread.java:124)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1012)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3821)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: io.realm.exceptions.RealmException: Could not find the validateTable method in the generated io.realm.HistoryItemRealmProxy class: Annotation processor may not have been executed.
at io.realm.Realm.initializeRealm(Realm.java:608)
at io.realm.Realm.createAndValidate(Realm.java:523)
at io.realm.Realm.create(Realm.java:480)
at io.realm.Realm.getInstance(Realm.java:397)
at io.realm.Realm.getInstance(Realm.java:359)
at io.realm.Realm.getInstance(Realm.java:340)
at com.tbilisi.bus.App.loadRealm(App.java:22)
at com.tbilisi.bus.App.onCreate(App.java:18)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3410)
at android.app.ActivityThread.access$2200(ActivityThread.java:124)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1012)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3821)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
All of my source is published at https://github.com/shvelo/tbilisi-bus
I've tried adding @RealmClass to my models but it doesn't help at all.
Hi @shvelo I just checked your code out and ran it from Android Studio without any problems. Have you tried cleaning and/or reimporting the project again?
I've tried deleting the build directory and building again, several times. What Android version are you running it on?
On 11:23am, Thu, Feb 19, 2015 Christian Melchior [email protected] wrote:
Hi @shvelo https://github.com/shvelo I just checked your code out and ran it from Android Studio without any problems. Have you tried cleaning and/or reimporting the project again?
— Reply to this email directly or view it on GitHub https://github.com/realm/realm-java/issues/870#issuecomment-75008651.
Lollipop, but those classes are generated by the annotation processor so it should not be Android related, but perhaps more Java version related. What version of Java are you using?
I'm using OpenJDK 8. The app works fine on my Jellybean device, but the crash only happens on Gingerbread. Here's my build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.+'
}
}
repositories {
jcenter()
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.google.maps.android:android-maps-utils:0.3+'
compile 'io.realm:realm-android:0.79.0'
}
android {
defaultConfig {
versionCode 42
versionName "4.2.0"
}
compileSdkVersion 21
buildToolsVersion "21.1.2"
lintOptions {
abortOnError false
}
defaultConfig {
minSdkVersion 9
targetSdkVersion 21
}
buildTypes {
release {
debuggable false
minifyEnabled true
proguardFile file("proguard.cfg")
}
}
signingConfigs {
debug {
storeFile file("debug.keystore")
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
apply from: 'signing.gradle'
Same problem here, working great on Android 4.0+ but not for 2.3. I'm using @RealmClass annotation.
Hmm, you are correct there seem to be some issue with Gingerbread. Our proxy files and methods gets generated allright, but the code calling them cannot find them. Very odd.
It seems to be related to the bugs described here: https://github.com/square/otto/issues/37 http://corner.squareup.com/2012/08/getting-to-the-bottom.html
It looks like it might be due to our proxy classes using unsupported API's (on 2.3.7) which then fail to initialise (they shouldn't). In this case our proxy classes are using JsonReader which isn't supported before API 11, but I will have to investigate further to be sure.
Yeah I was getting a warning in Logcat that JsonReader was not found.
E/dalvikvm( 481): Could not find class 'android.util.JsonReader', referenced from method io.realm.Realm.createOrUpdateAllFromJson
Yeah, but Dalvik should be able to handle that. It apparently doesn't do that very well on some versions of Android :(
I am having this issue as well on all gingerbread (<2.3.7) devices Is there any hacky way to resolve this problem?
Hi @njovy
The hacky approach would be to remove the populateUsingJsonStream() method from the proxy class as well as the import android.util.JsonReader;
This bug will be fixed as part of our migration rewrite (#880), as we plan to change how the ProxyClasses are created.
@cmelchior Thanks for the quick response! I will get rid of the method from proxy class and build realm until this issue is fixed.
@njovy are you successful with the hacky approach and can you please share how you achieved that. Thanks.
@Sakirk The app uses createFromJson heavily to make a new realm object as our realm objects are returned from a server in json format so I didn't get rid of the method to resolve the issue yet. We have very few clients using gingerbread devices so we told them to upgrade their phones at the moment. I would include android.util.JsonReader class in realm and build a jar to fix this issue until #880 is fixed .
I also have the same crash at my application on Gingerbread devices. I'm using 0.80.0 Realm version and it is crashes my app. I'm not using calls like createFromJson(). Maybe there is a temporary hotfix for this issue until it will be fixed?
It looks like it will take more time until this issue is resolved. As my app does not start on gingerbread devices, I had to do a hacky way until it is fixed completely. For those of you who are still waiting for this fix, I have forked the repo and replaced android.util.JsonReader with newly included android.support.v11.util.JsonReader(copy from Android project). The repo is here https://github.com/njovy/realm-java. I ran realm:connectedCheck on Galaxy S running 2.3.6 with no error. You can build the project or simply use the jar file I added under build/libs directory. Hope migration rewrite is done soon.
The same crash here on 2.3. Thanks @njovy I will use this for now. :+1:
Please Realm Team we really really need this fixed. Thanks
We also have an app that needs to work on API 10, but in the meantime @njovy 's fix works, thanks. :+1:
I am glad that it helped :) The repo will be updated until #938 is fixed!
Sorry for the wait. A fix should now have been merged to master.