Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-12981

Error: Cannot read property ‘replace’ of undefined [Android]

    XMLWordPrintableJSON

Details

    Description

      Error happens when running `cordova run android` or `cordova emulate android`:

      Example output:

      BUILD SUCCESSFUL
      
      Total time: 1.601 secs
      Built the following apk(s): 
      	/Users/Joanne/Desktop/learning/mobile/platforms/android/build/outputs/apk/android-debug.apk
      ANDROID_HOME=/Users/Joanne/Library/Android/sdk
      JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
      No target specified and no devices found, deploying to emulator
      Error: Cannot read property 'replace' of undefined
      

      More details, environment information of multiple people having this problem can be found here:
      https://forum.ionicframework.com/t/error-cannot-read-property-replace-of-undefined-android/93297

      A solution was also proposed here:
      https://forum.ionicframework.com/t/error-cannot-read-property-replace-of-undefined-android/93297/11

      I just came across the same problem. I tracked it down to file /platforms/android/cordova/lib/emulator.js line 202:

      var num = target.split('(API level ')[1].replace(')', '');

      I replaced it with a regex search and extraction:

      var num = target.match(/\d+/)[0];

      Not sure if this is the right way to fix this.

      Attachments

        Issue Links

          Activity

            People

              filmaj Filip Maj
              birowsky Birowsky
              Votes:
              4 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: