0

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.

BrantApps
  • 6,362
  • 2
  • 27
  • 60
  • A bit more info. I've taken out the dagger-compiler dependency thus the fallback module adapter is being used throughout (ReflectiveAdapter) - this was owing to the sort of issue described [here](https://github.com/square/dagger/issues/266) – BrantApps Jun 30 '13 at 22:25
  • Support library should be compiled, not provided scope. Do you use proguard? – Eugen Martynov Jun 30 '13 at 23:19
  • Hi Eugen, thank you for your comment. I'll set the scope on the support librsry to compile in the morning! Proguard is switched off (see pom) since it breaks Dagger. I checked the "classes.dex" file under the apk and it appeared to have all the correct activities etc. Is there any other bits of info that would assist in diagnosing the problem? Not sure whether I have provided enough detail. – BrantApps Jul 01 '13 at 01:04
  • Perhaps you could post your Dagger module to help diagnose? – jfrey Jul 01 '13 at 10:09
  • @jfrey - I've had a bit more of a play around this morning and noticed that the only affeted classes are those subclassing ActionBarSherlock classes (SherlockActivity, SherlockFragment etc). Thus, I think Dagger is doing fine, and yet again, it's a classpath issue. What do you think? – BrantApps Jul 01 '13 at 10:29

1 Answers1

0

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'.

BrantApps
  • 6,362
  • 2
  • 27
  • 60