A Gradle plugin which enables AspectJ for Android builds.
Supports writing code with AspectJ-lang in .aj files which then builds into annotated java class.
Full support of Android product flavors and build types.
Compilation order:
if (hasRetrolambda)
retrolambdaTask.dependsOn(aspectCompileTask)
else
javaComplieTask.finalizedBy(aspectCompileTask)This workaround is friendly with APT (Android Annotation Processing Tools) and Retrolambda project. AndroidAnnotations, Dagger are also supported and works fine. Butterknife now doesn't support ad could works with bugs and errors. WIP on that problem.
This plugin based on uPhyca's plugin.
First add a maven repo link into your repositories block of module build file:
mavenCentral()
maven { url 'https://github.com/Archinamon/GradleAspectJ-Android/raw/master' }Don't forget to add mavenCentral() due to some dependencies inside AspectJ-gradle module.
Add the plugin to your buildscript's dependencies section:
classpath 'com.archinamon:AspectJ-gradle:1.1.0'Apply the aspectj plugin:
apply plugin: 'com.archinamon.aspectj'To tune logging and error processing just add an extension:
aspectj {
weaveInfo true //turns on debug weaving information
ignoreErrors false //explicitly ignores all aspectJ errors, could break a build
addSerialVersionUID false //adds serialUID for Serializable interface inter-type injections
logFileName "ajc_details.log" //custom name of default weaveInfo file
}Now you can write aspects using annotation style or native (even without IntelliJ IDEA Ultimate edition). Let's write simple Application advice:
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());
}
}- includes all previous progress;
- updated aspectjtools and aspectjrt to 1.8.7 version;
- now has extension configuration;
- all logging moved to the separate file in
app/build/ajc_details.log; - logging, log file name, error ignoring now could be tuned within the extension;
- more complex and correct way to detect and inject source sets for flavors, buildTypes, etc;
- !!IMPORTANT!! now corectly supports automatically indexing and attaching aspectj sources within any buildTypes and flavors;
- workspace code refactored;
- removed unnecessary logging calls;
- optimized ajc logging to provide more info about ongoing compilation;
- migrating from corp to personal routes within plugin name, classpath;
- added full support of buld variants within flavors and dimensions;
- added custom source root folder -- e.g.
src/main/aspectj/path.to.package.Aspect.aj;
- added basic support of additional build varians and flavors;
- trying to add incremental build //was removed due to current implementation of ajc-task;
- configured properly compile-order for gradle-Retrolambda plugin;
- added roots for preprocessing generated files (needed to support Dagger, etc.);
- added MultiDex support;
- Plugin doesn't support direct speach into AspectJ code if project uses preprocessor (e.g. calling aspect class from java);
- No incremental aj-compilation;
- Doesn't support gradle-experimental plugin;
All these limits are fighting on and I'll be glad to introduce new build as soon as I solve these problems.
Copyright 2015 Eduard "Archinamon" Matsukov.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.