Coder Social home page Coder Social logo

ryanfu / gradle_plugin_android_aspectjx Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hujiangtechnology/gradle_plugin_android_aspectjx

0.0 1.0 0.0 394 KB

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

License: Apache License 2.0

Groovy 69.35% Java 30.65%

gradle_plugin_android_aspectjx's Introduction

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.8'
        }

OR

using JAR from product. Make new directory named as plugins, and put product/gradle-android-plugin-aspectjx-1.0.8.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:[email protected]

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

gradle_plugin_android_aspectjx's People

Contributors

firefly1126 avatar zzz40500 avatar

Watchers

 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.