I'm looking for a clear step-by-step explanation on how to import GreenDao in Android Studio.
I've used it before in AS, but failed to get it to work again. There are some tutorials out there, but they don't seem to apply to the latest version of AS.
When I clone from github, I get a example project stuff etc. Is there a way to install GreenDaoGenerator without these extras?
Just looking for an up-to-date step-by-step explanation.
Update: I suggest using Realm.io now! Check it out! :-)
Any help would be appreciated!
greenDAO 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. Home page, documentation, and support links: https://greenrobot.org/greendao/
An ORM stands for Object Relational Mapping and will map database tables to entities. For a Persons table for example, a class Person will be created. You will then be able to edit the fields of the class and when you call a "save" method, the database table will be updated.
Sugar ORM is a database persistence library that provides a simple and concise way to integrate your application models into SQLite. In contrast to ActiveAndroid, which is mature, powerful, and flexible, Sugar ORM is: Less verbose. Quicker to set up.
Tested on Android Studio 2.0
With Android Studio 0.6.1+ (and possibly earlier) you can easily add non android project to your android project as a module.
Using below method you can have Java modules(greenDaoGenerator
) and Android modules in the same project and also have the ability to compile and run Java modules as stand alone Java projects.
Open the build.gradle file of the java project and add the following dependency
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile('de.greenrobot:DaoGenerator:1.3.0') }
Copy your DaoGenerator
classes or create if you don't have one to your java module.For e.g. I have created ExampleDaoGenerator
class in my java module.
public class ExampleDaoGenerator { public static void main(String[] args) throws Exception { Schema schema = new Schema(1000, "de.greenrobot.daoexample"); addNote(schema); new DaoGenerator().generateAll(schema, "../DaoExample/src-gen"); } private static void addNote(Schema schema) { Entity note = schema.addEntity("Note"); note.addIdProperty(); note.addStringProperty("text").notNull(); note.addStringProperty("comment"); note.addDateProperty("date"); } }
Now, to generate the classes that you can use in android project follow below steps.
A new application configuration should appear, fill the following information.
com.greendao.generator.ExampleDaoGenerator
Its done !!! you can check your generated classes in the folder that you have specified.For e.g. in this case it is /DaoExample/src-gen
NOTE: You can run your android project again by clicking on run menu -> Edit Configuration . select your project and click ok.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With