Skip to content
This repository was archived by the owner on Aug 17, 2023. It is now read-only.
This repository was archived by the owner on Aug 17, 2023. It is now read-only.

Unable to build after upgrading to Cordova 7.0.0 #99

Closed
@cindyliu-yb

Description

@cindyliu-yb

Hello,

I can't do cordova build because of something in the plugin after upgrading to Cordova 7.0.0. See the error below. Once I remove the plugin, I can build successfully.

screen shot 2017-05-05 at 11 28 15

Could you fix this? Thanks in advance!

Activity

ihadeed

ihadeed commented on May 6, 2017

@ihadeed
Contributor

@cindyliu-yb I don't think this is related to this plugin. I was just experiencing the same issue. Run the following command to fix it:

sudo npm i -g cordova@6.5.0
peterpeterparker

peterpeterparker commented on May 6, 2017

@peterpeterparker
Contributor

@ihadeed it's related to this plugin I think...

ionic plugin add ionic-plugin-deeplink
ionic platform rm ios
ionic platform add ios

=> Error: Cannot find module '../plugman/platforms/ios'

ionic plugin rm ionic-plugin-deeplink
ionic platform rm ios
ionic platform add ios
ionic plugin add ionic-plugin-deeplink

=> ok but fail later on ionic build ios --prod

ionic plugin rm ionic-plugin-deeplink
ionic platform rm ios
ionic platform add ios
ionic build ios --prod

=> ok

P.S.: I didn't faced that error with the android platform, was alright

peterpeterparker

peterpeterparker commented on May 6, 2017

@peterpeterparker
Contributor

In xcodePreferences.js:

try {
// try pre-5.0 cordova structure
platform_ios = context.requireCordovaModule('cordova-lib/src/plugman/platforms')['ios'];
projectFile = platform_ios.parseProjectFile(iosPlatformPath());
} catch (e) {
  // let's try cordova 5.0 structure
  platform_ios = context.requireCordovaModule('cordova-lib/src/plugman/platforms/ios');
  projectFile = platform_ios.parseProjectFile(iosPlatformPath());
}

But 'cordova-lib/src/plugman/platforms/ios' seems to doesn't exist anymore in Cordova 7.0.0, see following commit:

apache/cordova-lib@64fea70

janpio

janpio commented on May 6, 2017

@janpio

So this https://github.com/driftyco/ionic-plugin-deeplinks/blob/master/hooks/afterPrepareHook.js
is including this https://github.com/driftyco/ionic-plugin-deeplinks/blob/master/hooks/lib/ios/xcodePreferences.js where these lines don't do what they are supposed to do any more: https://github.com/driftyco/ionic-plugin-deeplinks/blob/master/hooks/lib/ios/xcodePreferences.js#L151-L159

The commit @peterpeterparker linked to seems to have removed some deprecated stuff. Was there a deprecation notice output when executing this with Cordova 6.5.0?

peterpeterparker

peterpeterparker commented on May 6, 2017

@peterpeterparker
Contributor

He you go, a quick and dirty solution. In xcodePreferences.js, replace method loadProjectFile with following code:

function loadProjectFile() {
  var platform_ios;
  var projectFile;

  try {
    // try pre-5.0 cordova structure
    platform_ios = context.requireCordovaModule('cordova-lib/src/plugman/platforms')['ios'];
    projectFile = platform_ios.parseProjectFile(iosPlatformPath());
  } catch (e) {
      try {
          // let's try cordova 5.0 structure
          platform_ios = context.requireCordovaModule('cordova-lib/src/plugman/platforms/ios');
          projectFile = platform_ios.parseProjectFile(iosPlatformPath());
      } catch (e) {
          // Then cordova 7.0
          var project_files = context.requireCordovaModule('glob').sync(path.join(iosPlatformPath(), '*.xcodeproj', 'project.pbxproj'));

          if (project_files.length === 0) {
            throw new Error('does not appear to be an xcode project (no xcode project file)');
          }

          var pbxPath = project_files[0];

          var xcodeproj = context.requireCordovaModule('xcode').project(pbxPath);
          xcodeproj.parseSync();

          projectFile = {
              'xcode': xcodeproj,
              write: function () {
                  var fs = context.requireCordovaModule('fs');

              var frameworks_file = path.join(iosPlatformPath(), 'frameworks.json');
              var frameworks = {};
              try {
                  frameworks = context.requireCordovaModule(frameworks_file);
              } catch (e) { }

              fs.writeFileSync(pbxPath, xcodeproj.writeSync());
                  if (Object.keys(frameworks).length === 0){
                      // If there is no framework references remain in the project, just remove this file
                      context.requireCordovaModule('shelljs').rm('-rf', frameworks_file);
                      return;
                  }
                  fs.writeFileSync(frameworks_file, JSON.stringify(this.frameworks, null, 4));
              }
          };
      }
  }

  return projectFile;
}    
ihadeed

ihadeed commented on May 8, 2017

@ihadeed
Contributor

@peterpeterparker thanks for the fix. You should submit a PR :)

peterpeterparker

peterpeterparker commented on May 8, 2017

@peterpeterparker
Contributor

@ihadeed sure, would be my pleasure: #103

added a commit that references this issue on May 9, 2017

Merge pull request #103 from peterpeterparker/fix-cordova7

aramando

aramando commented on May 17, 2017

@aramando

I've come up with a much simpler solution. Can anyone confirm this works as intended? It appears to work OK for me, but I'm insufficiently familiar with the inner machinations of Cordova to know how good a solution it is.

function loadProjectFile() {
  var platform_ios;
  var projectFile;
  try {
    // try pre-5.0 cordova structure
    platform_ios = context.requireCordovaModule('cordova-lib/src/plugman/platforms')['ios'];
    projectFile = platform_ios.parseProjectFile(iosPlatformPath());
  } catch (e) {
    try {
      // let's try cordova 5.0 structure
      platform_ios = context.requireCordovaModule('cordova-lib/src/plugman/platforms/ios');
      projectFile = platform_ios.parse(iosPlatformPath());
    } catch (e) {
      // try cordova 7.0 structure
      var iosPlatformApi = require(path.join(iosPlatformPath(), '/cordova/Api'));
      var projectFileApi = require(path.join(iosPlatformPath(), '/cordova/lib/projectFile.js'));
      var locations = (new iosPlatformApi()).locations;
      projectFile = projectFileApi.parse(locations);
    }
  }
  return projectFile;
}
ihadeed

ihadeed commented on May 17, 2017

@ihadeed
Contributor

@peterpeterparker 's PR was merged, this should be fixed now.

peterpeterparker

peterpeterparker commented on May 17, 2017

@peterpeterparker
Contributor

@ihadeed yes it's merged and confirm it's fixed but of course Im not against a easier cuter solution, like I said, I did a quick fix

mlynch

mlynch commented on Sep 19, 2017

@mlynch
Contributor

btw I removed all the hooks. Caused more problems than they were worth. See #82

added a commit that references this issue on Oct 7, 2017
Prodev2017

Prodev2017 commented on Dec 16, 2017

@Prodev2017

I tried to add ionic-plugin-deeplink
but i got errors

An error occurred while running cordova plugin add ionic-plugin-deeplink --save (exit

    code 1):
    
    Error: Registry returned 404 for GET on 
    https://registry.npmjs.org/ionic-plugin-deeplink

Please help me

timothylombrana

timothylombrana commented on Jan 13, 2018

@timothylombrana

Any update on installation error, I as well am getting a 404. Could really use the help.

added a commit that references this issue on May 22, 2018

ionic-team#99: Fix Xcode project file detection for Cordova 7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mlynch@janpio@aramando@timothylombrana@ihadeed

        Issue actions

          Unable to build after upgrading to Cordova 7.0.0 · Issue #99 · ionic-team/ionic-plugin-deeplinks