I am trying to configure AspectJ in Android Studio.
But after all trial and error its not working ! Surprisingly I am able to make it work with Eclipse Kepler version
The steps I followed for Android Studio
Android
ProjectAspectJ
in Plugin section
compile 'org.aspectj:aspectjrt:1.8.1'
to the to the build.gradle (Module:app)Analytics_onBackPressed.aj
for back button press detection
Analytics_OnClick.aj
for click events detection
Analytics_onCreate.aj
for components oncreate event detection
*.aj
classes will internally callMy Question is what is more required to make AspectJ working with Android Studio
Steps followed in Eclipse and got AspectJ working
Eclipse
Kepler versionAspectJ Development Tools (Required)
. Analytics_onBackPressed.aj
for back button press detection
Analytics_OnClick.aj
for click events detection
Analytics_onCreate.aj
for components oncreate event detection
Environment Used
Android Studio : 2.1.2
JRE : 1.8.0
Windows 7 Enterprise
Any help is highly appreciated!
EDIT : 1 , From the output , still AspectJ is not properly configured
As per this link , I created jar file from eclipse including *.aj
files and corresponding dependency. Excluded AndroidManifest.xml
while creating jar file
and created jar
Created Project in Android Studio. Placed this *.jar file in libs file. (apps> libs)
. I have enabled AspectJ waving as shown below
Now searched the properties for AspectJ and enabled
Now running the project, should be creating logs I had put in *.aj
files which is in plugin . Unfortunately these logs are not printed in Android Studio logs.
Form which I am concluding still AspectJ is not enabled in this project OR there is a configuration error
Disclosure: I am the author of the inofficial AspectJ weaver plugin.
As noted in the AspectJ weaver plugin documentation, the plugin does not support compiling .aj
files.
To use this plugin, you have two options:
.aj
to annotation style aspects..aj
files outside the IDE (IntelliJ Community / Android Studio), for example using Maven/Gradle/Ant, and package them into a .jar
. Include this .jar
as a dependency in your project and click the Search for aspects... button, as per the documentation.I have had various success trying to get AspectJ working in Android Studio. This link helped me get part of the way there (assumes Gradle build setup for your project). http://fernandocejas.com/2014/08/03/aspect-oriented-programming-in-android/
Using the custom block of code in the build.gradle
file, I was able to get aspects defined using annotations in .java
files compiling and weaving properly in my project. However, this same method did not work for me when defining native aspects using .aj
files. I hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With