Eclipse, Maven, AndroidAnnotations: MainActivity_ is generated but not included in apk
I know that there are a few questions here on SO that are quite similar to mine but still none of the answers there could really help me.
The scenario is this: I am using Eclipse + ADT to develop an Android app. I recently moved to Maven for dependency and build management, to make it easier to include Spring for Android, Google Play Services, etc. At the moment building with Maven (from the command line) works but running the app with Eclipse does not work anymore.
- add a new dependency to pom.xml
- do mvn eclipse:eclipse to make the new dependency available in Eclipse (that's the correct to do it, right?)
I get this error: "/foo/gen already exists but is not a source folder. Convert to a source folder or rename it."
I tried several ways of making this error go away, but I all I get is other errors: When I:
- go to Properties > Java Build Path (Source tab) > Add Folder... > check gen > OK > OK
this error is replaced by "The type BuildConfig is already defined".
- go to Properties > Java Build Path (Source tab) > select Foo/target/generated-sources/r > Remove
Ok, no errors now, but when I try to run the app on my device, I get:
"Caused by: java.lang.ClassNotFoundException: Didn't find class "com.bar.foo.MainActivity_" on path: /data/app/com.bar.foo-1.apk
Checking in bin/classes however, I find that MainActivity_.class is indeed generated - but somehow it is not included in the apk, I guess?
Note that the I can also see the classes from my source code, so the following, for example, works:
When I check Properties > Java Build Path (Order and Export tab) I see that the folder /.apt_generated is at the very bottom of the list. Is that a problem?
By the way, the error is exactly the same if I remove all the target folders generated by Maven from the build path so that the build path (Source tab) shows only src, gen and .apt_generated
Is there a way to get this approach - using Maven for dependency and build management but not using any Maven plugins in Eclipse - to work?
Anyway, I also tried the following approach as was suggested here:
I installed Eclipse Maven support by:
- installing m2e from http://download.eclipse.org/technology/m2e/releases
- installing the Eclipse Marketplace
- trying to follow this how-to from m2e-android (SO won't let me post another link)
- I go to Eclipse Marketplace
- type "android m2e"
- find something called "Android Configurator for M2E" (is this same as the "Android Connector"?) and install it
- right click the project > Configure > Convert to Maven project
Then I get an error in my pom.xml - "Plugin execution not covered by life cycle ... com.jayway.maven.plugins.android.generation2"
So, all in all, using the Eclipse plugins for Maven didn't work either...
Is there ANY way to get all of the components in my setup to work together somehow: Eclipse, ADT, Maven, AndroidAnnotations (and optionally m2e and m2e-android)?
You have to install the m2e, m2e-apt and m2e-android plugins for Eclipse. If you have Plugin execution not covered by life cycle errors, just apply the Quick fix for it. This error is shown because m2e-android cannot use AAR libraries, yet. Enable m2e-apt to configure JDT to use the AndroidAnnotations processor, you can read it here. If its done, right click on the project -> Maven -> Update Project. At this point your app should compile, but the generated classes may not included in the APK. To resolve that, modify your .classpath. The correct classpath is here in the workin_cp.xml file.