用于 ORMLite 配置生成的 Android Studio 运行配置 [英] Android Studio run configuration for ORMLite config generation

查看:21
本文介绍了用于 ORMLite 配置生成的 Android Studio 运行配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Android Studio 并想使用 ORMLite 框架.ORMLite for Android 有一种通过找到他的插件.我试过了,效果还不错.它创建了一个名为 createORMLiteConfigFile*Variant* 的任务,您可以运行该任务来生成文件.

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.

这篇关于用于 ORMLite 配置生成的 Android Studio 运行配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆