GreenDao机器人工作室 [英] GreenDao Android Studio

查看:116
本文介绍了GreenDao机器人工作室的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在找一个明确的一步一步的解释如何在Android的工作室导入GreenDao。

我以前用它在AS,但未能得到它的工作了。 有一些教程在那里,但他们似乎并不适用于作为最新版本。

当我从github上克隆,我得到一个示例项目的东西等。 有没有一种方法来安装GreenDaoGenerator没有这些额外?

只是寻找一个向上的最新一步一步的解释。

更新:我建议使用Realm.io吧!一探究竟! : - )

任何帮助将是AP preciated!

解决方案

测试在Android工作室1.0

使用Android的工作室0.6.1+(甚至更早),你可以很容易的非Android项目添加到您的Andr​​oid项目作为一个模块。

使用下面的方法,你可以拥有的Java模块(<$ C C $> greenDaoGenerator )和Android模块在同一个项目,也有编译和运行Java模块作为独立的Java项目的能力

  1. 打开在Android的Studio中的Andr​​oid项目。如果你没有一个, 创建一个。
  2. 点击文件>新建模块。选择 Java库,然后单击下一步。
  3. 包的名称等填充,然后单击完成。您现在应该看到一个 你的Andr​​oid项目中的Java模块。
  4. 打开 build.gradle 文件Java项目,并添加下面的依赖

     相关性{
        编译文件树(导演:库,包括:['的* .jar'])
        编译(de.greenrobot:DaoGenerator:1.3.0)
    }
     

  5. 复制你的 DaoGenerator 类或创建,如果你没有一个到你的java module.For如我创建了 ExampleDaoGenerator 在我的Java模块类。

     公共类ExampleDaoGenerator {
    
        公共静态无效的主要(字串[] args)抛出异常{
            架构模式=新模式(1000,de.greenrobot.daoexample);
            addNote(架构);
            新DaoGenerator()generateAll(架构,../DaoExample/src-gen)。
        }
    
        私有静态无效addNote(架构模式){
            实体注= schema.addEntity(注);
            note.addIdProperty();
            note.addStringProperty(文本)NOTNULL()。
            note.addStringProperty(意见);
            note.addDateProperty(日);
       }
    
    }
     

现在,生成可以在Android项目使用的类遵循以下步骤。

  1. 点击执行菜单中的顶吧。点击修改配置...
  2. 在新窗口中,点击以及登录窗口的左上角并选择应用
  3. 一个新的应用程序配置应该出现,填写以下信息。

    1. 给它一个名称如greenDao。
    2. 主要类点击 ...按钮并选择具有主method.for例如,您的生成器类在这种情况下,它是 com.greendao.generator.ExampleDaoGenerator
    3. 工作目录Java项目的选择路径。
    4. 使用类模块选择您的Java项目。 单击确定。
    5. 再次进入运行菜单,现在你可以看到如运行greendao。点击it.It应该编译成功。

它做!你可以检查你生成的类,你有specified.For如文件夹中在这种情况下, / DaoExample / src目录根

注:您可以通过点击运行菜单中再次运行Android项目 - > 修改配置。选择您的项目,然后点击确定。

I'm looking for a clear step-by-step explanation on how to import GreenDao in Android Studio.

I've used it before in AS, but failed to get it to work again. There are some tutorials out there, but they don't seem to apply to the latest version of AS.

When I clone from github, I get a example project stuff etc. Is there a way to install GreenDaoGenerator without these extras?

Just looking for an up-to-date step-by-step explanation.

Update: I suggest using Realm.io now! Check it out! :-)

Any help would be appreciated!

解决方案

Tested on Android Studio 1.0

With Android Studio 0.6.1+ (and possibly earlier) you can easily add non android project to your android project as a module.

Using below method you can have Java modules(greenDaoGenerator) and Android modules in the same project and also have the ability to compile and run Java modules as stand alone Java projects.

  1. Open your Android project in Android Studio. If you do not have one, create one.
  2. Click File > New Module. Select Java Library and click Next.
  3. Fill in the package name, etc and click Finish. You should now see a Java module inside your Android project.
  4. Open the build.gradle file of the java project and add the following dependency

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile('de.greenrobot:DaoGenerator:1.3.0')
    }
    

  5. Copy your DaoGenerator classes or create if you don't have one to your java module.For e.g. I have created ExampleDaoGenerator class in my java module.

    public class ExampleDaoGenerator {
    
        public static void main(String[] args) throws Exception {
            Schema schema = new Schema(1000, "de.greenrobot.daoexample");
            addNote(schema);
            new DaoGenerator().generateAll(schema, "../DaoExample/src-gen");
        }
    
        private static void addNote(Schema schema) {
            Entity note = schema.addEntity("Note");
            note.addIdProperty();
            note.addStringProperty("text").notNull();
            note.addStringProperty("comment");
            note.addDateProperty("date");
       }
    
    }
    

Now, to generate the classes that you can use in android project follow below steps.

  1. Click on the run menu in the top bar. Click Edit Configurations...
  2. In the new window, click on the plus sign at the top left of the window and select Application
  3. A new application configuration should appear, fill the following information.

    1. Give it a name e.g. greenDao.
    2. In main class click … button and select your generator class which have the main method.for e.g. in this case it is com.greendao.generator.ExampleDaoGenerator
    3. In working directory select path of your java project.
    4. In use class of module select you java project. click ok.
    5. Again go to run menu and now you can see e.g. run greendao. click on it.It should compile successfully.

Its done !!! you can check your generated classes in the folder that you have specified.For e.g. in this case it is /DaoExample/src-gen

NOTE: You can run your android project again by clicking on run menu -> Edit Configuration . select your project and click ok.

这篇关于GreenDao机器人工作室的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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