Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GradleAspectJ-Android not working within my app

See original GitHub issue

Hi 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 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() {

after(): catchAny() {

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.content.Context;

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")

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 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 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:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

Archinamoncommented, Oct 8, 2017

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

When I apply AspectJ to Android project with ... - Stack Overflow
1 Answer 1 ; maven { url ' · ' }. Add the plugin to your buildscript's dependencies section: ; classpath 'com.archinamon:AspectJ-gradle:1.0.15'. Apply...
Read more >
How to use android gradle aspectj plugin? - Buildship
Import application in the workspace along with all libraries. · Right click on main project – export – android- generate gradle build file...
Read more >
vincentbrison / GradleAspectJ-Android Download - JitPack
A Gradle plugin which enables AspectJ for Android builds. Supports writing code with AspectJ-lang in .aj files and in java-annotation style.
Read more >
AspectJ - David Wong's Blog
In the first part of this post, I showed some ways that AspectJ would be useful in android development when it comes to...
Read more >
Switching AspectJ Plugins in Android | JD Porterfield | Articles
This is because the aspects that you write when using the android-gradle-aspectj plugin, for example, are referencing classes within the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found