2

I want to try and use AspectJ as part of an android library project. I tried creating an android library project and used annotation based style to create pointcuts.

The problem is that the aspects of the library project does not get weaved into the android application which has added my library project.

My Android library project has few aspects defined in it. Something like

@AfterReturning(pointcut = "execution(* *.*(..)) && !this(com.xyz.aspects.xyz)")
public void abc(JoinPoint jp) 
{ 
    dosomething;
}

I've added this library project to my android application. However the 'dosomething' is not executed. Any advices?

Deepak
  • 1,347
  • 7
  • 20

2 Answers2

3

Finally fixed this. I added the library project to my aspect path and things started to work.

Deepak
  • 1,347
  • 7
  • 20
  • 2
    Can you tell me how thats done ? having the same issue right now – Joel Dean Jul 02 '15 at 00:23
  • I had added the aspectj plugin for eclipse to weave in the code. Right now there are much better ways to do it. Checkout : https://github.com/uPhyca/gradle-android-aspectj-plugin – Deepak Mar 04 '16 at 12:11
  • I figured it out . That's my answer http://stackoverflow.com/questions/31142125/aspectj-with-android-library/31225630#31225630 – Joel Dean Mar 04 '16 at 14:42
1

How about

execution(* *(..)) && !within(com.xyz.aspects.xyz..*)

I have not tested it, just quickly written it with my iPad, but maybe it helps. Keep me updated if it does not.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • Yes, it will - unless you have a problem in your Spring or AspectJ configuration, which still you have not posted. Does aspect weaving work with ANY kind of pointcut/advice? The pointcut code you posted is definitely wrong! – kriegaex Apr 10 '13 at 09:46
  • Why wouldnt that work?. Its perfectly working on my android project. I can see that its getting woven. But anyways, the question is how do I use annotation based aspects to be woven into an android project by using normal java compiler – Deepak Apr 16 '13 at 14:46
  • Because your `this` pointcut seems to be a package name. It should be (or match) a class name. – kriegaex Apr 16 '13 at 17:42
  • com.xyz.aspects.xyz was intended to be a class name placeholder. Any idea how to compile annotation based aspects via normal java compiler. Can you give me a sample code ? – Deepak Apr 17 '13 at 12:19
  • Because your class name started with a lower-case letter, I thought that by convention you meant a package. As for the other question: Yes, I can, when I am back home in a few days. – kriegaex Apr 17 '13 at 17:57
  • Will be looking forward to that. Thanks in advance – Deepak Apr 18 '13 at 11:51