google / accompanist

A collection of extension libraries for Jetpack Compose
https://google.github.io/accompanist
Apache License 2.0
7.38k stars 596 forks source link

[WebView] MissingWebViewPackageException #1673

Closed kk-atom closed 1 year ago

kk-atom commented 1 year ago
Fatal Exception: android.util.AndroidRuntimeException: android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed
       at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:435)
       at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:252)
       at android.webkit.WebView.getFactory(WebView.java:2551)
       at android.webkit.WebView.ensureProviderCreated(WebView.java:2545)
       at android.webkit.WebView.setOverScrollMode(WebView.java:2613)
       at android.view.View.<init>(View.java:5072)
       at android.view.View.<init>(View.java:5213)
       at android.view.ViewGroup.<init>(ViewGroup.java:676)
       at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:56)
       at android.webkit.WebView.<init>(WebView.java:410)
       at android.webkit.WebView.<init>(WebView.java:353)
       at android.webkit.WebView.<init>(WebView.java:336)
       at android.webkit.WebView.<init>(WebView.java:323)
       at android.webkit.WebView.<init>(WebView.java:313)
       at com.google.accompanist.web.WebViewKt$WebView$13.invoke(WebView.kt:213)
       at com.google.accompanist.web.WebViewKt$WebView$13.invoke(WebView.kt:211)
bentrengrove commented 1 year ago

This looks like the device or emulator you are running on doesn't have a WebView installed.

kk-atom commented 1 year ago

Can You please add a check if WebView is available? Or how can I handle this exception? Try catch is not supported around composable function invocations.

bentrengrove commented 1 year ago

That is a fair request so I'll reopen this issue, you could handle this yourself though by just wrapping the WebView usage in an if

if(getPackageManager().hasSystemFeature("android.software.webview")) {
   WebView()
} else {
   Text("WebView not supported")
}
kk-atom commented 1 year ago

As I understand hasSystemFeature is not reliable because it will return true also when webview is disabled.

bentrengrove commented 1 year ago

Unfortunately Accompanist WebView has been deprecated and won't be supported going forwards. I am closing this issue. We recommend you fork the implemenation here and customise it to your needs. For more information please see our update blog