Android 从包发布的错误通知-是否强制在用于生成通知的自定义布局中硬编码值?

Android 从包发布的错误通知-是否强制在用于生成通知的自定义布局中硬编码值?,android,notifications,Android,Notifications,我从Crashlytics获得以下崩溃。不能在本地繁殖 Fatal Exception: android.app.RemoteServiceException: Bad notification posted from package com.abc: Couldn't expand RemoteViews for: StatusBarNotification(pkg=com.abc id=71404926 tag=null score=20 notn=Notification(pri=2 co

我从Crashlytics获得以下崩溃。不能在本地繁殖

Fatal Exception: android.app.RemoteServiceException: Bad notification posted from package com.abc: Couldn't expand RemoteViews for: StatusBarNotification(pkg=com.abc id=71404926 tag=null score=20 notn=Notification(pri=2 contentView=com.eterno/0x7f04016c vibrate=null sound=null defaults=0x0 flags=0x10 kind=[null]) tickerText=पीएम मोदी की पाकिस्तानी बहन राखी बांधने दिल्ली पहुंची contactCharSeq=null when=1502090973664 threadId=0)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1417)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4944)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
   at dalvik.system.NativeStart.main(NativeStart.java)
由于这种情况并非发生在每台设备上,而且堆栈跟踪也没有提供太多信息,因此我提出了导致此崩溃的以下根本原因

  • 我的应用程序中的通知是使用自定义布局准备的。布局参考尺寸作为设置图像徽标边距的
    @dimen/some_值
  • 通知通过
    notify()
    功能发布到
    NotificationManager
  • 同时,应用程序得到更新,并且
    @dimen/some_value
    获得一些其他资源id。(验证了这一点。对于同一资源,两个不同的APK将具有不同的资源id)
  • 当系统试图在StatusBarNotification上绘制通知时,它找不到资源id,因此崩溃
  • 因此,我们的想法是删除引用的变量,并用硬编码字符串替换它

    i、 e替换

    android:layout_marginLeft="@dimen/notification_text_margin_left"
    

    我没有找到任何官方文件告诉我这样做,但找到了答案。我只是想知道这次坠机还有其他原因吗?另外,对于崩溃的修复是否正确


    另外,此崩溃发生在所有手机和所有操作系统版本中。

    添加一些代码,以便我们可以帮助您膨胀
    RemoteView
    android系统正在使用的
    getDimensionPixelOffset
    功能添加一些代码,以便我们可以帮助您膨胀
    RemoteView
    android系统正在使用的
    getDimensionPixelOffset
    函数
    android:layout_marginLeft="20dp"