Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Plugin install fails when preview sdk is installed #985

Merged
merged 1 commit into from
Jun 18, 2020

Conversation

breautek
Copy link
Contributor

@breautek breautek commented Jun 5, 2020

Platforms affected

android

Motivation and Context

Fixes #981

If a plugin declares a android-sdk engine requirement such as <engine name="android-sdk" version=">=26" /> the plugin may unexpectedly fail if the following conditions are met:

  1. You have an appropriate SDK version installed (such as version android-28)
  2. You have android preview SDK installed.

If the android preview SDK is installed, it was treated as the highest sdk version, even if it has no numerical value. This then led to errors such as:

Installing "cordova-plugin-local-notification" for android
Failed to install 'cordova-plugin-local-notification': TypeError: Invalid Version: android-R
    at new SemVer (/home/norman/.nvm/versions/node/v14.2.0/lib/node_modules/cordova/node_modules/semver/semver.js:323:11)
    at Range.test (/home/norman/.nvm/versions/node/v14.2.0/lib/node_modules/cordova/node_modules/semver/semver.js:1203:15)
    at Function.satisfies (/home/norman/.nvm/versions/node/v14.2.0/lib/node_modules/cordova/node_modules/semver/semver.js:1257:16)
    at checkEngines (/home/norman/.nvm/versions/node/v14.2.0/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:113:20)
    at /home/norman/.nvm/versions/node/v14.2.0/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:305:16
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Invalid Version: android-R

Description

This PR changes the sort_by_largest_numerical_suffix and give preview SDKs a numerical value of 0, thus preview SDKs are put to the bottom of the stack.

This does mean that preview SDKs will never be chosen, but I believe this should be the default behaviour. If the user wants to use a preview SDK, I think that should be an opt-in feature, and it is out of scope of this PR.

Existing tests were modified to ensure that preview SDKs were ordered properly.

Special thanks to @timpark for supplying a patch that fixes the sort_by_largest_numerical_suffix method.

Testing

I've ran npm test
I've tested against the my local fork with the PR applied, using the following commands on an empty project.

cordova platform add (android | android-fork)
cordova plugin add https://github.com/Steffaan/cordova-plugin-local-notifications

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

@breautek breautek requested review from erisu and timbru31 June 5, 2020 02:24
@codecov-commenter
Copy link

codecov-commenter commented Jun 5, 2020

Codecov Report

Merging #985 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #985   +/-   ##
=======================================
  Coverage   68.11%   68.11%           
=======================================
  Files          21       21           
  Lines        1866     1866           
=======================================
  Hits         1271     1271           
  Misses        595      595           
Impacted Files Coverage Δ
bin/templates/cordova/lib/android_sdk.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a830145...771d78f. Read the comment docs.

@breautek breautek merged commit 8d8600b into apache:master Jun 18, 2020
@breautek breautek deleted the GH-981-fix-sdk-choice branch June 18, 2020 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plugin installation can fail when Android Preview SDK is installed
3 participants