RoboGuice 3.0 NoClassDefFoundError: AnnotationDatabaseImpl

蓝咒 提交于 2020-01-14 09:49:09

问题


For some reason the RoboBlender does not generate the annotation database. My build.gradle has the following dependencies:

dependencies {
    provided 'org.roboguice:roboblender:3.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'org.roboguice:roboguice:3.0'
}

回答1:


This is not a final solution, but it can help you. I don't know why, but RoboGuice 3.0 and 3.0.1 throws this exception. What you have to do is disable annotations for databases in your MainActivity as follows:

static {
    RoboGuice.setUseAnnotationDatabases(false);
}

I hope this help




回答2:


Ok, so it seems that since I didn't have any injection in the main class MainActivity it didn't trigger the annotation processing of the inner AsyncTask. Therefore no annotation database was created.

Moreover, it seems that injection in anonymous inner classes is not supported. So the AsyncTask needs to be a proper class (it can still be inside the MainActivity).

I haven't figured out yet how to tell RoboGuice to inspect the inner classes even though the outer one does not have injections.




回答3:


What does the rest of your project structure look like?

Specifically, have you read the RoboBlender wiki

Later versions of Android Studio will, by default, generate a project that falls into the Configuring RoboBlender for a large application using libraries-category.

Fix below does the following:

  1. Rearrange dependencies in build.gradle
  2. Supplies pointer to GuiceModule in project
  3. Rudimentary module for your project


diff --git a/app/build.gradle b/app/build.gradle
index 1e69cec..8450fff 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -34,9 +34,9 @@ android {
 }

 dependencies {
-    provided 'org.roboguice:roboblender:3.0'
     compile fileTree(dir: 'libs', include: ['*.jar'])
     compile 'org.roboguice:roboguice:3.0'
+    provided 'org.roboguice:roboblender:3.0'
 }

 project.tasks.withType(JavaCompile) { task ->
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 017d11e..dba9e49 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -8,6 +8,7 @@
         android:label="@string/app_name"
         android:theme="@style/AppTheme" >
         <meta-data android:name="roboguice.annotations.packages" android:value="org.jush.roboguice3test"/>
+        <meta-data android:name="roboguice.modules" android:value="org.jush.roboguice3test.GuiceModule"/>
         <activity
             android:name="org.jush.roboguice3test.MainActivity"
             android:label="@string/app_name" >


package org.jush.roboguice3test;

import android.app.Application;

import com.google.inject.AbstractModule;

public class GuiceModule extends AbstractModule {
    private Application application;

    public GuiceModule(Application application) {
        this.application = application;
    }

    @Override
    protected void configure() {
    }
}



回答4:


What did you have to do that it did trigger the annotation processing? My main activity has injections. The maina activity inherits from an abstract activity which has as well injections. That abstract activity inherits from RoboActivity.

When i set the roboguice.annotations.packages to roboguice the NoClassFound exception isn't thrown anymore, but i get a NullPointer Exception for the first inject-Object that I wanna use.

I use eclipse to start the app.

When I disable RoboBlender (RoboGuice.setUseAnnotationDatabases(false);) injection works.




回答5:


The AnnotationDatabaseImpl is generated at compile time

An explanation is available here

Injected objects became null after upgrading to Roboguice 3



来源:https://stackoverflow.com/questions/26661571/roboguice-3-0-noclassdeffounderror-annotationdatabaseimpl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!