Roboblender use annotation databases with multiple modules

1.3k views Asked by At

I'm following the steps from the RoboBlender Wiki to use annotations database but I keep getting java.lang.IllegalStateException: Unable to use annotation database(s) because it cannot find AnnotationDatabaseImpl

I am using Android Studio and Gradle. The project consists of multiple modules.

  • app
  • moduleA
  • moduleB
  • moduleC

Here is what I added to my build scripts:

app/build.gradle:

dependencies {
  provided 'org.roboguice:roboblender:3.0.1'
  provided 'org.roboguice:roboblender:3.0.1'
}
project.tasks.withType(JavaCompile) { task ->
    options.compilerArgs << "-AguiceAnnotationDatabasePackageName=com.sample.myapp"
}

module[x]/build.gradle:

project.tasks.withType(JavaCompile) { task ->
    options.compilerArgs << "-AguiceAnnotationDatabasePackageName=com.sample.module[x]"
}

On the Application Object:

 RoboGuice.setUseAnnotationDatabases(true);
 RoboGuice.getOrCreateBaseApplicationInjector(this, RoboGuice.DEFAULT_STAGE,
 RoboGuice.newDefaultRoboModule(this), new MyModule());
        RoboGuice.injectMembers(this, this);

Am I missing something? I found some similar questions but they weren't very useful.

Update: I forgot to add it on the first time but yes I am including the manifest meta.

<meta-data android:name="roboguice.modules" android:value="your.package.MyModule"/>  
<meta-data android:name="roboguice.annotations.packages" android:value="com.sample.myapp,com.sample.modulex,com.sample.moduley"/>

Update 2: I finally found the problem. Proguard was deleting the class. Fixed by adding:

-keep public class * extends com.google.inject.AnnotationDatabase
2

There are 2 answers

1
Federico Perez On BEST ANSWER

After some hours I found the problem. It was proguard. Adding the following line fixed the issue.

-keep public class * extends com.google.inject.AnnotationDatabase

You can check that the classes are being generated by running in the project folder:

find . | grep -i AnnotationDatabaseImpl
1
schnatterer On

Did you list your module and your annotation databases in your AndroidManifest.xml?

    <meta-data android:name="roboguice.modules" android:value="your.package.MyModule"/>  
    <meta-data android:name="roboguice.annotations.packages" android:value="com.sample.myapp,com.sample.modulex,com.sample.moduley"/>