I'm using Android Studio and want to use ORMLite framework. ORMLite for Android has a mechanism for making DAO creation through table config file.
How to setup additional Run Configuration in Android Studio for generating this config?
Note: An easy way to locate your configuration directory is to navigate to Help > Edit Custom VM Options in Android Studio. This will open a configuration file.
I managed to do it, but it was a little bit tricky.
I have a class called DatabaseConfigUtil which extends OrmLiteConfigUtil, that I created just by following the ormlite official tutorial, so I'll just assume you did the same and also have that class. Please note that you have to pass the complete path to the configuration file, instead of just the file name. Nonetheless, here it is:
public class DatabaseConfigUtil extends OrmLiteConfigUtil { private static final Class<?>[] classes = new Class[] { Class1.class, Class2.class, Class3.class, Class4.class }; public static void main(String[] args) throws SQLException, IOException { writeConfigFile(new File("PATH/TO/ANDROID/PROJECT/src/main/res/raw/ormlite_config.txt"), classes); } }
This is the class we want to execute in order to create the ormlite_config.txt.
In the Android Studio project navigation panel, right-click on the DatabaseConfigUtil.java and select "Run" (the option with the green arrow). If you don't have a Run Configuration created, it will create one for you.
Now, just edit the configuration
In the "Before launch" section, remove the Make. This is not problematic if in the raw folder you already have the file ormlite_config.txt, but if you don't, when you run the class, the project will compile which will fail because the ormlite_config.txt doesn't exist.
Now run the project again.
Everything should go smoothly now.
Cheers
---------------------------- ## ----------------------------
UPDATE:
Recently I had to work with ORMLite again and decided that this solution could be automated with a gradle plugin. Before creating my own, as the lazy developer that I am, I decided to check if anyone had attempted the same before. Thankfully, @snicolas did just that and you can find his plugin here. I've tried it, and it works reasonably well. It creates a task called createORMLiteConfigFile*Variant*
that you can run to generate the file.
Collecting up all the comments under @Joao's answer gave me this working solution:
1) Edit Configuration for your DB config file generator:
2) Configure the Working directory
to be $MODULE_DIR$/src/main
.
3) In Before launch
, replace Make
with Make, no error check
When you have these steps in place you can specify just the file name in your OrmLiteConfigUtil
class:
public class DBConfigUtil extends OrmLiteConfigUtil { /** * To make this work in Android Studio, you may need to update your * Run Configuration as explained here: * http://stackoverflow.com/a/17332546 */ public static void main(String[] args) throws Exception { writeConfigFile("ormlite_config.txt", sClasses); }
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