我遇到了一个与 AspectJ 的建议有关的奇怪问题。当我将函数(低于private void gotNetType2())声明为由周围建议调用的私有成员函数时,在启动 apk 时,它失败并出现以下错误。
11-04 12:31:56.742: W/dalvikvm(2229): VFY: invoke type does not match method type of Lcom/bright/net/test/NetType2;.gotNetType2
11-04 12:31:56.742: W/dalvikvm(2229): VFY: rejecting opcode 0x6e at 0x0000
11-04 12:31:56.743: W/dalvikvm(2229): VFY: rejected Lcom/xxx/net/test/NetType2;.ajc$inlineAccessMethod$com_xxx_net_test_NetType2$com_xxx_net_test_NetType2$gotNetType2 (Lcom/xxx/net/test/NetType2;)V
11-04 12:31:56.743: W/dalvikvm(2229): Verifier rejected class Lcom/xxx/net/test/NetType2;
....
....
11-04 12:31:56.863: E/AndroidRuntime(2229): FATAL EXCEPTION: main
11-04 12:31:56.863: E/AndroidRuntime(2229): java.lang.VerifyError: com/xxx/net/test/NetType2
11-04 12:31:56.863: E/AndroidRuntime(2229): at com.xxx.main.MainActivity.onCreate(MainActivity.java:1)
11-04 12:31:56.863: E/AndroidRuntime(2229): at android.app.Activity.performCreate(Activity.java:5206)
11-04 12:31:56.863: E/AndroidRuntime(2229): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
11-04 12:31:56.863: E/AndroidRuntime(2229): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2297)
11-04 12:31:56.863: E/AndroidRuntime(2229): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2385)
11-04 12:31:56.863: E/AndroidRuntime(2229): at android.app.ActivityThread.access$600(ActivityThread.java:157)
11-04 12:31:56.863: E/AndroidRuntime(2229): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
11-04 12:31:56.863: E/AndroidRuntime(2229): at android.os.Handler.dispatchMessage(Handler.java:99)
11-04 12:31:56.863: E/AndroidRuntime(2229): at android.os.Looper.loop(Looper.java:153)
11-04 12:31:56.863: E/AndroidRuntime(2229): at android.app.ActivityThread.main(ActivityThread.java:5326)
11-04 12:31:56.863: E/AndroidRuntime(2229): at java.lang.reflect.Method.invokeNative(Native Method)
11-04 12:31:56.863: E/AndroidRuntime(2229): at java.lang.reflect.Method.invoke(Method.java:511)
11-04 12:31:56.863: E/AndroidRuntime(2229): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:848)
11-04 12:31:56.863: E/AndroidRuntime(2229): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:615)
11-04 12:31:56.863: E/AndroidRuntime(2229): at dalvik.system.NativeStart.main(Native Method)
但是在我将函数更改为公共函数(public void gotNetType2())后,错误消失了。我尝试将 sdk 从 1.7 切换到 1.6,并尝试将目标 apk 版本构建为 4.1,与我的 android 手机相同。但是错误仍然存在。
我不知道为什么只有私人功能失败了。有什么建议么?非常感谢。
下面是aspectj代码供大家参考,很简单。
public aspect NetType2 {
public final static String TAG = "NetTypeAspectJ";
pointcut testMainActivity():execution(* com.xxx.main.MainActivity.onCreate(..));
void around():testMainActivity()
{
proceed();
gotNetType2();
}
private void gotNetType2()
{
Log.e(TAG, "hahaha....");
}
}