Green Dao: Android ORM for your SQLite database

GreenDAO is an open-source Android ORM making development, It is a light & fast ORM for Android that maps objects to SQLite databases. Being highly optimized for Android, greenDAO offers great performance and consumes minimal memory. It relieves developers from dealing with low-level database requirements while saving development time. SQLite is an awesome embedded relational database. Still, writing SQL and parsing query results are quite tedious and time-consuming tasks. greenDAO frees you from these by mapping Java objects to database tables (called ORM, “object/relational mapping”). This way you can store, update, delete, and query for Java objects using a simple object-oriented API.


greenDAO’s unique set of features:

  • Rock-solid: greenDAO has been around since 2011 and is used by countless famous apps
  • Super simple: concise and straight-forward API, in V3 with annotations
  • Small: The library is <150K and it’s just plain Java jar (no CPU dependent native parts)
  • Fast: Probably the fastest ORM for Android, driven by intelligent code generation
  • Safe and expressive query API: QueryBuilder uses property constants to avoid typos
  • Powerful joins: query across entities and even chain joins for complex relations
  • Flexible property types: use custom classes or enums to represent data in your entity
  • Encryption: supports SQLCipher encrypted databases

Add greenDAO to your project

greenDAO is available on Maven Central. Please ensure that you are using the latest versions of the greendao and greendao-gradle-plugin artifact. You can also see the setup here

Add the following Gradle configuration to your Android project. In your root build.gradle file:

buildscript {
repositories {
mavenCentral() // add repository
dependencies {
classpath ''
classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0' // add plugin

In your app modules app/build.gradle file:

apply plugin: ''
apply plugin: 'org.greenrobot.greendao' // apply plugin

dependencies {
implementation 'org.greenrobot:greendao:3.3.0' // add library

Note that this hooks up the greenDAO Gradle plugin to your build process. When you build your project, it generates classes like DaoMaster, DaoSession, and DAOs.

After adding the GreenDao library dependency and the Gradle plugin, we need to first create an entity object.


An entity is a Plain Old Java Object (POJO) that models some data in the database. GreenDao will use this class to create a table in the SQLite database and automatically generate helper classes we can use to access and store data without having to write SQL statements.

public class Users {
@Id(autoincrement = true)
private Long id;
private String firstname;
private String lastname;
private String email;
// Getters and setters for the fields...}

One-time GreenDao setup

Each time an application is launched GreenDao needs to be initialized. GreenDao suggests keeping this code in an Application class or somewhere it will only be run once.

DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "mydatabase", null);
db = helper.getWritableDatabase();
DaoMaster daoMaster = new DaoMaster(db);
DaoSession daoSession = daoMaster.newSession();

GreenDao Helper Classes

After the entity object is created, GreenDao automatically creates the helper classes used to interact with the database. These are named similarly to the name of the entity object that was created, followed by Dao and are retrieved from the daoSession object.

UsersDao usersDao = daoSession.getUsersDao();

Many typical database actions can now be performed using this Dao object with the entity object.


String email = "";
String firstname = "John";
// Single user query WHERE email matches ""
Users user = userDao.queryBuilder()
// Multiple user query WHERE firstname = "John"
List<Users> user = userDao.queryBuilder()


Users newUser = new User("John","Doe","");


// Modify a previously retrieved user object and update


// Delete a previously retrieved user object

R8, ProGuard

If your project uses R8 or ProGuard add the following rules:

-keepclassmembers class * extends org.greenrobot.greendao.AbstractDao {
public static java.lang.String TABLENAME;
-keep class **$Properties { *; }
# If you DO use SQLCipher:
-keep class org.greenrobot.greendao.database.SqlCipherEncryptedHelper { *; }
# If you do NOT use SQLCipher:
-dontwarn net.sqlcipher.database.**
# If you do NOT use RxJava:
-dontwarn rx.**

For Complete details of GreenDao please read documentation’s from below:



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhishek Srivastava

Abhishek Srivastava


Senior Software Engineer | Android | Java | Kotlin |Xamarin Native Android |Flutter |Go