问题描述
所以这就是交易:我在 Android 上使用 ORMLite,它在 Android 中使用注释进行映射.如您所知,Android 中的注释很慢,而 ORMLite 的制造商已经意识到这一点,因此他们添加了运行 java 可执行文件以生成资源文件的功能,从而绕过了在 android 应用程序中在运行时检查注释的需要.它看起来像这样:
So here's the deal: I'm using ORMLite for Android, which uses annotations for it's mapping in Android. As you know, annotations are slow in Android, and the makers of ORMLite have realized this, so they added the ability to run a java executable to generate a resource file that bypasses the need to check annotations at runtime in the android app. It looks something like this:
public class DatabaseConfigUtil extends OrmLiteConfigUtil {
private static final Class<?>[] classes = new Class[] {
SimpleData.class,
};
public static void main(String[] args) throws Exception {
writeConfigFile("ormlite_config.txt", classes);
}
}
我需要一种每隔一段时间运行这个 java 可执行文件的方法.总结一下:我需要一种在 Android Studio 中运行 java 可执行文件的方法.它可以通过 Gradle,另一个运行配置,JUnit 测试的一部分,我并不在乎.我只需要能够从 AndroidStudio 运行它.
I need a way to run this java executable every once in a while. To sum this up: I need a way to run a java executable in Android Studio. It can be via Gradle, another run configuration, part of a JUnit test, I don't really care. I just need the ability to run this from AndroidStudio.
这是我当前的 Gradle 脚本:
This is my current Gradle Script:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 18
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':AndroidLibrary')
compile 'com.j256.ormlite:ormlite-android:4.47'
}
推荐答案
为此我使用 IDE 配置.实现方法如下:
I use IDE configuration for this. Here is how to achieve it:
- 在菜单中选择运行 -> 编辑配置
- 按加号图标 -> 应用程序
- 名称:
OrmLite DB config
,主类:com.yourclasspath.DatabaseConfigUtil
,使用模块的类路径:main
- 切换到您的主要构建配置,并在
Before launch
按加号图标 -> 运行另一个配置并选择 OrmLite DB 配置
- in menu select Run -> Edit configuration
- press plus icon -> Application
- Name:
OrmLite DB config
, Main class:com.yourclasspath.DatabaseConfigUtil
, Use classpath of module:main
- switch to your main build configuration and in the
Before launch
press plus icon -> Run another configuration and select OrmLite DB config
现在每次构建主配置时,它还会执行 DatabaseConfigUtil.
Now everytime you build your main configuration it also executes DatabaseConfigUtil.
如果您不想在每次构建之前运行 DatabaseConfigUtil,只需跳过第 4 步并从工具栏中运行图标旁边的配置选择中运行它.
If you dont want to run DatabaseConfigUtil before every build just skip step 4 and run it from configuration selection next to the Run icon in the toolbar.
这篇关于设置 Gradle 以在 Android Studio 中运行 Java 可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!