How to specify javaagent for Android?

2019-05-30 06:06发布

问题:

Is there any way to specify -javaagent argument when starting an APK on Android? I'd like to specify aspectj's aspectjweaver.jar to java vm argument for a loading time instrumentation. Thanks a lot.

回答1:

No. The Dalvik VM running application code in Android is not a JVM.

Android does, however support instrumentation through Instrumentation classes. You may be able to find a port of aspectj for Android that already supports this, though you may also need to write it yourself.

Don't forget to register your instrumentation class in your manifest if you go down this route.