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!
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.