简体   繁体   中英

Cordova Android App - Works on Android 7,8,9; Fails on Android 4,5, and 6

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

Steps to debug

  1. I have taken to updating plugins that could be causing the issue
  2. Test on real hardware and emulation
  3. Replace let with var
  4. Added console logging to see full stack traces

Errors

  1. On Android 4,5,6 when it tries to load 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

堆栈跟踪

  1. On Android 5,6

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.

Setup

Ide

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

Test Devices

  • Samsung Galaxy 9 - Android 9 - Works
  • HTC 10 - Android 8 - Works
  • HTC One - Android 6 - Fails
  • Raspberry Pi 2 - Android 5 - Still booting. lol:'(

Test Emulators

All using a hardware profile for a LGVK700 and running x86_64

  • Android 9 - Works
  • Android 8 - Works
  • Android 7 - Works
  • Android 6 - Fails
  • Android 5 - Fails
  • Android 4 - Fails

Setting Files

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

Support

I have verified that cordova should be supporting 4.4, 5 and 6

Android Requirements

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
  • Adding default vars to function signatures
  • Missing or extra ;
  • Using ` for blocks of strings

There 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM