Skip to content
This repository has been 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 opened this issue May 5, 2017 · 13 comments
Closed

Unable to build after upgrading to Cordova 7.0.0 #99

cindyliu-yb opened this issue May 5, 2017 · 13 comments

Comments

@cindyliu-yb
Copy link

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!

@ihadeed
Copy link
Contributor

ihadeed commented May 6, 2017

@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
Copy link
Contributor

peterpeterparker commented May 6, 2017

@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
Copy link
Contributor

peterpeterparker commented May 6, 2017

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
Copy link

janpio commented May 6, 2017

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
Copy link
Contributor

peterpeterparker commented May 6, 2017

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
Copy link
Contributor

ihadeed commented May 8, 2017

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

@peterpeterparker
Copy link
Contributor

@ihadeed sure, would be my pleasure: #103

mlynch added a commit that referenced this issue May 9, 2017
#99: Fix Xcode project file detection for Cordova 7
@aramando
Copy link

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
Copy link
Contributor

ihadeed commented May 17, 2017

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

@peterpeterparker
Copy link
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
Copy link
Contributor

mlynch commented Sep 19, 2017

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

@mlynch mlynch closed this as completed Sep 19, 2017
flipflopapp added a commit to flipflopapp/cordova-universal-links-plugin that referenced this issue Oct 7, 2017
@Prodev2017
Copy link

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
Copy link

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

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

No branches or pull requests

8 participants