sensorsdata / sa-sdk-android-plugin2

神策数据官方 Android 埋点插件,用于 Android 端的数据采集。通过使用字节码插桩(ASM)的技术实现 Android 端的全埋点(无埋点、无码埋点、无痕埋点、自动埋点)。
http://opensource.sensorsdata.cn
Other
438 stars 150 forks source link

load class in gradle plugin #12

Closed ethanhua closed 3 years ago

ethanhua commented 3 years ago

the plugin is nice,i have an question when i read the source code, the question is that why you use URLClassLoader for load webview related class, the URLClassLoader created by traverseing transformInvocation which will cost some time, the method Class.forName doesn't meet your needs?

dengshiwei commented 3 years ago

At compile time, Class.forName doesn't work。

GvcZhang commented 3 years ago

ASM just handles class files, so we need a way to check class if a webview‘s children, DiDi's Booster project is using the way. Another way is building the class’s inheritance relationship when traverse class files like TikTok's ByteX does.

ethanhua commented 3 years ago

At compile time, Class.forName doesn't work。

@dengshiwei thank you for your reply. i got it . and can you explain why Class.forName doesn't work in detail? thanks

dengshiwei commented 3 years ago

@ethanhua I think Class.forName is a method of reflection, applicable at runtime, while ASM is a compiler processing bytecode