Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova android emulation - Error: Cannot read property 'semver' of null

Trying to emulate Android app with cordova, but get this error message:

Built the following apk(s): /Users/jnj/cordova/hello/platforms/android/build/outputs/apk/android-debug.apk ANDROID_HOME=/Users/jnj/Library/Android/sdk JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home

Error: Cannot read property 'semver' of null

Any solutions?

like image 846
Jonas Jakobsen Avatar asked Oct 30 '17 15:10

Jonas Jakobsen


2 Answers

This is due using an emulator with an unstable Developer Preview API version.

You probably have a device using API 27 (Android 8.1).

Open your AVD, remove that device and re-run.

It's also useful to use --target <emulator_name> when launching the emulator if you have more than one.

To get a list of available names to use, call the emulate command with --list

like image 184
Daniel Avatar answered Nov 12 '22 07:11

Daniel


The Mighty Chris is right, that is the problem and he fixed it upstream (thank you Chris!). However just to add to his answer, for people like me who cannot update cordova-android to include the patch, the fix is (for cordova-android v6.4.0):

  • find the path <project_root>/platforms/android/cordova/lib/emulator.js
  • find the line avd.target = 'Android ' + level.semver + ' (API level ' + api_level + ')';
  • replace it with avd.target = 'Android ' + (level ? level.semver : '') + ' (API level ' + api_level + ')';

Here is the relevant patch.

like image 63
oidualc Avatar answered Nov 12 '22 09:11

oidualc