• Stars
    star
    223
  • Rank 178,458 (Top 4 %)
  • Language
    Groovy
  • Created over 8 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A gradle plugin that enables AOP in android.

RoboAspectJ

RoboAspectJ is a Gradle plugin to introduce AspectJ (Aspect-Orient Programming) to Android project. It compiles aspects(if needed) and weave them all together in FULL-PROJECT scope. This means project (or subproject) sources, external libraries and local dependencies will all be dealt with by default.

Note: This plugin may change due to the modification of transform-api. So you may keep track of RoboAspectJ to make sure you're using the most recent version.

latest version: v0.9.1

Prerequisite

Android Plugin (application) 2.1.0

Apply

Add plugin dependency in buildscript classpath:

buildscript {
    dependencies {
        classpath 'com.meituan.gradle:roboaspectj:0.9.+'
    }
}

Apply plugin:

apply plugin: 'com.meituan.roboaspectj'

Coding

There are basically 2 ways to write your aspects and weave them into production code:

As Source

write aspects in @AspectJ syntax under your project's java source directory. e.g. {$projectDir}/src/main/java/

As Library

compile and bundle your aspects independently using ajc, then make it dependency in build script. For example:

compile 'com.example.myaspects:library:1.0'

This way may be a little bit complicated. But it's suitable for those who want to maintain their aspects as an independent project.

Variant-Specific Concern

While RoboAspectJ is registered globally, we still can do our crosscutting concern under specific variant. Actually, this is already done by Android plugin.

As Source

put variant-specific aspects under corresponding folder.

For example, I want to do some performance monitoring in myflavor, so I will write aspects under ${projectDir}/src/myflavor/java/.

As Library

add variant-specific aspects dependency to corresponding configuration scope.

myflavorCompile 'com.example.myaspects:library:1.0'

Configuration

There is an extension aspectj for you to do some tweaking.

Exclude

If you want to leave some artifact untouched from AspectJ, using:

aspectj {
	exclude group: 'com.google.android', module: 'support-v4'
}

Java runtime

When applying rxjava or retrolambda, you may need jrt.jar as classpath. Configure it by:

aspectj {
	javartNeeded true
}

Disable

For debug or performance use, you can disable weaving:

aspectj {
    enable false    //by default, it's true and you don't have to add this statement.
}

alternatively, set roboaspectj.enable property false when run gradle.

$ gradle clean assembleDebug -Droboaspectj.enable=false

Maybe you want it to be smarter to disable it when it's a debug flavor, then add this to your build script:

aspectj {
    disableWhenDebug true // default is false
}

or, specify roboaspectj.disableWhenDebug property.

$ gradle clean assembleDebug -Droboaspectj.disableWhenDebug=true

Though weaving is disabled, Aspects and AspectJ compile dependencies are all still there. It's only the weaving step doesn't happen.

Note: Corresponding property has precedence over config in build script in both of these 2 cases. For instance, weaving will not take effect when your roboaspectj.enable property is false, no matter what you config in build script.

License

Code is under the Apache Licence v2.

Feedback

This plugin is currently a prototype, and it still has much to improve. Feel free to contact: [email protected]

More Repositories

1

YOLOv6

YOLOv6: a single-stage object detection framework dedicated to industrial applications.
Jupyter Notebook
5,702
star
2

WMRouter

WMRouter是一款Android路由框架,基于组件化的设计思路,有功能灵活、使用简单的特点。
Java
2,308
star
3

Meituan-INFORMS-TSL-Research-Challenge

80
star
4

ptubes

Ptubes is a database disaster recovery product based on the PITR (Point In Time Recovery) method, which can be used to restore the entire database to a specific point in time to help users improve the reliability and security of the database
Java
54
star
5

Firefly

Lightweight thrift client code generator and runtime library for Android and Java.
Java
50
star
6

monkey

Data mapping system
JavaScript
42
star
7

mssapi_js

美团云对象存储 Javascript SDK
JavaScript
27
star
8

mssapi_java

美团云对象存储 Java SDK
Java
18
star
9

mcsapi_python

美团云 API Python SDK和客户端
Python
15
star
10

mssapi_python

美团云对象存储 Python SDK
Python
15
star
11

mcsapi_java

美团云 API Java SDK和客户端
Java
11
star
12

mssapi_php

美团云对象存储 PHP SDK
PHP
7
star
13

mssapi_ruby

美团云对象存储 Ruby SDK
Ruby
7
star
14

imghdr

The imghdr module determines the type of image contained in a file or octet streams(obj of Buffer).
JavaScript
6
star
15

mock-response

Response renderer
JavaScript
5
star
16

mcsapi

MOS云主机(MCS)API文档
4
star
17

mock-generator

Random data generator
JavaScript
3
star
18

mock-request

Request parser
JavaScript
3
star
19

mock-template

Template mock data generator
JavaScript
2
star
20

mock-random

Random JSON generator for mock service
JavaScript
2
star
21

mssapi_ruby_gem

美团云对象存储 Ruby SDK Gem版本
Ruby
2
star
22

mock-locator

Resource locator
JavaScript
1
star
23

stub-demo

List of demos of how to use `stub`
JavaScript
1
star
24

stub-proxy

HTTP proxy frontend for monkey
JavaScript
1
star