Skip to content

Commit

Permalink
fix(android): handle webview version for developer builds (#6907)
Browse files Browse the repository at this point in the history
Co-authored-by: colenso <colenso.castellino@gmail.com>
  • Loading branch information
jcesarmobile and colenso committed Sep 15, 2023
1 parent dfe5dc2 commit 3cab84c
Showing 1 changed file with 12 additions and 6 deletions.
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

0 comments on commit 3cab84c

Please sign in to comment.