使用AspectJ拦截android中的第三方功能 [英] Intercepting third party functions in android using AspectJ

查看:60
本文介绍了使用AspectJ拦截android中的第三方功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用AspectJ拦截属于我的应用程序的所有第三方功能,但是以某种方式只能拦截由我声明的功能,而不能拦截由第三方库声明的功能.

I have been trying to intercept all the third party functions which are part of my application using aspectJ, but somehow am only able to intercept the functions declared by me and not the ones declared by third party libraries.

我正在使用从本教程引用的aspectJ gradle配置.

这是我的表情:

private static final String POINTCUT_METHOD = "execution(* *(..))";

@Pointcut(POINTCUT_METHOD) 
public void methodAnnotatedWithDebugTrace() {}

@Around("methodAnnotatedWithDebugTrace()") 
public Object weaveJoinPoint(ProceedingJoinPoint joinPoint) 
            throws Throwable { 
    // ...
}

还有什么方法可以开始拦截第三方功能?

Is there any way by which we can start intercepting third party functions as well ??

推荐答案

释义多次给出的另一个答案:

To paraphrase another answer that has been given multiple times :

您只能编织自己的代码

You can only weave your own code

基本上,Android的Aspects仅在编译时有效,并且通常会编织您自己的代码.如果您使用的是没有源代码的现有代码(例如Android框架),则编译器将无权修改这些代码.就您而言,您只能在代码访问第三方库时捕获.

Basically Aspects with android only works at compile time and will usually weave your own code. If you're using existing code for which you don't have source (like the Android framework for example), the compiler won't have access to modify those. In your case, you can only catch when your code is accessing the third party library.

意味着,如果要拦截第三方库,则需要使用"call(* *(..))" 而不是"execution(* *(..))"

Meaning that if you want to intercept third party libraries you need to use "call(* *(..))" instead of "execution(* *(..))"

这篇关于使用AspectJ拦截android中的第三方功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆