EddyVerbruggen / nativescript-barcodescanner

🔎 NativeScript QR / barcode (bulk)scanner plugin
MIT License
293 stars 73 forks source link

Cannot read properties of undefined (reading 'content') #288

Closed vmartins closed 2 months ago

vmartins commented 2 months ago

The app compiles and runs without errors in development mode (ns run and ns debug), but when I build (ns build) the application crashes when trying to open. I added the minimize=false option in webpack to better understand the error (analyzed via adb logcat):

09-02 08:57:05.615 27443 27443 I TNS.Runtime: NativeScript Runtime Version 8.8.2, commit e2de001c0293495e1248d2e4cde752be70430add
09-02 08:57:05.690 27443 27443 D TNS.Runtime: V8 version 10.3.22
09-02 08:57:06.817 15884 15959 I WorkerManager: dispose()
09-02 08:57:07.326 27443 27443 D AndroidRuntime: Shutting down VM
09-02 08:57:07.326 27443 27443 E AndroidRuntime: FATAL EXCEPTION: main
09-02 08:57:07.326 27443 27443 E AndroidRuntime: Process: com.myapp, PID: 27443
09-02 08:57:07.326 27443 27443 E AndroidRuntime: java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: Error calling module function 
09-02 08:57:07.326 27443 27443 E AndroidRuntime: TypeError: Cannot read properties of undefined (reading 'content')
09-02 08:57:07.326 27443 27443 E AndroidRuntime: File: (file:///data/data/com.myapp/files/app/vendor.js:104384:95)
09-02 08:57:07.326 27443 27443 E AndroidRuntime: 
09-02 08:57:07.326 27443 27443 E AndroidRuntime: StackTrace: 
09-02 08:57:07.326 27443 27443 E AndroidRuntime: 9424(file:///data/data/com.myapp/files/app/vendor.js:104384:96)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at __webpack_require__(file:///data/data/com.myapp/files/app/runtime.js:23:42)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at 11(file:///data/data/com.myapp/files/app/bundle.js:6460:30)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at __webpack_require__(file:///data/data/com.myapp/files/app/runtime.js:23:42)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at __webpack_exec__(file:///data/data/com.myapp/files/app/bundle.js:9416:39)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at (file:///data/data/com.myapp/files/app/bundle.js:9417:114)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at __webpack_require__.X(file:///data/data/com.myapp/files/app/runtime.js:114:21)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at (file:///data/data/com.myapp/files/app/bundle.js:9417:47)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at (file:///data/data/com.myapp/files/app/bundle.js:9422:3)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at require(:1:266)
09-02 08:57:07.326 27443 27443 E AndroidRuntime: 
09-02 08:57:07.326 27443 27443 E AndroidRuntime: 
09-02 08:57:07.326 27443 27443 E AndroidRuntime: TypeError: Cannot read properties of undefined (reading 'content')
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6798)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:106)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at android.os.Looper.loopOnce(Looper.java:201)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:288)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:7934)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
09-02 08:57:07.326 27443 27443 E AndroidRuntime: Caused by: com.tns.NativeScriptException: Error calling module function 
09-02 08:57:07.326 27443 27443 E AndroidRuntime: TypeError: Cannot read properties of undefined (reading 'content')
09-02 08:57:07.326 27443 27443 E AndroidRuntime: File: (file:///data/data/com.myapp/files/app/vendor.js:104384:95)
09-02 08:57:07.326 27443 27443 E AndroidRuntime: 
09-02 08:57:07.326 27443 27443 E AndroidRuntime: StackTrace: 
09-02 08:57:07.326 27443 27443 E AndroidRuntime: 9424(file:///data/data/com.myapp/files/app/vendor.js:104384:96)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at __webpack_require__(file:///data/data/com.myapp/files/app/runtime.js:23:42)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at 11(file:///data/data/com.myapp/files/app/bundle.js:6460:30)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at __webpack_require__(file:///data/data/com.myapp/files/app/runtime.js:23:42)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at __webpack_exec__(file:///data/data/com.myapp/files/app/bundle.js:9416:39)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at (file:///data/data/com.myapp/files/app/bundle.js:9417:114)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at __webpack_require__.X(file:///data/data/com.myapp/files/app/runtime.js:114:21)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at (file:///data/data/com.myapp/files/app/bundle.js:9417:47)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at (file:///data/data/com.myapp/files/app/bundle.js:9422:3)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at require(:1:266)
09-02 08:57:07.326 27443 27443 E AndroidRuntime: 
09-02 08:57:07.326 27443 27443 E AndroidRuntime: 
09-02 08:57:07.326 27443 27443 E AndroidRuntime: TypeError: Cannot read properties of undefined (reading 'content')
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at com.tns.Runtime.runModule(Native Method)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at com.tns.Runtime.runModule(Runtime.java:689)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at com.tns.Runtime.run(Runtime.java:681)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:21)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1283)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6793)
09-02 08:57:07.326 27443 27443 E AndroidRuntime:    ... 9 more

Looking inside the apk for the vendor.js file on line 104384:

104374  "use strict";
104375  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
104376  /* harmony export */   v: () => (/* binding */ BarcodeScanner)
104377  /* harmony export */ });
104378  /* harmony import */ var _nativescript_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3236);
104379  /* harmony import */ var _nativescript_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6858);
104380  
104381  const SCANNER_REQUEST_CODE = 444;
104382  const AppPackageName = useAndroidX() ? global.androidx.core.app : android.support.v4.app;
104383  const ContentPackageName = useAndroidX() ? global.androidx.core.content : android.support.v4.content;
*104384  const LocalBroadcastManagerPackageName = useAndroidX() ? global.androidx.localbroadcastmanager.content : android.support.v4.content;
104385  let _onScanReceivedCallback = undefined;
104386  let _onContinuousScanResult = undefined;
104387  function useAndroidX() {
104388      return global.androidx && global.androidx.appcompat;
104389  }
104390  class BarcodeScanner {
104391      constructor() {
104392          this.broadcastManager = null;
104393          this.uniquelyScannedCodes = [];

Build command:

ns build android \
--release \
--compileSdk 33 \
--key-store-path MYKEYSTORE \
--key-store-password MYKEYSTOREPASS \
--key-store-alias MYALIAS \
--key-store-alias-password MYALIASPASS \
--apk \
--copy-to "MYOUTPUT" \
--clean 

Versions:

@nativescript/core v8.8.2
@nativescript/android v8.8.2
nativescript-barcodescanner v4.1.2
ns v8.8.2
node v20.17.0
Android v13
vmartins commented 2 months ago

Fixed after these steps https://github.com/EddyVerbruggen/nativescript-barcodescanner/issues/286#issuecomment-1249749011