【问题标题】:RoboGuice, RoboBlender and EclipseRoboGuice、RoboBlender 和 Eclipse
【发布时间】:2015-02-07 19:44:16
【问题描述】:

我使用 RoboGuice 3.0 alpha-2,已经使用了很长一段时间,对此我很满意。现在我想升级到 RoboGuice-3.0 或 -3.01,但我无法开始工作。

我使用 Eclipse(我在某些项目中使用 Android Studio,但我真的不喜欢它),RoboBlender 抱怨 AnnotationDatabaseImpl 不存在。当我禁用 Roboblender 时,我得到 ​​p>

E/AndroidRuntime(18825): FATAL EXCEPTION: main
E/AndroidRuntime(18825): java.lang.NoClassDefFoundError: com.google.inject.internal.util.$Maps
E/AndroidRuntime(18825):    at com.google.inject.assistedinject.BindingCollector.<init>(BindingCollector.java:34)
E/AndroidRuntime(18825):    at com.google.inject.assistedinject.FactoryModuleBuilder.<init>(FactoryModuleBuilder.java:206)
E/AndroidRuntime(18825):    at com.loqli.android.robo.GossipModule.configure(GossipModule.java:260)
E/AndroidRuntime(18825):    at com.google.inject.AbstractModule.configure(AbstractModule.java:78)
E/AndroidRuntime(18825):    at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:252)
E/AndroidRuntime(18825):    at com.google.inject.spi.Elements.getElements(Elements.java:107)
E/AndroidRuntime(18825):    at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:135)
E/AndroidRuntime(18825):    at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
E/AndroidRuntime(18825):    at com.google.inject.Guice.createInjector(Guice.java:100)
E/AndroidRuntime(18825):    at com.google.inject.Guice.createInjector(Guice.java:87)
E/AndroidRuntime(18825):    at roboguice.RoboGuice.createGuiceInjector(RoboGuice.java:186)
E/AndroidRuntime(18825):    at roboguice.RoboGuice.getOrCreateBaseApplicationInjector(RoboGuice.java:151)
E/AndroidRuntime(18825):    at roboguice.RoboGuice.getOrCreateBaseApplicationInjector(RoboGuice.java:90)

我回到了 alpha-2,但现在我想知道,RG 和 RB 是否应该与 Eclipse 和 ant 一起使用?

编辑:我提到了“Eclipse”。我对它在 Android Studio 上的工作方式不感兴趣,我想知道如何让它在 Eclipse 中工作。

【问题讨论】:

    标签: android eclipse roboguice


    【解决方案1】:

    eclipse 中的正确方法是set RoboBlender up as annotation processor。但是,它并没有让它起作用(见下文)。

    Maven - 工作解决方案

    这就是我的工作方式 - 使用 Maven。 Maven 生成注释数据库到target\generated-sources\annotations。所以我只是将此路径添加为 eclipse 中的源文件夹,然后就不再使用 java.lang.ClassNotFoundException: AnnotationDatabaseImpl

    Ant - 类似的解决方案?

    根据您的问题,我认为您使用的是蚂蚁?!也许你可以set up the annotation processing with ant 代替 maven?

    Eclipse 注释处理器 - 进一步的方法

    如前所述,我首先尝试使用 Eclipse 注释处理器,并且几乎可以正常工作。 我在工厂路径中添加了RoboBlender and its transitive dependencies。对于 RoboBlender 3.0.1,这是

    1. RoboBlender,它的依赖
    2. velocity 及其依赖项
    3. commons-collections
    4. commons-lang

    因为我在注释数据库中使用了多个模块,所以我添加了处理器选项guiceAnnotationDatabasePackageName

    这导致在我的 Eclipse 错误日志中显示 Impossible to generate annotation database. 的信息消息,这正是 generic exception thrown by the RoboGuice's AnnotationDatabaseGenerator 的消息。 不幸的是,没有堆栈跟踪或任何东西,所以我放弃了这里并使用如上所述的 maven 找到了解决方案。也许其他人可以在这里找到丢失的部分?
    如果对您有帮助,您可以找到我使用 RoboBlender here 的项目。

    【讨论】:

      【解决方案2】:

      AnnotationDatabaseImpl 类由 RoboBlender 在编译时生成。

      您可以将以下内容指定为 Java 编译器参数(使用您的包名)

      -AguiceAnnotationDatabasePackageName=some.package.name.here
      

      这应该会在编译时生成您需要的类。

      然后在你的清单中你需要指向同一个包

       <meta-data android:name="roboguice.annotations.packages" android:value="some.package.name.here"/>
      

      对于 Maven 设置,请参考此处的答案:

      Injected objects became null after upgrading to Roboguice 3

      【讨论】:

      • 啊。我做了清单中的事情,但没有做财产。我会试试的。
      • 但我想我迟早要切换到Android Studio,不幸的是......
      • 我添加了 java 编译器参数,我的清单中已经有了元数据行,但它仍然不会生成 AnnotationDatabaseImpl 文件。
      • 我在 Intellij 中完成了此操作并进行了完整的重建。您应该能够在生成的源和目标类目录中看到该类。如果没有元标记,它会在类目录的根目录中生成一个类(没有包名)。
      • 我现在已经切换到 Android Studio(很遗憾),所以这个问题对我来说不再那么重要了。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-14
      • 2015-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多