安装摇篮运行在Android的工作室Java可执行文件 [英] Setup Gradle to run Java executable in Android Studio

查看:149
本文介绍了安装摇篮运行在Android的工作室Java可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这里的交易:我使用ORMLite为Android,它使用注释它在Android的映射。如你所知,注释是缓慢的Andr​​oid和ORMLite的制造商已经意识到了这一点,所以他们增加运行Java可执行文件来生成,它绕过需要在android应用程序来查看注释在运行时的资源文件的功能。它看起来是这样的:

 公共类DatabaseConfigUtil扩展OrmLiteConfigUtil {
  私有静态final类<> []类=新类[] {
    SimpleData.class,
  };
  公共静态无效的主要(字串[] args)抛出异常{
    writeConfigFile(ormlite_config.txt,班);
  }
}
 

我需要一种方法来在一段时间运行此Java可执行文件的每一次。总结这件事:我需要一种方法来运行一个Java可执行文件在Android的工作室。它可以通过摇篮,另一个运行配置,JUnit测试的一部分,我真的不关心。我只是需要从AndroidStudio运行这个能力。

这是我目前的摇篮脚本:

  buildscript {
    库{
        mavenCentral()
    }
    依赖{
        类路径com.android.tools.build:gradle:0.5.+
    }
}
应用插件:'机器人'

库{
    mavenCentral()
}

安卓{
    compileSdkVersion 17
    buildToolsVersion17.0.0

    defaultConfig {
        的minSdkVersion 7
        targetSdkVersion 18
    }
}

依赖{
    编译文件树(导演:库,包括:的* .jar)
    编制项目(:AndroidLibrary)

    编译com.j256.ormlite:ormlite-机器人:4.47
}
 

解决方案

我使用的IDE配置这一点。这是如何实现的:

  1. 在菜单中选择运行 - >编辑配置
  2. preSS加号图标 - >应用程序
  3. 名称: OrmLite数据库配置,主要类: com.yourclasspath.DatabaseConfigUtil ,模块使用类路径:
  4. 切换到主构建配置和推出前 preSS加号图标 - >运行其他的配置和选择OrmLite数据库配置

现在,每次你建立你的主要配置它也执行DatabaseConfigUtil。

如果你不希望每次运行前DatabaseConfigUtil只构建跳过步骤4和配置选择运行它​​旁边的工具栏中的运行图标。

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);
  }
}

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.

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'
}

解决方案

I use IDE configuration for this. Here is how to achieve it:

  1. in menu select Run -> Edit configuration
  2. press plus icon -> Application
  3. Name: OrmLite DB config, Main class: com.yourclasspath.DatabaseConfigUtil, Use classpath of module: main
  4. switch to your main build configuration and in the Before launch press plus icon -> Run another configuration and select OrmLite DB config

Now everytime you build your main configuration it also executes DatabaseConfigUtil.

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.

这篇关于安装摇篮运行在Android的工作室Java可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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