I'm noticing a strange crash report on production. I've tried to look it up, but I haven't found anything in source code. For me it looks like vendors of these devices just modified something in their SDK.

But it happens in support library. So how can this happen ?

Stacktrace:

Fatal Exception: java.lang.NoSuchMethodError: No interface method build()Landroid/app/Notification; in class Landroid/support/v4/app/NotificationBuilderWithBuilderAccessor; or its super classes (declaration of 'android.support.v4.app.NotificationBuilderWithBuilderAccessor' appears in /data/app/com.myapp-1/base.apk)
   at android.support.v4.app.NotificationCompat$BuilderExtender.build(NotificationCompat.java:469)
   at android.support.v4.app.NotificationCompat$NotificationCompatImplApi21.build(NotificationCompat.java:768)
   at android.support.v4.app.NotificationCompat$Builder.build(NotificationCompat.java:1559)
   at com.myapp.NotificationListener$MyNotification.updateText(MyNotification.java:106)

Code where it happens:

Builder mBuiler = new NotificationCompat.Builder(mContext);

...

private Notification updateText(String title, String message) {
        return mBuidler
                .setContentTitle(title)
                .setContentText(message)
                .setStyle(new BigTextStyle(mBuidler)
                        .bigText(message))
                .build();
}

Reproduces mostly on following devices:

  • Samsung SM-G925F
  • Samsung SM-G935F
  • Samsung GT-I9300
  • Some Lenovo devices
  • Solarin phone (whatever it is)

Operating systems:

  • Android 6 - 95%
  • Android 4 - 3%
  • Android 5 - 2%

I have millions of users and only few of them are getting this crash.

2

There are 2 answers

6
Mahesh Kavathiya On

Please use below code:

NotificationCompat.Builder mBuidler = new NotificationCompat.Builder(this);

Your return method:

private NotificationCompat.Builder updateText(String title, String message) {
    return mBuidler
            .setContentTitle(title)
            .setContentText(message)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
            .build();
}
3
Akram On

This error will happen if you update your android SDK but still using a support-v4 file which belongs to an older version. You can check your build.gradle (if you are using android studio) to see if app-compact library or support-v4 library are set according to your latest SDK update or not. Also, it is possible that one of your Gradle dependencies files are using an older version of support-v4.

If you are using eclipse or some other environment in which you included support-v4.jar, just replace it with the latest one that you have in your SDK folder.