0

I have been using ButterKnife successfully to inject views in my application like so:

@InjectView(android.R.id.text1)
TextView mMessageText;
@InjectView(android.R.id.button1)
ImageView mButton;
... then later...
View.inflate(ctx, R.layout.layout_message_with_button, this);
ButterKnife.inject(this);
mMessageText.setText("Some Text");

This morning I integrated MonkeyTalk for some testing, and my injections now seem to be busted. I've removed/readded annotation processing for ButterKnife, but that didn't seem to fix the problem. Using findViewById fixed the issue (the views were found), but changing the project to use findViewById directly isn't really an option at this point.

I wasn't able to find any information about conflicts between the libraries (or using AspectJ with ButterKnife in general), so hopefully someone here can help provide some insight into what I might be doing wrong (or if they are just in general incompatible).

I am using ButterKnife 4.0.1 and MonkeyTalk Agent 2.0.9

UPDATE: I have also tried changing the build order of the libraries in the Eclipse project properties, but this also doesn't seem to help.

UPDATE: I narrowed it down to the generated files not being created in ButterKnife. It appears to be related to Annotation processing not happening in the org.eclipse.ajdt.core.ajbuilder. When I add org.eclipse.jdt.core.javabuilder to the .project as suggested here : https://bugs.eclipse.org/bugs/show_bug.cgi?id=169857, the classes are generated, but I'm getting NoClassDefFoundError at run time on .ajc files. Any idea how to get the annotation processor to run in the ajbuilder? That seems to be the correct solution for my problem.

UPDATE: From this post (http://andrewclement.blogspot.ca/2014/08/annotation-processing-in-ajdt.html), it appears that Aspects and Annotations can be processed in the same project using Eclipse 4.4. It seems, however, that the combination of ADT 23 + Eclipse 4.4 + AspectJ is pretty unstable (and doesn't appear to generate the code from ButterKnife's Annotations anyway). Anyone know if Android Studio would be any help here?

UPDATE: I converted my project to Android Studio and it looks like both the Aspects and the Annotations are working. I know I'm still not doing something right with the Aspects, since they weren't processing until I added Jake Wharton's Hugo library to the Android project.

frenziedherring
  • 2,225
  • 2
  • 15
  • 23
  • I wanted to check what version of AJDT you are on - is it AJDT 2.2.3 and that is from the dev update site: http://download.eclipse.org/tools/ajdt/44/dev/update because the last released version of AJDT doesn't have an AspectJ in that can process annotations. I will say the annotation processing support in AJ is very new but if the java builder picks up on the annotation processor in your library then the aspectj builder should too. – Andy Clement Oct 14 '14 at 14:48
  • I think that should say 2.2.4 and not 2.2.3 - 2.2.3 is the last released version. 2.2.4 are the dev builds for Eclipse 4.4. – Andy Clement Oct 14 '14 at 16:06
  • The version I'm using was from that update site. I think in the case of Eclipse 4.4 + AJDT it was the addition of the Android Development Tools that was causing the instability. As a test I ended up porting everything to Android Studio and it seemed to be able to process both Aspects and Annotations, though I'm not 100% sure exactly what I did to enable that. Seems like on the Eclipse side I would need 3.8/ADT/AJDT (no annotations from AJDT) or 4.4/ADT/AJDT (no ADT that is stable for 4.4). I might go back to this problem later when I have time – frenziedherring Oct 15 '14 at 17:23

0 Answers0