Subscribe Free

Join 2670+ others. No spamming.
I promise!

We are currently under high development. Follow us at github.


Looking for Python Tutorials?
Check these awesome tutorials



HujiangTechnology/gradle_plugin_android_aspectjx

254

HujiangTechnology / gradle_plugin_android_aspectjx

Groovy

A Android gradle plugin that effects AspectJ on Android project and can hook methods in Kotlin, aar and jar file.


READ ME

aspectjx

A gradle plugin that supports using AspectJ in android project. can weave third party libs and kotlin code

中文版本

why born

There is no perfect AOP tools or framework on android, even though xposed and dexposed are fantastic libs, but not compatible for all Android system versions.And some of the AspectJ plugins can not work well on libs(aar, jar) and kotlin code.

aspectjx takes some great ideas from JakeWharton's project Hugo and uPhyca's gradle-android-aspectj-plugin, and extends the ability to support aar, jar, kotlin. Thanks to JakeWharton and uPhyca.

How to use

Before using aspectjx, Android gradle plugin version must be greater than or equal 1.5.0, and aspectjx must be used in application module, not library module.

i. dependency

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

OR

using JAR from product. Make new directory named as plugins, and put product/gradle-android-plugin-aspectjx-1.0.9.jar in plugins, then do as below:

dependencies {
        classpath fileTree(dir:'plugins', include:['*.jar'])
        //don't lost dependency
        classpath 'org.aspectj:aspectjtools:1.8.+'
        }

ATTENTION: compile 'org.aspectj:aspectjrt:1.8.+' must be added to the modules that contain the AspectJ code, read the Demo

ii. using in application module

apply plugin: 'android-aspectjx'

iii. aspectjx extension configuration

aspectjx will scan and weave all .class file and jar, aar by the default,except for add some filter config includeJarFilter, excludeJarFilter. includeJarFilter, excludeJarFilter can support groupId filter, artifactId filter and dependency path matching.

aspectjx {
    //includes the libs that you want to weave
    includeJarFilter 'universal-image-loader', 'AspectJX-Demo/library'

    //excludes the libs that you don't want to weave
    excludeJarFilter 'universal-image-loader'
}
  • excludes the lib whose groupId is org.apache.httpcomponents
aspectjx {
    excludeJarFilter 'org.apache.httpcomponents'
}
  • exlucdes the lib whose artifactId is gson
    aspectjx {
        excludeJarFilter 'gson'
    }
  • excludes the jar alisdk-tlog-1.jar
    aspectjx {
        excludeJarFilter 'alisdk-tlog-1'
    }
  • excludes all dependency libs
aspectjx {
    excludeJarFilter '.jar'
}

Attention

  • IntelliJ now has no tools for AspectJ, Just Annotation Style AspectJ can work on Android studio. *.aj file can not be compiled . How to use Annotation Style AspectJ
  • AspectJ may not work well on Android studio with Instant Run feature, if so, close the Instant Run feature.
  • AspectJ may compile error as below, just exlcudes the associated lib to resolve it.

  • The Classes and methods that you want to hooked in AOP should not be obfuscated:
package com.hujiang.test;

public class A {
    public boolean funcA(String args) {
        ....
    }
}

//if you want to hook A#funcA(String) in AOP code, keep this class and method in proguard config file

-keep class com.hujiang.test.A {*;}

Tell me what trouble you are in

Click me to know more changes in history

Click me to know what will happen in the future

Reference

Contact

email:xiaoming1109@gmail.com

License

Copyright 2016 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