GrowingIO踩坑记录

growingIO

前言

GrowingIO无埋点的方式节约了许多埋点时间。但是作为Android开发者,我是反对这种全埋点行为的,原因有三:
1、全埋点,意味着数据的使用者不明确自己需要哪些数据,许多数据是多余的。
2、造成App卡顿,浪费用户手机性能,对用户不负责。
3、平时小心翼翼的写一些精致的代码,节省的一点点性能都被全埋点给浪费了!

踩过的坑

在项目中使用的GrowingIO版本为com.growingio.android:vds-gradle-plugin:RN-autotrack-2.5.0-beta10

bug-list

主线程频繁写数据库造成ANR

错误日志:

ANR Broadcast of Intent { act=android.intent.action.TIME_TICK flg=0x50000014 (has extras) }
com.growingio.android.sdk.data.db.DBAdapter.saveEvent(DBAdapter.java:177)
com.growingio.android.sdk.data.db.DBAdapter.saveEvent(DBAdapter.java:177)
com.growingio.android.sdk.data.DataSubscriber.saveMessage(DataSubscriber.java:141)
com.growingio.android.sdk.data.DataSubscriber.onGIOEvent(DataSubscriber.java:100)
com.growingio.android.sdk.data.DataSubscriber.do$Action(DataSubscriber.java)
com.growingio.eventcenter.bus.Subscription.action(Subscription.java:54)
com.growingio.eventcenter.bus.EventBus.invokeSubscriber(EventBus.java:624)

分析:
1、eventbus分发事件
2、DataSubscriber在主线程接收了GIOEvent事件
3、处理GIOEvent,往数据库写入数据,造成ANR
anr1

频繁SharedPreferences.commit造成ANR

错误日志:

Input dispatching timed out
ANR Input dispatching timed out (Waiting to send key event because the focused window has not finished processing all of the input events that were previously delivered to it. Outbound queue length: 0. Wait queue length: 1.)
com.growingio.android.sdk.collection.GConfig.getAndAddEsidFromSP(GConfig.java:448)
android.app.SharedPreferencesImpl$EditorImpl.commit(SharedPreferencesImpl.java:454)
com.growingio.android.sdk.collection.GConfig.getAndAddEsidFromSP(GConfig.java:448)
com.growingio.android.sdk.collection.GConfig.getAndAddEsid(GConfig.java:440)
com.growingio.android.sdk.data.DataSubscriber.patchEsid(DataSubscriber.java:156)
com.growingio.android.sdk.data.DataSubscriber.saveMessage(DataSubscriber.java:137)
com.growingio.android.sdk.data.DataSubscriber.onGIOEvent(DataSubscriber.java:100)
com.growingio.android.sdk.data.DataSubscriber.do$Action(DataSubscriber.java)

分析:
1、DataSubscriber接收GIOEvent事件
2、处理GIOEvent,判断Event为instantEvent时写入SharedPreferences使用了commit

频繁反射造成ANR

错误日志:

Input dispatching timed out
ANR Input dispatching timed out (Waiting because the touched window has not finished processing the input events that were previously delivered to it.)
com.growingio.android.sdk.autoburry.page.visitor.ListenerInfoVisitor.checkEnv(ListenerInfoVisitor.java:46)
com.growingio.android.sdk.autoburry.page.visitor.ListenerInfoVisitor.checkEnv(ListenerInfoVisitor.java:46)
com.growingio.android.sdk.autoburry.page.visitor.ListenerInfoVisitor.handle(ListenerInfoVisitor.java:28)
com.growingio.android.sdk.autoburry.page.PageObserver$Callback.handleViewGroup(PageObserver.java:137)
com.growingio.android.sdk.autoburry.page.PageObserver$Callback.travelViewTree(PageObserver.java:104)

分析:
1、PageObserver监听到ViewTreeStatusChangeEvent事件
2、执行PageObserver.Callback遍历视图树
3、Callback中调用handleViewGroup,如果不是ViewPager等特定的ViewGroup就会执行ListenerInfoVisitor.handle,handle方法中会反射获取onClickListener。

GrowingIO点击拦截原理

看了jar包里的源码,大概就是这篇文章提到的https://blog.csdn.net/qq_32532321/article/details/80476797

简单总结

第三方SDK不可信。GrowingIO作为付费SDK,反馈问题后能及时修复,但是由于GrowingIO自身没有大规模用户的App,所以接入sdk以后还是需要测试、观察线上情况。