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

Plugin installation can fail when Android Preview SDK is installed #981

Closed
3 tasks done
timpark opened this issue May 28, 2020 · 3 comments · Fixed by #985
Closed
3 tasks done

Plugin installation can fail when Android Preview SDK is installed #981

timpark opened this issue May 28, 2020 · 3 comments · Fixed by #985
Labels

Comments

@timpark
Copy link

timpark commented May 28, 2020

Bug Report

Problem

The plugin.xml file of [EDIT: https://github.com/Steffaan/cordova-plugin-local-notifications ] contains the line:
<engine name="android-sdk" version=">=26" />

This plugin refused to install on the Nevercode CI platform even though android-29 was installed, because I discovered that (at the time, at least) their build environments have three Android Preview SDKs installed.

The issue is that when android_sdk.js encounters an SDK version without a number at the end (in my case, android-P, android-Q, and android-R), it refuses to move it, and depending on where it is in relation to other versions, it can block proper sorting of the SDKs.

What is expected to happen?

Plugin should install since a version of the SDK is installed matching the requirements.

What does actually happen?

Plugin did not install.

Information

Attempt to build a project with the cordova-plugin-local-notifications plugin (or any other with a similar requirement) with Android Preview SDKs installed.

Command or Code

Here's a patch that, instead of not moving the preview versions at all, gives them a version of 0 so they get sent to the end of the list.

--- android_sdk.js	2020-05-26 14:33:04.000000000 -0400
+++ android_sdk_new.js	2020-05-26 14:50:38.000000000 -0400
@@ -31,15 +31,12 @@
 function sort_by_largest_numerical_suffix (a, b) {
     var suffix_a = a.match(suffix_number_regex);
     var suffix_b = b.match(suffix_number_regex);
-    if (suffix_a && suffix_b) {
-        // If the two targets being compared have suffixes, return less than
-        // zero, or greater than zero, based on which suffix is larger.
-        return (parseInt(suffix_a[1]) > parseInt(suffix_b[1]) ? -1 : 1);
-    } else {
-        // If no suffix numbers were detected, leave the order as-is between
-        // elements a and b.
-        return 0;
-    }
+    // If no number is detected (eg: preview version like android-R),
+    // designate a suffix of 0 so it gets moved to the end
+    suffix_a = suffix_a ? suffix_a : ['0','0'];
+    suffix_b = suffix_b ? suffix_b : ['0','0'];
+    // Return < zero, or > zero, based on which suffix is larger.
+    return (parseInt(suffix_a[1]) > parseInt(suffix_b[1]) ? -1 : 1);
 }
 
 module.exports.print_newest_available_sdk_target = function () {

Perhaps the preview SDKs would be given a proper number, but that's more complicated than what I needed. Either way, it was causing my plugin install to fail on Nevercode. Due to the ordering of the installed SDKs, 15 got moved to the front instead of 29.

Sorry I didn't submit a pull request, but I'm not sure how to properly meet the required testing criteria with a bug like this.

Environment, Platform, Device

Nevercode CI with what looked like every Android SDK in existence installed

Version information

Cordova CLI 9.0.0
Cordova-Android 8.1.0
Ionic 3.20.1

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@breautek
Copy link
Contributor

breautek commented Jun 1, 2020

Is there another public package that reproduces this issue?

I've tried installing cordova-plugin-local-notifications but it failed due to an unrelated issue, because that plugin is so old and unmaintained.

Also, the plugin doesn't appear to have <engine name="android-sdk" version=">=26" /> in their master, maybe you're using a fork?

@breautek breautek added the info-needed / awaiting response Further information is requested label Jun 1, 2020
@timpark
Copy link
Author

timpark commented Jun 1, 2020

My apologies for not specifying the plugin correctly. There's a small difference between the names on npm and GitHub. I meant this plugin:

https://www.npmjs.com/package/cordova-plugin-local-notification which points to
https://github.com/katzer/cordova-plugin-local-notifications

Furthermore, I also forgot that I'm using a fork.
https://github.com/Steffaan/cordova-plugin-local-notifications

It looks like the original removed the engine restriction due to the issue I'm pointing out:
katzer/cordova-plugin-local-notifications#1561 (comment)

I looked around and found that these plugins also have an android-sdk engine requirement:
cordova-plugin-background-mode
cordova-plugin-printer

@breautek
Copy link
Contributor

breautek commented Jun 5, 2020

I'll retest using https://github.com/Steffaan/cordova-plugin-local-notifications fork

edit: I've confirmed the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants