Closed ryaa closed 7 months ago
@ryaa The PR above doesn't solved my problem. The problem still persist and even after I downgrade to 5.7.0 and 5.6.0. Help
If I revert to the following code, the app build works.
String js = "<script type=\"text/javascript\">" + getScriptString() + "</script>"; String html = this.readAssetStream(responseStream); if (html.contains("<head>")) { html = html.replace("<head>", "<head>\n" + js + "\n"); } else if (html.contains("</head>")) { html = html.replace("</head>", js + "\n" + "</head>"); } else { Logger.error("Unable to inject Capacitor, Plugins won't work"); } return new ByteArrayInputStream(html.getBytes(StandardCharsets.UTF_8));
If I revert to the following code, the app build works.
The problem that PR fixes is not related to the app build but it fixes the problem when the app is launched and immediately crashes with the error shown in the original description.
@ryaa The PR above doesn't solved my problem. The problem still persist and even after I downgrade to 5.7.0 and 5.6.0. Help
Please make sure to sync the native project after the you install a different version of @capacitor/android. The problem, as I believe, was introduced in 5.7.1 and everything should work fine in 5.7.0 or below
If I revert to the following code, the app build works.
String js = "<script type=\"text/javascript\">" + getScriptString() + "</script>"; String html = this.readAssetStream(responseStream); if (html.contains("<head>")) { html = html.replace("<head>", "<head>\n" + js + "\n"); } else if (html.contains("</head>")) { html = html.replace("</head>", js + "\n" + "</head>"); } else { Logger.error("Unable to inject Capacitor, Plugins won't work"); } return new ByteArrayInputStream(html.getBytes(StandardCharsets.UTF_8));
This method solved my problem. Thanks @aheadfullofcode @ryaa Thanks. Will try with the new PR also.
Will try with the new PR also.
The new @capacitor/android v5.7.2 has already been released with the appropriate fix. You can install and use it.
Hello, I did the migration to Capacitor 6 (using the tag "next" in package.json) and seems like I have the same problem, will there be a new version too for Capacitor 6 with this fix?
No more issue with 5.7.2. Thanks.
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.
Capacitor Version
alexryltsov@Alexs-MacBook-Pro-2 chore-781-upgrade-to-latest-capacitor-5x-and-native-dependencies-to-latest-versions % npx cap doctor 💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 5.7.1 @capacitor/core: 5.7.1 @capacitor/android: 5.7.1 @capacitor/ios: 5.7.1
Installed Dependencies:
@capacitor/cli: 5.5.0 @capacitor/core: 5.7.1 @capacitor/android: 5.7.1 @capacitor/ios: 5.7.1
[success] iOS looking great! 👌 [success] Android looking great! 👌
Other API Details
Platforms Affected
Current Behavior
Application crashes on Android after upgrading to the latest 5.7.1 version
Expected Behavior
The app works as expected and does not crash
Project Reproduction
https://github.com/ryaa/capacitor-android-5.7.1-app-crash
Additional Information
The problem seems to be related with the changes in JSInjector.java file in the recent @capacitor/android release v5.7.1. The problem is that some plugins (specifically cordova-plugin-advanced-http plugin) might embeds some scripts that has some special chars that needs to be properly escaped - see below
and
If this is not done, if the replacement string, passed to replaceFirst method, contains $1 or other $-prefixed sequences, the replaceFirst method will interpret them as references to capture groups and, since there might be no such a capture group, there will be an IndexOutOfBoundsException as shown above. This PR should fix this problem