最近用极光推送,发现有新的SDK,就试试用.我的手机是Nexus 6P,原生8.0,结果一更新,手机就不断闪屏,系统崩溃,说要恢复出厂设置了


Android 8.0接收通知后会手机崩溃,闪屏,恢复出厂设置的解决方法_java


Android 8.0接收通知后会手机崩溃,闪屏,恢复出厂设置的解决方法_ico_02

幸亏重启前截停了.然后求助极光推送,可得到的答复不是SDK的问题,碰巧也有人碰到这问题,但他说他的解决方法是在drawable-xxxx各分辨率下加上jpush_notification_icon.png就可以避免了.可我试了不行.郁闷啊.一天重启几十遍.也跟着官方的SDK那样配置,一样还是不行.


主要出的系统log(不是app的log)在这里

[plain]  view plain  copy



1. <span >E/AndroidRuntime: FATAL EXCEPTION: main  
2. Process: com.android.systemui, PID: 10388  
3. java.lang.IllegalArgumentException: width and height must be > 0  
4. at android.graphics.Bitmap.createBitmap(Bitmap.java:1001)  
5. at android.graphics.Bitmap.createBitmap(Bitmap.java:968)  
6. at android.graphics.Bitmap.createBitmap(Bitmap.java:918)  
7. at android.graphics.Bitmap.createBitmap(Bitmap.java:879)  
8. at android.graphics.drawable.AdaptiveIconDrawable.updateMaskBoundsInternal(AdaptiveIconDrawable.java:333)  
9. at android.graphics.drawable.AdaptiveIconDrawable.updateLayerBounds(AdaptiveIconDrawable.java:295)  
10. at android.graphics.drawable.AdaptiveIconDrawable.onStateChange(AdaptiveIconDrawable.java:782)  
11. at android.graphics.drawable.Drawable.setState(Drawable.java:775)  
12. at android.widget.ImageView.drawableStateChanged(ImageView.java:1305)  
13. at android.view.View.refreshDrawableState(View.java:20012)  
14. at android.view.View.dispatchAttachedToWindow(View.java:17409)  
15. at android.view.ViewGroup.addViewInner(ViewGroup.java:4955)  
16. at android.view.ViewGroup.addView(ViewGroup.java:4746)  
17. at com.android.systemui.statusbar.phone.NotificationIconAreaController.updateIconsForLayout(NotificationIconAreaController.java:247)  
18. at com.android.systemui.statusbar.phone.NotificationIconAreaController.updateNotificationIcons(NotificationIconAreaController.java:155)  
19. at com.android.systemui.statusbar.phone.StatusBar.updateNotificationShade(StatusBar.java:1956)  
20. at com.android.systemui.statusbar.phone.StatusBar.updateNotifications(StatusBar.java:2136)  
21. at com.android.systemui.statusbar.phone.StatusBar.addNotificationViews(StatusBar.java:6702)  
22. at com.android.systemui.statusbar.phone.StatusBar.addEntry(StatusBar.java:1627)  
23. at com.android.systemui.statusbar.phone.StatusBar.onAsyncInflationFinished(StatusBar.java:1644)  
24. at com.android.systemui.statusbar.notification.NotificationInflater$AsyncInflationTask.onAsyncInflationFinished(NotificationInflater.java:641)  
25. at com.android.systemui.statusbar.notification.NotificationInflater.finishIfDone(NotificationInflater.java:460)  
26. at com.android.systemui.statusbar.notification.NotificationInflater.-wrap0(Unknown Source:0)  
27. at com.android.systemui.statusbar.notification.NotificationInflater$6.onViewApplied(NotificationInflater.java:343)  
28. at android.widget.RemoteViews$AsyncApplyTask.onPostExecute(RemoteViews.java:3421)  
29. at android.widget.RemoteViews$AsyncApplyTask.onPostExecute(RemoteViews.java:3401)  
30. at android.os.AsyncTask.finish(AsyncTask.java:695)  
31. at android.os.AsyncTask.-wrap1(Unknown Source:0)  
32. at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)  
33. at android.os.Handler.dispatchMessage(Handler.java:105)  
34. at android.os.Looper.loop(Looper.java:164)  
35. at android.app.ActivityThread.main(ActivityThread.java:6541)  
36. at java.lang.reflect.Method.invoke(Native Method)  
37. at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)  
38. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)</span>


后来终于有官方的技术人员解答了这个问题. 原来是系统的bug, 原贴在这里:

https://blog.pusher.com/upgrade-app-android-oreo-avoid-factory-reset/

如果你也有这个问题,你看看你新建的项目的资源文件目录里是不是有个mipmap-anydpi-v26的目录?里面有icon的xml文件? 处理的方法有三种,要么target SDK低于26或者不用这个icon,把这目录里面的icon的xml删掉.或者在manifest里加meta-data,


[html] 
   view plain
    copy
   
   
 
1. <span style="font-size:12px;"><meta-data  
2. android:name="com.google.firebase.messaging.default_notification_icon"  
3. android:resource="@drawable/your_non_adaptive_drawable" /></span>

不过我自己试过加meta-data,还是不行.所以最简单的方法就是把那些icon的xml删了就是了.希望遇到这问题的各位也能顺利解决,我就困扰了两天,重启了4,50次了