When I try to build my Angular application and run it on an Android 10 (API 29) emulator, I get a white screen on the device and this log entry in Android Studio:
E/Capacitor/Console: File: http://localhost/ - Line 610 - Msg: SyntaxError: Unexpected token ?
E/Capacitor: JavaScript Error: {"type":"js.error","error":{"message":"Uncaught SyntaxError: Unexpected token ?","url":"http://localhost/main.31deaa0a1e940765.js","line":1,"col":1028,"errorObject":"{}"}}
E/Capacitor/Console: File: http://localhost/main.31deaa0a1e940765.js - Line 1 - Msg: Uncaught SyntaxError: Unexpected token ?
On the image here you can see the exact location of the unexpected '?' token in the main.js file
The reproducible project with the standard Angular application can be found here: https://gitlab.com/BlackBird604/api29-syntax-error-example
Here is what I have done:
- created a default Angular 15 project
- added the latest version of Capacitor (4.6.1)
- configured Capacitor and built the project
- ran it in Android Studio (Dolphin | 2021.3.1 Patch 1) on a Pixel 2 device with API 29
The strange thing is that the app works fine on web browsers as well as on the Android 11 and 12 emulators. I read that by default only the last two Android versions are supported and setting the target inside "tsconfig.json" to "ES2015" should resolve the issue, but sadly no luck here. I also tried to add a .browserslistrc but it also didn't work.
Do you guys have any idea what the problem could be? I would be very grateful for your help :)
CodePudding user response:
Angular 15 has no support for old Chrome versions and android emulators have old Chrome/WebView versions by default.
You'll have to create an emulator that has Google Play, log in and update the System WebView package to a more recent version.
Or downgrade angular to 14 by undoing this changes if you want to support older versions https://github.com/ionic-team/starters/commit/dc48a925b5455e97099858428d2a74cc113bea47