Code Monkey home page Code Monkey logo

gradle_plugin_android_aspectjx's Introduction

AspectJX

一个基于AspectJ并在此基础上扩展出来可应用于Android开发平台的AOP框架,可作用于java源码,class文件及jar包,同时支持kotlin的应用。

最近更新

v2.0.4

v2.0.2

  • 解决无法识别kotlin写的Aspect文件的Bug

v2.0.0

  • 支持Instant Run编译
  • 废弃 includeJarFilterexcludeJarFilter两个配置命令
  • 新增 includeexclude配置命令,通过包名(package)路径关键字匹配,可过滤class文件和库文件(jar)
  • includeexclude配置命令支持***通配符
  • 修复已知的gradle兼容性Bug
  • 提升编译效率

查看更多版本信息

AspectJX 2.0.0版本与旧版本之间编译性能对比数据

下面的数据来自于同一个项目不同环境下的编译情况 由于旧版本不支持Instant Run增量编译,故没有这块数据

gradle version android plugin version full build(2.0.0/1.1.1 ms) instant run(2.0.0/1.1.1 ms) 性能提升
2.14.1 2.2.0 9761/13213 2596/- +35%
3.3 2.3.0 8133/15306 890/- +88%
4.1 3.0.1 6681/15306 713/- 129%
4.4 3.1.4

如何使用

AspectJX是基于 gradle android插件1.5及以上版本设计使用的,如果你还在用1.3或者更低版本,请把版本升上去。

本使用说明是基于重构后的2.0.0版本编写的,如需要查阅旧版本的README,请切换到对应的Tag。

  • 插件引用

在项目根目录的build.gradle里依赖AspectJX

 dependencies {
        classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.4'
        }

或者使用product目录下的jar包,在你的项目根目录下新建目录plugins,把product/gradle-android-plugin-aspectjx-2.0.0.jar拷贝到plugins,依赖jar包

dependencies {
        classpath fileTree(dir:'plugins', include:['*.jar'])
        }

注意:

  1. 区别于旧版本,离线新版本不再需要依赖org.aspectj:aspectjtools:1.8.+
  2. compile 'org.aspectj:aspectjrt:1.8.+' 必须添加到包含有AspectJ代码的module. 可以参考Demo
  • 在app项目的build.gradle里应用插件
apply plugin: 'android-aspectjx'
//或者这样也可以
apply plugin: 'com.hujiang.android-aspectjx'
  • AspectJX配置

AspectJX默认会处理所有的二进制代码文件和库,为了提升编译效率及规避部分第三方库出现的编译兼容性问题,AspectJX提供include,exclude命令来过滤需要处理的文件及排除某些文件(包括class文件及jar文件)。

注意:2.0.0版本之后旧版本的includeJarFilterexcludeJarFilter命令废弃,不再支持使用

2.0.0版本的 include,exclude通过package路径匹配class文件及jar文件,不再支持通过jar物理文件路径匹配的方式,比如:

支持

aspectjx {
//排除所有package路径中包含`android.support`的class文件及库(jar文件)
	exclude 'android.support'
}

不支持

aspectjx {
	excludeJarFilter 'universal-image-loader'
}

//或者
aspectjx {
	exclude 'universal-image-loader'
}

支持***匹配

aspectjx {
//忽略所有的class文件及jar文件,相当于AspectJX不生效
	exclude '*'
}

提供enabled 开关

enabled默认为true,即默认AspectJX生效

aspectjx {
//关闭AspectJX功能
	enabled false
}

常见问题

  • 问:AspectJX是否支持*.aj文件的编译?

答: 不支持。目前AspectJX仅支持annotation的方式,具体可以参考支持kotlin代码织入的AspectJ Demo

  • 问:编译时会出现can't determine superclass of missing type**及其他编译错误怎么办

答:大部分情况下把出现问题相关的class文件或者库(jar文件)过滤掉就可以搞定了

感谢

  • 开发AspectJX的初衷
  1. 目前的开源库中还没有发现可应用于Android平台的比较好的AOP框架或者工具,虽然xposeddexposed非常强大,但基于严重的碎片化现状,兼容问题永远是一座无法逾越的大山。
  2. 目前其他的AspectJ相关插件和框架都不支持AAR或者JAR切入的,对于目前在Android圈很火爆的Kotlin更加无能为力。
  • 感谢
  1. 该项目的设计参考了大神JakeWhartonHugo项目及uPhycagradle-android-aspectj-plugin项目的设计**,并在它们的基础上扩展支持AAR, JAR及Kotlin的应用。在此感谢JakeWharton和uPhyca.
  2. 感谢热心的AspectJX粉丝及其他使用者的积极反馈,你们提供的PR以及在Issues里提出的问题和答复给大家解决了很多问题,你们都为AspectJX贡献了力量

参考

联系方式

email:[email protected]

QQ:541136835

WeChat:firefly_1126

作者激励

● BTC

18yjhBTjipmDgFezzV9n5B7KynLqZN4osL

● ETH (ERC20 coin support)

0xe36e1877F4e386C314894923c339c28ED4a88536

License

Copyright 2018 firefly1126, Inc.

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.gradle_plugin_android_aspectjx

gradle_plugin_android_aspectjx's People

Contributors

firefly1126 avatar zzz40500 avatar landerlyoung avatar saantiaguilera avatar aifeii avatar muja555 avatar xuyisheng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.