SyntaxError: Unexpected number in JSON at position 4 when trying to debug with VSCode (Android)

Hi,

I’m trying to debug (Andorid device) my app created with ionic start myApp1 tabs --cordova with no success. Anyway all my debug configuration options fails:

1) Attach to running Android on device:
Error: Unable to find localabstract name of cordova app

2) Run Android on device:

Iniciando para android (esta operación puede tardar varios minutos)...
Command failed: emulator -list-avds
/bin/sh: 1: emulator: not found
Continue using standard CLI workflow.
2021-08-19T14:43:40.896Z ionic:lib Terminal info: { ci: false, shell: '/bin/bash', tty: false, windows: false }
2021-08-19T14:43:40.899Z ionic:lib CLI global options: { _: [ 'cordova', 'run', 'android' ], help: null, h: null, verbose: true, quiet: null, interactive: false, color: true, confirm: null, json: null, project: null, '--': [] }
2021-08-19T14:43:41.557Z ionic:lib:project Project type from config: @ionic/angular (angular)
2021-08-19T14:43:41.557Z ionic:lib:project Project details: { context: 'app', type: 'angular', errors: [], configPath: '/media/ramiro/EEE86441E86409E3/Documentos/Proyectos/Ionic/Ionic/Pruebas/Ionic 5/myApp1/ionic.config.json' }
2021-08-19T14:43:41.562Z ionic Context: { binPath: '/usr/lib/node_modules/@ionic/cli/bin/ionic', libPath: '/usr/lib/node_modules/@ionic/cli', execPath: '/media/ramiro/EEE86441E86409E3/Documentos/Proyectos/Ionic/Ionic/Pruebas/Ionic 5/myApp1', version: '6.16.3' }
2021-08-19T14:43:41.725Z ionic:lib:integrations:cordova:config Loading Cordova Config (config.xml: '/media/ramiro/EEE86441E86409E3/Documentos/Proyectos/Ionic/Ionic/Pruebas/Ionic 5/myApp1/config.xml', package.json: '/media/ramiro/EEE86441E86409E3/Documentos/Proyectos/Ionic/Ionic/Pruebas/Ionic 5/myApp1/package.json')
SyntaxError: Unexpected number in JSON at position 4

at JSON.parse (<anonymous>)
at Object.getNativeTargets (/usr/lib/node_modules/@ionic/cli/lib/native-run.js:110:44)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
2021-08-19T14:43:42.912Z ionic SyntaxError: Unexpected number in JSON at position 4
    at JSON.parse (<anonymous>)
    at Object.getNativeTargets (/usr/lib/node_modules/@ionic/cli/lib/native-run.js:110:44)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Error de ionic cordova run android --verbose --no-interactive con el código de salida 1

3) android-webview
No webviews found

My device is a Samsung S6. I can start my app from terminal with ionic cordova run android

My launch.json file:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to running Android on device",
            "type": "cordova",
            "request": "attach",
            "platform": "android",
            "target": "device",
            "port": 9222,
            "sourceMaps": true,
            "cwd": "${workspaceFolder}"
        },
    {
        "name": "Run Android on device",
        "type": "cordova",
        "request": "launch",
        "platform": "android",
        "target": "device",
        "port": 9222,
        "sourceMaps": true,
        "cwd": "${workspaceFolder}"
    },
        {
            "type": "android-webview",
            "request": "attach",
            "name": "Attach to Android WebView",
            "webRoot": "${workspaceFolder}"
        },
    ]
}

My package.json:

{
  "name": "myapp1",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "~12.1.1",
    "@angular/compiler": "~12.1.1",
    "@angular/core": "~12.1.1",
    "@angular/forms": "~12.1.1",
    "@angular/platform-browser": "~12.1.1",
    "@angular/platform-browser-dynamic": "~12.1.1",
    "@angular/router": "~12.1.1",
    "@capacitor/app": "1.0.2",
    "@capacitor/core": "3.1.2",
    "@capacitor/haptics": "1.0.2",
    "@capacitor/keyboard": "1.0.2",
    "@capacitor/status-bar": "1.0.2",
    "@ionic/angular": "^5.5.2",
    "rxjs": "~6.6.0",
    "tslib": "^2.2.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~12.1.1",
    "@angular-eslint/builder": "~12.0.0",
    "@angular-eslint/eslint-plugin": "~12.0.0",
    "@angular-eslint/eslint-plugin-template": "~12.0.0",
    "@angular-eslint/template-parser": "~12.0.0",
    "@angular/cli": "~12.1.1",
    "@angular/compiler": "~12.1.1",
    "@angular/compiler-cli": "~12.1.1",
    "@angular/language-service": "~12.0.1",
    "@capacitor/cli": "3.1.2",
    "@ionic/angular-toolkit": "^4.0.0",
    "@types/jasmine": "~3.6.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "@typescript-eslint/eslint-plugin": "4.16.1",
    "@typescript-eslint/parser": "4.16.1",
    "cordova-android": "^9.1.0",
    "cordova-plugin-device": "2.0.2",
    "cordova-plugin-ionic-keyboard": "^2.0.5",
    "cordova-plugin-ionic-webview": "^4.0.0",
    "cordova-plugin-splashscreen": "5.0.2",
    "cordova-plugin-statusbar": "2.4.2",
    "cordova-plugin-whitelist": "1.3.3",
    "eslint": "^7.6.0",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-jsdoc": "30.7.6",
    "eslint-plugin-prefer-arrow": "1.2.2",
    "jasmine-core": "~3.8.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~6.3.2",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "typescript": "~4.2.4"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-whitelist": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {},
      "cordova-plugin-ionic-keyboard": {}
    },
    "platforms": [
      "android"
    ]
  },
  "main": "karma.conf.js",
  "license": "ISC"
}

Ionic info output:

Ionic:

   Ionic CLI                     : 6.16.3 (/usr/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.6.13
   @angular-devkit/build-angular : 12.1.4
   @angular-devkit/schematics    : 12.1.4
   @angular/cli                  : 12.1.4
   @ionic/angular-toolkit        : 4.0.0

Cordova:

   Cordova CLI       : 10.0.0
   Cordova Platforms : android 9.1.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 4 other plugins)

Utility:

   cordova-res : 0.15.3
   native-run  : 1.4.0

System:

   Android SDK Tools : 26.1.1 (/home/ramiro/Android/Sdk)
   NodeJS            : v12.22.5 (/usr/bin/node)
   npm               : 6.14.14
   OS                : Linux 5.11

I’m stuck here. Any help? Thanks.

Three random suggestions:

  • get rid of all spaces in relevant directory names (I’m looking at you, Ionic 5)
  • install nvm
  • once you have nvm, install the latest LTS node (14.17.5 as of now)
1 Like

Hi,

Thanks for answer. Followed your tips…

Space in path name Ionic 5 removed.

nvm installed:

nvm -v
0.38.0

LTS node installed:

node -v
v14.17.5

Debugging results:

1) Attach to running Android on device:
Error: Unable to find localabstract name of cordova app

2) Run Android on device:

Iniciando para android (esta operación puede tardar varios minutos)...
Command failed: emulator -list-avds
/bin/sh: 1: emulator: not found
Continue using standard CLI workflow.
2021-08-20T15:32:34.641Z ionic:lib Terminal info: { ci: false, shell: '/bin/bash', tty: false, windows: false }
2021-08-20T15:32:34.647Z ionic:lib CLI global options: { _: [ 'cordova', 'run', 'android' ], help: null, h: null, verbose: true, quiet: null, interactive: false, color: true, confirm: null, json: null, project: null, '--': [] }
2021-08-20T15:32:35.035Z ionic:lib:project Project type from config: @ionic/angular (angular)
2021-08-20T15:32:35.038Z ionic:lib:project Project details: { context: 'app', type: 'angular', errors: [], configPath: '/media/ramiro/EEE86441E86409E3/Documentos/Proyectos/Ionic/Ionic/Pruebas/Ionic5/myApp1/ionic.config.json' }
2021-08-20T15:32:35.046Z ionic Context: { binPath: '/usr/lib/node_modules/@ionic/cli/bin/ionic', libPath: '/usr/lib/node_modules/@ionic/cli', execPath: '/media/ramiro/EEE86441E86409E3/Documentos/Proyectos/Ionic/Ionic/Pruebas/Ionic5/myApp1', version: '6.16.3' }
2021-08-20T15:32:35.149Z ionic:lib:integrations:cordova:config Loading Cordova Config (config.xml: '/media/ramiro/EEE86441E86409E3/Documentos/Proyectos/Ionic/Ionic/Pruebas/Ionic5/myApp1/config.xml', package.json: '/media/ramiro/EEE86441E86409E3/Documentos/Proyectos/Ionic/Ionic/Pruebas/Ionic5/myApp1/package.json')
SyntaxError: Unexpected number in JSON at position 4

at JSON.parse (<anonymous>)
at Object.getNativeTargets (/usr/lib/node_modules/@ionic/cli/lib/native-run.js:110:44)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async RunCommand.preRun (/usr/lib/node_modules/@ionic/cli/commands/cordova/run.js:201:37)
at async RunCommand.execute (/usr/lib/node_modules/@ionic/cli/lib/command.js:42:13)
at async Executor.run (/usr/lib/node_modules/@ionic/cli/lib/executor.js:54:9)
at async Executor.execute (/usr/lib/node_modules/@ionic/cli/node_modules/@ionic/cli-framework/lib/executor.js:70:13)
at async Object.run (/usr/lib/node_modules/@ionic/cli/index.js:106:9)
2021-08-20T15:32:36.244Z ionic SyntaxError: Unexpected number in JSON at position 4
    at JSON.parse (<anonymous>)
    at Object.getNativeTargets (/usr/lib/node_modules/@ionic/cli/lib/native-run.js:110:44)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async RunCommand.preRun (/usr/lib/node_modules/@ionic/cli/commands/cordova/run.js:201:37)
    at async RunCommand.execute (/usr/lib/node_modules/@ionic/cli/lib/command.js:42:13)
    at async Executor.run (/usr/lib/node_modules/@ionic/cli/lib/executor.js:54:9)
    at async Executor.execute (/usr/lib/node_modules/@ionic/cli/node_modules/@ionic/cli-framework/lib/executor.js:70:13)
    at async Object.run (/usr/lib/node_modules/@ionic/cli/index.js:106:9)
Error de ionic cordova run android --verbose --no-interactive con el código de salida 1

3) android-webview
No webviews found

I’m confused why you’re trying to use both capacitor and cordova. What happens if you try creating the project with only capacitor and no cordova?

I have to convert my old Ionic 3 project to Ionic 5. My old Ionic 3 project uses cordova. So I was traying to test a Ionic 5 project from scratch with no errors first before start the conversion. I’m stuck if I can’t debug a simple Ionic 5 project with nothing added by me. I didn’t know that I’m mixing cordova with capacitor, the project was created using ionic start myApp1 tabs --cordova

Anyway I’m gonna try using capacitor for testing.

My old project uses bluetooth serial and ng-canvas-gauges. Are these compatible with capacitor?

I believe the list of known incompatible plugins is here.

I made a new app using ionic start myApp2 tabs --capacitor. I get the app running in my Android device with ionic cap run android but I can’t debug using VSCode because No WebViews found after attaching my device id.

launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "android-webview",
            "request": "attach",
            "name": "Attach to Android WebView",
            "webRoot": "${workspaceFolder}"
        }
    ]
}

or you can use Chrome Devtools: Open Chrome DevTools - Chrome Developers

Ok. I’m managed to debug myApp2 with capacitor using VSCode: Launching first the app from terminal with ionic cap run android and then clicking Start Debugging (Run menu). The debug process was not automatic like I expected.