Inflate exception occurs 'androidx.appcompat:appcompat:1.1.0'

Meyben :

I am trying to upgrade my gradle. When i updated the appcompat from 1.0.2 to 1.1.0, my webview didnt work anymore on certain phones. (api 21 and 22).
Is there a smart way to upgrade to 1.1.0 and still make the webview work.

I get an 'android.view.InflateException: Binary XML file line #1: Error inflating class '. I have tried to find a way to update the webview on my emulators. But i really hope for a code that either way fixes the problem, for users that dont update the webview.

my xml:

<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />

My Activity:

 private WebView mWebView;
    private String state;

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        try {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.login_webview_activity);

            mWebView = findViewById(R.id.webview);

            mWebView.setWebViewClient(new MyBrowser());

            WebSettings settings = mWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setDomStorageEnabled(true);

            CookieManager.getInstance().setAcceptCookie(true);
            CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, true);

            mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

My error:

WebViewActivity: android.view.InflateException: Binary XML file line #1: Error inflating class android.webkit.WebView
        at android.view.LayoutInflater.createView(LayoutInflater.java:633)
        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at no.posten.sporing.controller.activity.WebViewActivity.onCreate(WebViewActivity.java:53)
        at android.app.Activity.performCreate(Activity.java:5937)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)

And again- appcompat 1.0.2 works like a charm, but not 1.1.0.

G00fY :

If you are not relying on DayNight theme switching (or other UiMode events), you can add android:configChanges="uiMode" to the webview activity manifest to prevent AppCompatDelegate updating the Resources configuration and thereby messing up the webview inflation. Found this workaround by studing the sourcecode of the 1.1.0-rc01 to 1.1.0 changes.

Downgrading to 1.1.0-rc01 should also work.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=164781&siteId=1