This has been a monster of a headache trying to figure out what is going on.
I have an android app that I have been developing and maintaining. My latest test devices are on android 9 and bring up the app with no issues. Many of the files that I am currently having issues with have been part of this project when these OS's were in their prime in popularity.
In order to maintain a wide compatibility range, I am targeting to get this app running on android 5 through 9
let
with var
jquery-1.8.1.js
it returns the error below causing the whole app to crash. The stack trace seems rather unhelpful.Uncaught SyntaxError: Unexpected token =
Stack Trace
Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
I imagine that this is due to the OS's age. Not sure how to enable strict mode through the entire app or even if that is a good thing. For the time being I have replaced all let
with var
to get around the issue. Not my preferred solution, if you have a better one, please let me know.
vsCode Android Studio: (Not sure why one of them can do both) * 3.6.1 for Emulators running x86 * 3.4.0 to connect to my test device
All using a hardware profile for a LGVK700 and running x86_64
This is running on Cordova 8.1.2 (cordova-lib@8.1.1)
config.xml:
<preference name="android-minSdkVersion" value="19" />
<preference name="android-targetSdkVersion" value="28" />
Cordova plugins and platforms
$ cordova plugins
cordova-android-support-gradle-release 2.0.1 "cordova-android-support-gradle-release"
cordova-plugin-actionsheet 2.3.3 "ActionSheet"
cordova-plugin-appminimize 1.0.1 "AppMinimize"
cordova-plugin-camera 4.0.3 "Camera"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-dialogs 2.0.1 "Notification"
cordova-plugin-file 6.0.1 "File"
cordova-plugin-file-opener2 2.2.0 "File Opener2"
cordova-plugin-file-transfer 1.7.1 "File Transfer"
cordova-plugin-geolocation 4.0.1 "Geolocation"
cordova-plugin-inappbrowser 3.2.0 "InAppBrowser"
cordova-plugin-media-capture 3.0.2 "Capture"
cordova-plugin-network-information 2.0.1 "Network Information"
cordova-plugin-save-image 0.3.0 "SaveImage"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-statusbar 2.4.2 "StatusBar"
cordova-plugin-whitelist 1.3.3 "Whitelist"
uk.co.workingedge.phonegap.plugin.launchnavigator 4.2.2 "Launch Navigator"
$ cordova platforms
Installed platforms:
android 8.1.0
ios 5.0.1
I have verified that cordova should be supporting 4.4, 5 and 6
Target Versions
After four long nights and a full day of linting later, I figured out what the issue is.
The errors I get are not from jquery-1.8.1, but from jquery throwing the error caused when loading other js files that are not compatible with es5.
The plugins and platform version are not the issue, it was me taking advantage of cool new features that are not supported in old browsers.
Examples:
let
instead of var
, so that memory is freed up sooner ;
`
for blocks of stringsThere were also several string and array functions that did not exist in older browsers.
Using JavaScript inherent flexibility, I can add these back in using a technique known as polyfill.
Shout out:
Sources for polyfill:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.