Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Gradle_plugin_android_aspectjx | 3,499 | 2 years ago | 145 | apache-2.0 | Groovy | |||||
A Android gradle plugin that effects AspectJ on Android project and can hook methods in Kotlin, aar and jar file. | ||||||||||
Argusapm | 2,106 | 4 years ago | 29 | apache-2.0 | Java | |||||
Powerful, comprehensive (Android) application performance management platform. 360线上移动性能检测平台 | ||||||||||
Sa Sdk Android Plugin2 | 379 | 7 days ago | 69 | October 24, 2022 | 6 | apache-2.0 | Kotlin | |||
神策数据官方 Android 埋点插件,用于 Android 端的数据采集。通过使用字节码插桩(ASM)的技术实现 Android 端的全埋点(无埋点、无码埋点、无痕埋点、自动埋点)。 | ||||||||||
Android Gradle Aspectj | 342 | a year ago | 36 | apache-2.0 | Kotlin | |||||
gradle plug-in adding supports of AspectJ into Android project | ||||||||||
Awesome Android Architecture | 303 | 3 months ago | 1 | apache-2.0 | ||||||
:rocket: Android 架构师成长之路(进行中~) | ||||||||||
Gradle Android Aspectj Plugin | 273 | 6 years ago | 2 | apache-2.0 | Java | |||||
A Gradle plugin which enables AspectJ for Android builds. | ||||||||||
Roboaspectj | 219 | 7 years ago | 4 | apache-2.0 | Groovy | |||||
A gradle plugin that enables AOP in android. | ||||||||||
Jaop | 113 | 5 years ago | apache-2.0 | Java | ||||||
jaop is a gradle plugin base on javassist&asm for android aop | ||||||||||
Aspectj Maven Plugin | 98 | 22 | 2 | a day ago | 17 | July 29, 2021 | 15 | mit | Java | |
Sbt Aspectj | 74 | 5 years ago | 9 | Scala | ||||||
AspectJ sbt plugin |
A Gradle plugin which enables AspectJ for Android builds.
Supports writing code with AspectJ-lang in .aj
files and in java-annotation style.
Full support of Android product flavors and build types.
Support Kotlin, Groovy, Scala and any other languages that compiles into java bytecode.
Actual version supporting of AGP 4.1.+: com.archinamon:android-gradle-aspectj:4.3.0
.
Friendly with jRebel for Android!
This plugin is completely friendly with APT (Android Annotation Processing Tools) and Retrolambda project (but Java 8 not supported in .aj files). AndroidAnnotations, Dagger are also supported and works fine.
This plugin has many ideas from the others similar projects, but no one of them grants full pack of features like this one. Nowadays it has been completely re-written using Transform API.
Augments Java, Kotlin, Groovy bytecode simultaneously!
Works with background mechanics of jvm-based languages out-of-box!
How to teach Android Studio to understand the AspectJ!
May not work properly for AS 3.0 :(
It is easy to isolate your code with aspect classes, that will be simply injected via cross-point functions, named advices
, into your core application. The main idea is — code less, do more!
AspectJ-Gradle plugin provides supply of all known JVM-based languages, such as Groovy, Kotlin, etc. That means you can easily write cool stuff which may be inject into any JVM language, not only Java itself! :)
To start from you may look at my example project. And also you may find useful to look at reference manual of AspectJ language and simple code snippets. In case aspectj-native not supported by Android Studio (even with IDE-plugin it's using is complicated), you may write a java-classes with aspectj annotations.
Two simple rules you may consider when writing aspect classes.
src/$flavor/aspectj
source set! These aj-classes will be excluded from java compiler.These rules affects only in case you're writing in native aj-syntax. You may write aspects in java-annotation style and being free from these limitations.
First add a maven repo link into your repositories
block of module build file:
mavenCentral()
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:android-gradle-aspectj:4.3.0")
classpath 'com.archinamon:android-gradle-aspectj:4.3.0'
plugins {
id("com.android.application")
id("com.archinamon.aspectj")
}
plugins {
id 'com.android.application'
id 'com.archinamon.aspectj'
}
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());
}
}
aspectj {
compileTests = true // default value
ajc = "1.9.4" // default value
java = JavaVersion.VERSION_1_7 // default value
/* @see Ext plugin config **/
includeAllJars = false // default value
includeJar.addAll(arrayOf("design", "support-v4", "dagger")) // default is empty
excludeJar.addAll(arrayOf("support-v7", "joda")) // default is empty
extendClasspath = true // default value
includeAspectsFromJar.addAll(arrayOf("my-aj-logger-lib", "any-other-libs-with-aspects")) // default is empty
ajcArgs.apply {
add("-warn:deprecation")
add("-referenceInfo")
}
weaveInfo = true // default value
debugInfo = false // default value
addSerialVersionUID = false // default value
noInlineAround = false // default value
ignoreErrors = false // default value
breakOnError = true // default value
experimental = false // default value
buildTimeLog = true // default value
transformLogFile = "ajc-transform.log" // default value
compilationLogFile = "ajc-compile.log" // default value
}
aspectj {
dryRun false // default value
compileTests true // default value
ajc '1.9.4' // default value
java = JavaVersion.VERSION_1_7 // default value
/* @see Ext plugin config **/
includeAllJars false // default value
includeJar 'design', 'support-v4', 'dagger' // default is empty
excludeJar 'support-v7', 'joda' // default is empty
extendClasspath true // default value
includeAspectsFromJar 'my-aj-logger-lib', 'any-other-libs-with-aspects' // default is empty
ajcArgs << '-referenceInfo' << '-warn:deprecation'
weaveInfo true // default value
debugInfo false // default value
addSerialVersionUID false // default value
noInlineAround false // default value
ignoreErrors false // default value
breakOnError true // default value
experimental false // default value
buildTimeLog true // default value
transformLogFile 'ajc-transform.log' // default value
compilationLogFile 'ajc-compile.log' // default value
}
All the extension parameters are have default values (all of them are described above, except of includeJar/Aspects/ajcArgs options). So no need to define them manually.
compileTests
Workaround to disable compileDebugUnitTestAspectJ
for unitTest variant
ajc
Allows to define the aspectj runtime jar version manually (1.8.12 current)
java
What jvmTarget will ajc use to compile bytecode into
extendClasspath
Explicitly controls whether plugin should mutate the classpath with aspectj-runtime itself
includeAllJars
Explicitly include all available jar-files into -inpath to proceed by AJ-compiler
includeJar
Name filter to include any jar/aar which name or path satisfies the filter
excludeJar
Name filter to exclude any jar/aar which name or path satisfies the filter
includeAspectsFromJar
Name filter to include any jar/aar with compiled binary aspects you wanna affect your project
ajcExtraArgs
Additional parameters for aspectj compiler
weaveInfo
Enables printing info messages from Aj compiler
debugInfo
Adds special debug info in aspect's bytecode
addSerialVersionUID
Adds serialVersionUID field for Serializable-implemented aspect classes
noInlineAround
Strict ajc to inline around advice's body into the target methods
ignoreErrors
Prevent compiler from aborting if errors occurs during processing the sources
breakOnError
Allows to continue project building when ajc fails or throws any errors
experimental
Enables experimental ajc options: -XhasMember
and -Xjoinpoints:synchronization,arrayconstruction
. More details in issue #18
buildTimeLog
Appends a BuildTimeListener to current module that prints time spent for every task in build flow, granularity in millis
transformLogFile
Defines name for the log file where all Aj compiler info writes to, new separated for Transformer
compilationLogFile
Defines name for the log file where all Aj compiler info writes to, new separated for CompileTask
plugins {
id("com.android.application")
id("com.archinamon.aspectj-ext")
}
plugins {
id 'com.android.application'
id 'com.archinamon.aspectj-ext'
}
Currently it has some limitations:
InstantRun
must be switched off (Plugin detects IR status and fails build if IR will be found).plugins {
id("com.android.application")
id("com.archinamon.aspectj-provides")
}
plugins {
id 'com.android.application'
id 'com.archinamon.aspectj-provides'
}
You ain't limited to describe as much provider-modules as you need and then include them using includeAspectsFromJar
parameter in the module which code or dependencies you may want to augment.
With example project you could learn how to write such provider-module.
plugins {
id("com.android.application")
id("com.archinamon.aspectj-dryRun")
}
plugins {
id 'com.android.application'
id 'com.archinamon.aspectj-dryRun'
}
plugins {
id("com.android.application")
id("com.archinamon.aspectj-junit")
}
plugins {
id 'com.android.application'
id 'com.archinamon.aspectj-junit'
}
Correct tuning will depends on your own usage of aspect classes. So if you declares inter-type injections you'll have to predict side-effects and define your annotations/interfaces which you inject into java classes/methods/etc. in proguard config.
Basic rules you'll need to declare for your project:
-adaptclassstrings
-keepattributes InnerClasses, EnclosingMethod, Signature, *Annotation*
-keepnames @org.aspectj.lang.annotation.Aspect class * {
ajc* <methods>;
}
If you will face problems with lambda factories, you may need to explicitly suppress them. That could happen not in aspect classes but in any arbitrary java-class if you're using Retrolambda. So concrete rule is:
-keep class *$Lambda* { <methods>; }
-keepclassmembernames public class * {
*** lambda*(...);
}
project.task()
;-PdryRunAjc=true
;aspectj-ext
plugin to work properly with transform api;com.archinamon.aspectj-junit
plugin supporting weaving unit tests;com.archinamon.aspectj-test
has been removed as not working legacy sh$t;aspectj-ext
plugin;provides
plugin split to effectively extract aspects to external/sub modules;includeJar
parameter now able to read aar's manifest file to exactly detect required library;com.archinamon.aspectj-ext
plugin added to properly weave inpath jars, in this mode InstantRun doesn't allowed;/aspectj
folder;/build/aspectj/$variantName
folder for aspects class';updated
2.2.0 artifacts;AspectJ-gradle
to android-gradle-aspectj
;weaveTests
;app/build/ajc_details.log
;src/main/aspectj/path.to.package.Aspect.aj
;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.