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

Plugin framework management fails

    XMLWordPrintableJSON

Details

    Description

      The fix to https://issues.apache.org/jira/browse/CB-9976 has created another one (or made it visible), and the initial problem is thus left unsolved.
      Actually, I think the newly visible issue is something I've been suspecting for a while now. I'll explain it along the way.

      I was able to reproduce with a minimal scenario:
      (Step #2 is to fix another issue with 5.3.3, it has nothing to do with the issue at hand)

      • npm rm -g cordova && npm i -g cordova@5.3.3
      • mkdir -p <node/npm>/lib/node_modules/cordova/node_modules/cordova-lib/node_modules && ln -s <node/npm>/lib/node_modules/cordova/node_modules/cordova-app-hello-world <node/npm>/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-app-hello-world
      • cordova create hello
      • cd hello/
      • cordova platform add --save android
      • cordova plugin add --save cordova-plugin-facebook4 --variable APP_ID="123456789" --variable APP_NAME="myApplication"
      • cordova -d compile android -- --minSdkVersion=15 <- At this point everything is okay, and this minSdkVersion is to work around another issue
      • npm rm -g cordova && npm i -g cordova@5.4.1

      Before we go on, open up <node/npm>/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/platforms/android.js and add the following line at #174

      console.log('options', JSON.stringify(options, null, 4));
      
      • cordova prepare android -d

      Result:

      Executing "before_prepare"  hook for all plugins.
      Searching PlatformJson files for differences between project vs. platform installed plugins
      Reinstalling missing plugin cordova-plugin-device to android platform
      Beginning processing of action stack for android project...
      Action stack processing complete.
      Beginning processing of action stack for android project...
      Action stack processing complete.
      Reinstalling missing plugin cordova-plugin-facebook4 to android platform
      Beginning processing of action stack for android project...
      Uninstalling Android library: com.facebook.android:facebook-android-sdk:4.+
      options {
          "platforms": [
              "android"
          ],
          "options": {
              "verbose": true,
              "argv": []
          },
          "verbose": true,
          "silent": false,
          "browserify": false,
          "projectRoot": "<path>/temp/testes/5.4.1/hello-facebook-device",
          "cordova": {
              "platforms": [],
              "plugins": [
                  "cordova-plugin-device",
                  "cordova-plugin-facebook4"
              ],
              "version": "5.4.1"
          },
          "paths": [
              "<path>/temp/testes/5.4.1/hello-facebook-device/platforms/android/assets/www"
          ],
          "variables": {
              "APP_ID": "123456789",
              "APP_NAME": "myApplication",
              "PACKAGE_NAME": "io.cordova.hellocordova"
          },
          "usePlatformWww": true
      }
      Error during processing of action! Attempting to revert...
      Error: TypeError: Uh oh!
      Invalid Version: undefined
          at new SemVer (<node/npm>/lib/node_modules/cordova/node_modules/semver/semver.js:281:11)
          at compare (<node/npm>/lib/node_modules/cordova/node_modules/semver/semver.js:571:10)
          at Function.gte (<node/npm>/lib/node_modules/cordova/node_modules/semver/semver.js:620:10)
          at module.exports.framework.uninstall (<node/npm>/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/platforms/android.js:176:28)
          at <node/npm>/lib/node_modules/cordova/node_modules/cordova-lib/src/platforms/PlatformApiPoly.js:670:31
          at Object.ActionStack.process (<node/npm>/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-common/src/ActionStack.js:56:25)
          at PlatformApiPoly.removePlugin (<node/npm>/lib/node_modules/cordova/node_modules/cordova-lib/src/platforms/PlatformApiPoly.js:314:20)
          at <node/npm>/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/prepare.js:165:24
          at _fulfilled (<node/npm>/lib/node_modules/cordova/node_modules/q/q.js:787:54)
          at self.promiseDispatch.done (<node/npm>/lib/node_modules/cordova/node_modules/q/q.js:816:30)
      

      So, the thing is: the code responsible for installing or uninstalling frameworks for android (I haven't checked other platforms completely) tries to access the platform version in a way that does not match reality. This bug only appears if you have a plugin that includes framework dependencies, as is the case with jeduan's cordova-plugin-facebook4.
      options.platformVersion is never a valid attribute of this object, in any test I've done, and the correct way to get it should be options.cordova.version.
      The thing is, I've been suspecting that plugin uninstallations were never able to handle gradle dependencies added by a plugin, as far as I remember.
      I have all my platforms on version control, and I remember quite a few times when I had to remove or update plugins like this, I had to clean leftovers from a few places by hand. None of the following sections were updated properly on a plugin uninstallation process (I might have forgotten some):

      1. platforms/android/build.gradle (dependencies block: SUB-PROJECT DEPENDENCIES)
      2. platforms/android/project.properties
      3. platforms/ios/*.pdxproj (at every FRAMEWORK_SEARCH_PATHS section)

      Attachments

        Issue Links

          Activity

            People

              vladimir.kotikov Vladimir Kotikov
              kikoalemao Frederico Costa Galvão
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: