Reputation: 145
I downloaded and added "Nexus 5X API 26" to "Your Virtual Devices" in Android Studio, so that Cordova has at least 1 possible target to run in.
However, when I run the command
cordova run android
The terminal (after some other lines) responds:
BUILD SUCCESSFUL
Total time: 1.305 secs
Built the following apk(s):
/Users/karel/Cordova Projects/demo/platforms/android/build/outputs/apk/android-debug.apk
ANDROID_HOME=/Users/karel/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
No target specified and no devices found, deploying to emulator
Error: Cannot read property 'replace' of undefined
The emulator runs fine when I run it from an application in Android Studio, but not when using the cordova run command - which does work for other platforms.
If you can help me, that would be very appreciated!
Upvotes: 2
Views: 723
Reputation: 1241
Try to target API 25 instead of 26.
Problem and his fix are reported here: https://forum.ionicframework.com/t/error-cannot-read-property-replace-of-undefined-android/93297/31
In file /platforms/android/cordova/lib/emulator.js line 202:
var num = target.split('(API level ')[1].replace(')', '');
You need to replaced it with a regex search and extraction:
var num = target.match(/\d+/)[0];
because the target is Android API 26 and it is trying to parse it with this:
var num = target.split('(API level ')[1].replace(')', '')
Upvotes: 1