Archinamon / android-gradle-aspectj

gradle plug-in adding supports of AspectJ into Android project
Apache License 2.0
365 stars 58 forks source link

aspects not work for me #12

Closed ardmn closed 8 years ago

ardmn commented 8 years ago

Hello. I'm new in AOP and your plugin is the first try to use AspectJ. I do all like in your guide but not see that my aspect work .

I have TestAspectJ.aj file in ...\app\src\main\aspectj\com\example\aspectj :

package com.example.aspectj;

aspect TestAspectJ{

     pointcut  helloAscpectJ(): execution ( * *(..) );

     before():helloAscpectJ()
     {
        System.out.println("testAspectJ hello");
     }
}

plugin settings:

aspectj {
    binaryWeave true
    weaveTests false
    exclude "com.example.aspectj"
    weaveInfo true
    addSerialVersionUID true
    ignoreErrors true
}

In android studio "Android monitor" window I do not see any messages like "testAspectJ hello" when use my andorid app.

Archinamon commented 8 years ago

Hi!

First of all. You don't need all these options you're trying to use. Please, read their description carefully before enabling any of them. In your case you can remove all options.

I can't say exactly where is your problem. You may have no public methods in your java code. Otherwise declare them or modify the aspect to privileged access. The third point is to investigate through the build/ajc-details.log file, where you'll find details of AJ-compilation process.

ardmn commented 8 years ago

Thank you for advice. I remove all options in build.gradle file for aspectj. Rebuild project. And In ajc-details.log i get :


...many lines like this ...

Join point 'method-execution(void com.example.ui.fragment.TestFragment.testAspectJ())'
 in Type 'com.example.ui.fragment.TestFragment' (TestFragment.java:1424) 
 advised by before advice from 'com.example.aspectj.TestAspectJ' (TestAspectJ.aj:9)

...

[warning] build config error: skipping missing, empty or
 corrupt aspectpath entry: C:\StudioProjects\SampleProject\app\src\debug\aspectj

[warning] build config error: skipping missing, empty or
 corrupt aspectpath entry: C:\StudioProjects\SampleProject\app\src\customflavor\aspectj

[warning] invalid Class-Path header in manifest
 of jar file: C:\StudioProjects\SampleProject\app\libs\Extasys.jar

C:\StudioProjects\SampleProject\app\src\main\aspectj\com\example\aspectj\TestAspectJ.aj:9 [warning] advice defined in 
com.example.aspectj.TestAspectJ has not been applied [Xlint:adviceDidNotMatch]

I have source code folders :

aspectj folder with path \src\main\aspectj

How i can edit(set) aspectpath entry ? Or what I do wrang ?

Thanks.

Archinamon commented 8 years ago

As I see in your logs, joinpoints creates in a right way. So problem may occur within your build-variant config.

invalid Class-Path header in manifest of jar file: C:\StudioProjects\SampleProject\app\libs\Extasys.jar

This error I see first time. You may try to upload your project and share it to me, I'll take a look on it.

ardmn commented 8 years ago

Thank you @Archinamon .I published my project on gitHub.

ardmn commented 8 years ago

@Archinamon Have you some news ?

Archinamon commented 8 years ago

Yes. I was busy with my main work. Just looked up your proj. Everything goes fine until multidex step. After this dex output doesn't contains any aj-injects. Will investigate this problem on holidays.

ardmn commented 8 years ago

Thank you so much :)

Archinamon commented 8 years ago

I'd made some fix within your problem. Please, try 1.3.2 version :) On my local clone of your project everything works fine.

ardmn commented 8 years ago

I'll try it on Monday on a real project and I'll give you feedback

ardmn commented 8 years ago

v1.3.2 looks like work fine for me . Thank you :)