From 3cab84c50520e6a3042c7ff0c37cd788020f53a0 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Fri, 15 Sep 2023 17:11:51 +0200 Subject: [PATCH] fix(android): handle webview version for developer builds (#6907) Co-authored-by: colenso --- .../src/main/java/com/getcapacitor/Bridge.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java index 64c769f9a..0e732a99f 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java +++ b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java @@ -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; @@ -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