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