GradleAspectJ-Android not working within my app
See original GitHub issueHi I’m on Mac OS X 10.12.6 with Android Studio 2.3.3 and trying to write my own trace functionality so that I can see all of my app’s method calls with arguments on Android and stream them to my computer with adb logcat
. This trace will give me a broad view of the projects I work on to cut through callback hell in Android API.
I tried your example app at https://github.com/Archinamon/AspectJExampleAndroid and it worked (after many blind alleys with AppMon, Frida, etc) thank you for that!
I’ve spent many days searching the web and as far as I can tell, your GradleAspectJ-Android library is the only one that provides a working example for catching all app method calls using aspectj on Android without having to annotate every method.
I even managed to strip out the kotlin
, groovy
, proguard
, dagger
and annotion
stuff, so it simply has these aspectj hooks in Profiler
and MyProfilerImpl
:
before(): catchAny() {
writeEnterTime(thisJoinPointStaticPart);
}
after(): catchAny() {
writeExitTime(thisJoinPointStaticPart);
}
I left me.tatarka.retrolambda
in the project because I wasn’t sure if it was required for detecting anonymous classes (which I use in place of anonymous methods for now).
However, a few things:
Your AppStartNotifier never gets called if I create AspectJExampleAndroid/app/src/main/aspectj/com/archinamon/xpoint/AppStartNotifier.aj with:
import android.app.Application;
import android.app.NotificationManager;
import android.content.Context;
import android.support.v4.app.NotificationCompat;
aspect AppStartNotifier {
pointcut postInit(): within(Application) && execution(* Application.onCreate());
after() returning: postInit() {
Application app = (Application) thisJoinPoint.getTarget();
NotificationManager nmng = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
nmng.notify(9999, new NotificationCompat.Builder(app)
.setTicker("Hello AspectJ")
.setContentTitle("Notification from aspectJ")
.setContentText("privileged aspect AppAdvice")
.setSmallIcon(R.drawable.ic_launcher)
.build());
}
}
You can try it yourself (I don’t know if it’s not detecting the Application.onCreate()
etc). Which means I have no starting point for writing my own aspectj code.
Also, I’ve spent 2 days so far trying to copy your build.gradle
settings to my app and no matter how hard I try, it never calls my Profiler
or MyProfilerImpl
. I’m pretty sure I’ve nested it properly in src/my/app/id/aspectj
but I can’t get it to work. Without a better understanding of how the ajc call works, how aspectj is detecting the app’s methods, and how that gets called from gradle, there’s simply no further I can go with this.
I even tried building issue https://github.com/Archinamon/GradleAspectJ-Android/issues/12 https://github.com/ardmn/TestAspectJApplication but no matter how hard I try, it no longer builds and runs as of Android Studio 2.3.3. If someone can fork that somewhere and get it working, that might give me a starting point.
So without a minimalist app containing an Empty Activity, Basic Activity (or some other example from the Android Studio project stationary) with the addition of your library and a single aspectj example that demonstrates detecting the app’s methods without annotations, developers are going to have a hard time integrating your work. There are simply too many permutations to explore if it doesn’t work.
I’m unable to post my app to GitHub, but do you have any suggestions I can try to show:
- That my Profiler AspectJ code is compiling and running correctly?
- A list of the app’s methods collected by AspectJ, or proof that they are being detected?
Here is a minimal AspectJ method autodetection example, forked from yours with the above steps applied https://github.com/zmorris/AspectJExampleAndroid and even though it works, I can’t get the same build.gradle settings to work within my app.
Thanks in advance for any help you can provide!
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Hello again!
This holydays I’ve made a refine of example project. There has been removed groovy and simplified/updated dependencies. Also added example of new
aspectj-provides
plugin that will bundle since 3.1.0 version. Next I’ll make a separate example with simple tracer/logger aspects basing on your suggestions and fork. Thanks for your help and approach!https://github.com/Archinamon/AndroidAspectJExample2