Search code examples
androidmavenactionbarsherlockandroid-buildandroid-maven-plugin

Maven built .apk with Dagger DI failing to find injected activities


I am attempting to automate the building of my Android application using Maven for Android. The app has the standard Maven folder format with src living under src/main/java and tests living under src/test/java. Confusingly on executing the command, mvn install my app is compiled, tests are run the build is reported as successful.

However, on deploying and running the application on the emulator using the command, mvn android:deploy android:run the application starts but crashes immediately on creating the object graph used for DI by Dagger. The exception states;

06-30 17:31:08.626: E/AndroidRuntime(518): FATAL EXCEPTION: main
06-30 17:31:08.626: E/AndroidRuntime(518): java.lang.RuntimeException: Unable to create application com.oceanlife.MainApplication: java.lang.TypeNotPresentException: Type com.oceanlife.activity.AboutActivity not present
06-30 17:31:08.626: E/AndroidRuntime(518):  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4247)
06-30 17:31:08.626: E/AndroidRuntime(518):  at android.app.ActivityThread.access$3000(ActivityThread.java:125)
06-30 17:31:08.626: E/AndroidRuntime(518):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2071)
06-30 17:31:08.626: E/AndroidRuntime(518):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-30 17:31:08.626: E/AndroidRuntime(518):  at android.os.Looper.loop(Looper.java:123)
06-30 17:31:08.626: E/AndroidRuntime(518):  at android.app.ActivityThread.main(ActivityThread.java:4627)
06-30 17:31:08.626: E/AndroidRuntime(518):  at java.lang.reflect.Method.invokeNative(Native Method)
06-30 17:31:08.626: E/AndroidRuntime(518):  at java.lang.reflect.Method.invoke(Method.java:521)
06-30 17:31:08.626: E/AndroidRuntime(518):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-30 17:31:08.626: E/AndroidRuntime(518):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-30 17:31:08.626: E/AndroidRuntime(518):  at dalvik.system.NativeStart.main(Native Method)
06-30 17:31:08.626: E/AndroidRuntime(518): Caused by: java.lang.TypeNotPresentException: Type com.oceanlife.activity.AboutActivity not present
06-30 17:31:08.626: E/AndroidRuntime(518):  at java.lang.Class.getDeclaredAnnotations(Native Method)
06-30 17:31:08.626: E/AndroidRuntime(518):  at java.lang.Class.getAnnotations(Class.java:322)
06-30 17:31:08.626: E/AndroidRuntime(518):  at java.lang.Class.getAnnotation(Class.java:292)
06-30 17:31:08.626: E/AndroidRuntime(518):  at dagger.internal.plugins.reflect.ReflectivePlugin.getModuleAdapter(ReflectivePlugin.java:51)
06-30 17:31:08.626: E/AndroidRuntime(518):  at dagger.internal.RuntimeAggregatingPlugin.getModuleAdapter(RuntimeAggregatingPlugin.java:98)
06-30 17:31:08.626: E/AndroidRuntime(518):  at dagger.internal.RuntimeAggregatingPlugin.getAllModuleAdapters(RuntimeAggregatingPlugin.java:55)
06-30 17:31:08.626: E/AndroidRuntime(518):  at dagger.ObjectGraph.makeGraph(ObjectGraph.java:115)
06-30 17:31:08.626: E/AndroidRuntime(518):  at dagger.ObjectGraph.create(ObjectGraph.java:103)
06-30 17:31:08.626: E/AndroidRuntime(518):  at com.oceanlife.MainApplication.onCreate(MainApplication.java:36)
06-30 17:31:08.626: E/AndroidRuntime(518):  at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
06-30 17:31:08.626: E/AndroidRuntime(518):  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4244)
06-30 17:31:08.626: E/AndroidRuntime(518):

Following on from my previous questions regarding Maven vs. Eclipse vs. Dagger I have come to expect ClassNotFound type exceptions as the various build systems wrestle with where the compiled classes should live. However, I am completely stumped by this.

My POM is here if that helps...

Thank you in advance, any thoughts graciously received.


Solution

  • Hold your horses...this looks like my Maven build was using the Java 1.7 JDK...this is documented to be bad news for ActionBarSherlock.

    Update: Indeed this was the reason for the funny-ness - I had an additional complication with hamcrest type erasure in my tests (they required 1.7!) which was worked around with advice from the official documentation on the subject.

    So, my mvn build runs with 1.6.0_41 JDK and my tests are compiled with the 1.7.0_15 JDK. At last I have ABS, Maven, Dagger and a multi-module Android project building 'like a boss'.