Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent MissingWebViewPackageException #119

Merged
merged 1 commit into from
Jun 11, 2021

Conversation

capezzbr
Copy link
Contributor

@capezzbr capezzbr commented Jun 11, 2021

What does this PR do

When com.google.android.webview is not found by the OS, Fatal Exception: android.util.AndroidRuntimeException: android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed is throw crashing the app.

This PR prevents @react-native-cookies/cookies from throwing such exception, preventing the app from crashing

How to reproduce the crash

  1. Be on a physical device
  2. Open the Settings app and then navigate to All apps > Search for WebView > Disable

How does the PR work

This PR postpone accessing the CookieManager instance (which could throw MissingWebViewPackageException) until when it's necessary, instead of doing when the native module is initialized.

private CookieSyncManager mCookieSyncManager;

CookieManagerModule(ReactApplicationContext context) {
super(context);
this.mCookieSyncManager = CookieSyncManager.createInstance(context);
this.mCookieManager = CookieManager.getInstance();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lazy get CookieManager instance - basically try to only crash when actually using the library

cookieManager.setAcceptCookie(true);
return cookieManager;
} catch (Exception e) {
throw new Exception(e);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it explicit that CookieManager.getInstance can throw

@capezzbr
Copy link
Contributor Author

cc @safaiyeh 🙇

@safaiyeh
Copy link
Member

@capezzbr appreciate the PR! Let's get this deployed.

@safaiyeh safaiyeh merged commit 645f218 into react-native-cookies:master Jun 11, 2021
safaiyeh pushed a commit that referenced this pull request Jun 11, 2021
## [6.0.8](v6.0.7...v6.0.8) (2021-06-11)

### Bug Fixes

* **Android:** Prevent MissingWebViewPackageException ([#119](#119)) ([645f218](645f218))
@safaiyeh
Copy link
Member

🎉 This PR is included in version 6.0.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

@capezzbr capezzbr deleted the patch-1 branch June 14, 2021 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants