0

We are currently using greenDAO3 in this project. I believe we were using the greenDAO2 at some point because it seems that we were using the legacy generator class.

So I am attempting to add a new table to the database for a new feature in our application. I am not very familiar with greenDAO, but I figured it would be easier to have it auto-generate the file at build time with Gradle.

Everything works fine, but after adding some stuff to my root.gradle and app.gradle, I get this error.

ERROR: Found 1 problem(s) parsing "/Users/Dustin/Projects/project/app/src/main/java/com/package1/package2/db/MyClassTest.java". First problem:
Pb(96) The serializable class MyClassTest does not declare a static final serialVersionUID field of type long (536871008 at line 18).

These are the changes I made.

diff --git a/app/build.gradle b/app/build.gradle
index 40b3b80d..60f2a688 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,4 +1,7 @@
 apply plugin: 'com.android.application'
+apply plugin: 'com.google.gms.google-services'
+apply plugin: 'org.greenrobot.greendao'
+apply plugin: 'com.google.gms.google-services'
 apply plugin: 'io.fabric'

 android {
@@ -234,4 +237,7 @@ dependencies {
     implementation 'com.android.support.constraint:constraint-layout:1.1.3'
 }

-apply plugin: 'com.google.gms.google-services'
\ No newline at end of file
+greendao {
+    schemaVersion 24
+}
+

When I suppress warnings it proceeds to the next serializable class in the db folder. I really don't want to suppress warnings, because that seems like bad practice in this case.

Dustin K
  • 150
  • 2
  • 11

1 Answers1

1

Add a serialVersionUID field in your MyClassTest.java
A good pratice might be to set the last modification date

public class MyClassTest {
    private static final long serialVersionUid = 6082019L;
}

More informations available on this post

IQbrod
  • 2,060
  • 1
  • 6
  • 28
  • I thought about doing this, but is there a guarantee that this will work with all other application versions? Also, why was there no build errors before, but there is build errors after I added those lines to gradle. Which makes me think there may be something else going on in the project which I don't know about. – Dustin K Aug 06 '19 at 15:21
  • I think your class ```MyClassTest``` implements or extends an interface/class which extends [java.io.Serializable](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/Serializable.html) which requires a serialVersionUid. One of your dependcies (constraint-layout I suppose) now check serialVersionUid requirements. A warning from no serialVersionUid is a normal behavior tbh. Please provide your test class to have a better explanation ! – IQbrod Aug 06 '19 at 15:43
  • Your problem might also come from the schema version deleted from greendao. A default schemaVersion might be provided and not match your implementation. – IQbrod Aug 06 '19 at 15:47
  • Also a generated serialVerisonUid is generated at runtime anyway. This default value depends on environement (as mentionned in the related post), it's always a good practice to set a serialVersionUid rather than let it be generated automatically – IQbrod Aug 06 '19 at 15:52
  • Yes, it implements `java.io.Serializable` directly. This error never surfaced before, so I thought it was something else. The status quo on this project is there is no manually assigned `serialVersionUID`, but I figured I would suppress the warning for now and deal with it later. Thanks everyone! – Dustin K Aug 06 '19 at 17:46