一.問題
之前因為facebook的SDK許久未更新
我們把Facebook SDK從4.11.0更新到4.30.0
compile 'com.facebook.android:facebook-login:4.30.0'
compile 'com.facebook.android:account-kit-sdk:4.30.0'
遇到了很多下面的這個問題
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'org.json.JSONArray org.json.JSONObject.getJSONArray(java.lang.String)' on a null object reference
at com.facebook.accountkit.internal.ExperimentationConfigurator$2$1.onCompleted(SourceFile:93)
at com.facebook.accountkit.internal.AccountKitGraphRequestAsyncTask.onPostExecute(SourceFile:188)
at com.facebook.accountkit.internal.AccountKitGraphRequestAsyncTask.onPostExecute(SourceFile:42)
at android.os.AsyncTask.finish(AsyncTask.java:651)
at android.os.AsyncTask.access$500(AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
二.解決方案
1.是追溯調(diào)用棧的信息。
發(fā)現(xiàn)即使看不到調(diào)用棧,也追溯到了AccountKit.initialize()
方法會間接的調(diào)用到了Crash的代碼位置嘁锯。
2.查看自己代碼
果然有AccountKit.initialize()
的相關(guān)調(diào)用持灰〕耐ⅲ可是已經(jīng)@Deprecated
穿稳。
然后去官網(wǎng)查了一下Changelog:
Facebook SDK for Android Changelog 4.x
調(diào)查發(fā)現(xiàn)在4.11.0-4.30.0之間的Changelog中有這樣一段
4.19.0 - January 25, 2017
Facebook SDK
Modified
Facebook SDK is now auto initialized when the application starts. In most cases a manual call to FacebookSDK.sdkInitialize() is no longer needed. See upgrade guide for more details.
Activate App is now called during SDK initialization. To disable this feature please follow the directions in the upgrade guide.
Update the look and feel of LoginButton. See upgrade guide for more details.
Fixed
Possible memory leak in ActivityLifecycleTracker
Audience Network SDK
Added
Foregrounding/backgrounding listeners added to MediaView.
Fixed
Crash in NativeAdsManager fixed for Android API < 18.
onComplete method in MediaViewListener is now properly called when video playback finishes.
Crash when launching In-App Browser due to unsupported protocols.
Account Kit SDK
Modified
Account Kit SDK is now auto initialized when the application starts. In most cases a manual call to AccountKit.initialize() is no longer needed. See upgrade guide for more details.
Default Account Kit Instant Verification button as "Continue"
Fixed
Fixes crash bug where Android 7+ will throw exception if a file is marked WORLD_
Back arrow theming in entry screen
Setting focus on first entry field in confirmation code entry screen
VI translations
Checking permissions behavior on certain devices
Added
Logging for country codes
其中呢做葵,注意到2條汹买。4.19.0這個版本之后点弯。AccountKit.initialize()
,FacebookSdk.sdkInitialize(ctx);
都已經(jīng)@Deprecated
掉了仁锯。查看sdk源碼獲知妥泉,SDK已經(jīng)通過AccountKitInitProvider
,FacebookInitProvider
兩個ContentProvider的方式,在更早的時間節(jié)點完成了初始化它改。所以就不用我們手動初始化了侵贵。抱著試試看的想法,去掉了贴彼。無用的初始化調(diào)用潜腻。結(jié)果BUG量直線下降。雖然fabric上還有個別情況發(fā)生器仗。但是已經(jīng)不再是Rank榜第一了融涣。
雖然還是想不通。多調(diào)用一次init為什么會導(dǎo)致這樣的問題精钮。但還是算先改掉了這個BUG吧威鹿。
3.統(tǒng)計自動調(diào)用。
當(dāng)然這個也不需要手動調(diào)用了轨香。
AppEventsLogger.activateApp(this);