org.greenrobot.greendao.DaoException in android release mode when using androidx

342 Views Asked by At

I'm using greenDAO for a long time in my app without any problem! But after migrating my project to using androidX , I received an Exception (org.greenrobot.greendao.DaoException) like below.

Non-fatal Exception: org.greenrobot.greendao.DaoException: app.myapp.models.database.LocationDao@9eff3d3 (LOCATION) does not have a single-column primary key
   at org.greenrobot.greendao.AbstractDao.assertSinglePk(AbstractDao.java:917)
   at org.greenrobot.greendao.AbstractDao.load(AbstractDao.java:135)
   at app.myapp.views.activities.LocationDetailActivity.putLocationDetails(LocationDetailActivity.java:707)
   at app.myapp.views.activities.-$$Lambda$ZJfQ3ya-jyJgM_oHuJ1u29_DoCw.run(-.java)
   at android.os.Handler.handleCallback(Handler.java:815)
   at android.os.Handler.dispatchMessage(Handler.java:104)
   at android.os.Looper.loop(Looper.java:207)
   at android.app.ActivityThread.main(ActivityThread.java:5845)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:768)

I searched a lot in google for solving this problem but I didn't find an answer helping me. And this is my model class codes:

public class Location {

@Id (autoincrement = true)
@SerializedName("LocationID")
private long locationID;

@SerializedName("LocationCategoryID")
private long locationCategoryID;

@SerializedName("LocationTitleFA")
private String locationTitleFA;

@SerializedName("LocationTitleEN")
private String locationTitleEN;

@SerializedName("PictureAddress")
private String pictureAddress;

@Generated(hash = 591434765)
public Location(long locationID, long locationCategoryID,
        String locationTitleFA, String locationTitleEN, String pictureAddress) {
    this.locationID = locationID;
    this.locationCategoryID = locationCategoryID;
    this.locationTitleFA = locationTitleFA;
    this.locationTitleEN = locationTitleEN;
    this.pictureAddress = pictureAddress;
}

@Generated(hash = 375979639)
public Location() {
}}

and setter and getters...

Could anyone help me?!

1

There are 1 best solutions below

0
Mr. ViP On

Related to Mr. Markus Junginger's comment, I fixed issue:

"Release mode" is probably a good lead. Please check the following links: github.com/greenrobot/greenDAO#r8-proguard, developer.android.com/jetpack/androidx/migrate, github.com/objectbox/objectbox-java/issues/….

I updated my greendao Proguard codes and fixed problem. A line of codes was:

-dontwarn org.greenrobot.greendao.database.

Changed to:

-dontwarn net.sqlcipher.database.**