Error inflating class android.webkit.WebView happens sporadically in production
To fix this problem that appears on Android Lollipop you can use a custom WebView that creates a new configuration only on Android Lollipop (API 21 and 22). Replace the WebView on your XML layout with this custom WebView.
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.util.AttributeSet;
import android.webkit.WebView;
public class LollipopFixedWebView extends WebView {
public LollipopFixedWebView(Context context) {
super(getFixedContext(context));
}
public LollipopFixedWebView(Context context, AttributeSet attrs) {
super(getFixedContext(context), attrs);
}
public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(getFixedContext(context), attrs, defStyleAttr);
}
// To fix Android Lollipop WebView problem create a new configuration on that Android version only
private static Context getFixedContext(Context context) {
if (Build.VERSION.SDK_INT == 21 || Build.VERSION.SDK_INT == 22) // Android Lollipop 5.0 & 5.1
return context.createConfigurationContext(new Configuration());
return context;
}
}
If you see these reports from devices running Android Lollipop, please ignore them. This likely happens whenever something launches an activity that uses WebView while the WebView package is in the middle of being updated by Play Store (which can only happen on Lollipop currently). During updates, packages are treated as not installed by the package manager. That is, there is nothing wrong with your app. The time window while the updated package is considered non-existent is typically small, so when the app is relaunched after such a crash, it will start normally.