0

I'm investigating greenDAO for an Android version of one of our iOS apps that heavily uses CoreData functionality.

I'm confused on how to start though. I've seen the DaoGeneratorExample code, but I'm not confident on how that relates to my project.

Let's assume my project is called MyApp. Do I need to create a SECOND Android project called MyAppDaoGenerator which I just run to generate java files and put them in the MyApp directories?

Or is the schema generation supposed to exist within the MyApp code?

Kenny Wyland
  • 20,844
  • 26
  • 117
  • 229
  • I would suggest having it within you app as a separate module. Since this helps segregating it from the core functionality as well as indicating the source that needs to be edited to handle schema changes. – humblerookie Jun 15 '16 at 07:01

2 Answers2

3

The easy way to have all the code (the generator and the generated one) in one single project is to have all the generator code in a module as a Java library .

In this github project you have an already created module that you could import and modify to suit your needs. In the project README there's also a nice tutorial on how to run the generator code.

If you want to do it from scratch, this answer looks like a good point to start, but I always used the import module method.

Community
  • 1
  • 1
Jofre Mateu
  • 2,390
  • 15
  • 26
  • Ok, so it doesn't need to be a separate Android app. I could just have a Generator class in my android project that has a main() method and I just manually execute that main() method whenever I've updated my schema. Right? Your option uses gradle to fire off that updated-schema-generation task, where as the "scratch" just has another Run profile in their Android Studio project. Have I got that right? – Kenny Wyland Jun 15 '16 at 20:27
  • Exactly. At the end, both ways are practically the same, and with a little effort you could have working the imported module with a Run profile, only modifying how the target directory for the generated code is provided. By default, in the imported module, this directory is specyfied in the gradle file and if you want to use a Run profile you would have to define it in the source code or add the path to the directory as an argument in the profile. – Jofre Mateu Jun 16 '16 at 07:25
2

In the greenDao Generator Class you will have to specify the directory to your main project where you want the generated files to be stored.

See a tutorial i wrote about greenDao full implementation with android integrating-greenDao-into-your-android-application

Sunday G Akinsete
  • 802
  • 13
  • 14