Java 当我添加RoboBlender时,Gradle项目不会生成
我已经将RoboGuice 3依赖项添加到它编译和运行的gradle构建文件中,但是应用程序由于NoClassDefFoundError:AnnotationDatabaseImpl而崩溃。做了一些研究表明RoboBlender是生成定义所必需的(我熟悉RoboGuice 2,它不需要RoboBlender),但当我添加RoboBlender时,项目不再构建Java 当我添加RoboBlender时,Gradle项目不会生成,java,android,build.gradle,roboguice,Java,Android,Build.gradle,Roboguice,我已经将RoboGuice 3依赖项添加到它编译和运行的gradle构建文件中,但是应用程序由于NoClassDefFoundError:AnnotationDatabaseImpl而崩溃。做了一些研究表明RoboBlender是生成定义所必需的(我熟悉RoboGuice 2,它不需要RoboBlender),但当我添加RoboBlender时,项目不再构建 dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) comp
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'com.koushikdutta.urlimageviewhelper:urlimageviewhelper:1.0.4'
compile 'de.hdodenhof:circleimageview:1.2.1'
compile 'com.getbase:floatingactionbutton:1.4.0'
compile 'de.hdodenhof:circleimageview:1.2.1'
compile 'org.twitter4j:twitter4j-core:4.0.2'
compile files('libs/json-me.jar')
compile files('libs/twitter_api_me-1.9.jar')
compile('ch.acra:acra:4.5.0') {
exclude group: 'org.json'
}
compile 'org.roboguice:roboguice:3.0.1'
provided 'org.roboguice:roboblender:3.0.1'
}
生成错误:
Error:Execution failed for task ':app:compileDebugJava'.
java.lang.ClassCastException:com.sun.tools.javac.code.Type不能转换为javax.lang.model.Type.DeclaredType
l> 这是什么原因造成的,我如何修复它?我找到了一个解决办法,我刚刚禁用了AnnotationDatabase处理,删除了RoboBlender依赖项,解决了我的问题。我仍然想知道为什么我首先会遇到这个问题。我也有同样的问题,在我的例子中,有一个包含两个构造函数的类:
@Inject
public PaymentSelectionDialog(Context context) {
this.context = context;
}
@Inject
public PaymentSelectionDialog(Context context, PaymentSelectable paymentSelectable) {
this.context = context;
this.paymentSelectable = paymentSelectable;
我使用第一个构造函数没有问题,但当我使用第二个构造函数实例化我的对象时,我遇到了这个问题。所以问题是Roboguice试图注入一个实现PaymentSelectable接口的对象,但这个对象没有在任何模块中定义
可能您使用的构造函数引用没有在任何模块中定义
希望有帮助 如以下示例所示,错误使用
@Inject
可能会导致此类错误:
public class Foo {
@Inject
public Foo(Context context, int code) {
//this won't work because of the primitive in the constructor
//and the @Inject annotation are being used together
}
}
RoboBlender将无法构造数据库,因为无法将原语强制转换为声明的类型
因此,您的错误消息
java.lang.ClassCastException: com.sun.tools.javac.code.Type cannot be cast to javax.lang.model.type.DeclaredType
表示原语(com.sun.tools.javac.code.Type)
不能转换为引用类型javax.lang.model.Type.DeclaredType
相反,您需要编写一个提供程序:
public class FooProvider implements Provider<Foo> {
Context context;
private static int CODE = 1;
@Inject
public FooProvider(Context context) {
this.context = context;
}
@Override
public Foo get() {
return new Foo(context, CODE);
}
}
公共类FooProvider实现提供程序{
语境;
私有静态int代码=1;
@注入
公共FooProvider(上下文){
this.context=上下文;
}
@凌驾
公共Foo-get(){
返回新的Foo(上下文、代码);
}
}
并将Foo
绑定到模块中的该提供程序
binder.bind(Foo.class).toProvider(FooProvider.class)代码>
并从Foo
的构造函数中删除@Inject
我建议您遍历对象图,并在带有原语的构造函数上查找@Inject
注释。如上所述,删除注释并为其编写提供程序。RoboBlender将正确构建注释DatabaseImpl
,您的项目将编译