Skip to content
New issue

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

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

Already on GitHub? # to your account

fix(android): handle webview version for developer builds #6911

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions android/capacitor/src/main/java/com/getcapacitor/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.cordova.ConfigXmlParser;
import org.apache.cordova.CordovaPreferences;
import org.apache.cordova.CordovaWebView;
Expand Down Expand Up @@ -290,14 +292,18 @@ public boolean isMinimumWebViewInstalled() {
// Check getCurrentWebViewPackage() directly if above Android 8
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
PackageInfo info = WebView.getCurrentWebViewPackage();
if (info.packageName.equals("com.huawei.webview")) {
String majorVersionStr = info.versionName.split("\\.")[0];
Pattern pattern = Pattern.compile("(\\d+)");
Matcher matcher = pattern.matcher(info.versionName);
if (matcher.find()) {
String majorVersionStr = matcher.group(0);
int majorVersion = Integer.parseInt(majorVersionStr);
return majorVersion >= config.getMinHuaweiWebViewVersion();
if (info.packageName.equals("com.huawei.webview")) {
return majorVersion >= config.getMinHuaweiWebViewVersion();
}
return majorVersion >= config.getMinWebViewVersion();
} else {
return false;
}
String majorVersionStr = info.versionName.split("\\.")[0];
int majorVersion = Integer.parseInt(majorVersionStr);
return majorVersion >= config.getMinWebViewVersion();
}

// Otherwise manually check WebView versions
Expand Down