Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Adding <universal-links> block in config.xml breaks "cordova platform add ios" #54

Closed
ZyphiraZircon opened this issue Mar 17, 2016 · 24 comments
Labels

Comments

@ZyphiraZircon
Copy link

I've poured over the documents and couldn't find anything addressing this issue. I added a universal links block to my config.xml that looks like

<universal-links>
    <host name='store-name.myshopify.com' />
</universal-links>

And as a result I get the error

Error: ENOENT: no such file or directory, open '/Users/Keystoke/Desktop/new_preview_test/platforms/ios/CordovaLib/VERSION'

when trying to run 'cordova platform add ios'. In fact, it's as if CordovaLib isn't even being created, there's no directory at the time of the of crash.

I'm able to add the platform just fine when I remove that block from my config.xml, all I get is the expected error of " tag is not set in the config.xml. Universal Links plugin is not going to work." Any ideas on what could be causing this?

@nikDemyankov
Copy link
Member

I assume, that if you first add platform, and only then plugin - it will be fine? Saw a similar problem when you "add plugin -> add platform", but since usually it's another way around - didn't fix it, since there were more critical stuff...

@ZyphiraZircon
Copy link
Author

Yes that does work. The problem is I'm using a script to build multiple apps using different bundle ids from the same cordova project, so in order to make sure the build is not encountering any overlap I remove and re-add the platforms. For now, I've modified the script to remove the plugin and then re-install it once the platforms have been added back. I realize that mine is probably a fringe use-case but thank you for accepting it as a bug!

@LukeHartcher
Copy link

This identical error also occurs using this plugin within Visual Studio Tools for Apache Cordova.

Error: ENOENT: no such file or directory, open '/xxxxx/platforms/ios/CordovaLib/VERSION'

Any thoughts? Should I play around with the order the platforms/plugins are listed within the config.xml file?

@nikDemyankov
Copy link
Member

@LukeHartcher Can you add platform and plugin manually via console instead of doing so in Visual Studio?

Should I play around with the order the platforms/plugins are listed within the config.xml file?

Don't know, how VS works with Cordova, so can't say that this will help. Maybe there is some info on that in their documentation...

@LukeHartcher
Copy link

Thanks @nikDemyankov I will have a look. Unfortunately at this time I do not know exactly how VS performs the build process so will see what I can track down. I have also never built a Cordova project manually outside of VS but that sounds like a potential solution also.

From what you say, I need to (1) add iOS Platform, and once that is complete (2) add plugin?

Within VS you have one config.xml file that contains all the platforms/plugins and you build in one step - you simply select the target platform and press the build button. There is no multi-step process, just kick it off. There is some basic output but nothing detailed, will see if I can increase the output level.

I will start doing some reading!

@nikDemyankov
Copy link
Member

From what you say, I need to (1) add iOS Platform, and once that is complete (2) add plugin?

Yes, correct.

About VS: I don't how it helps with Cordova development, but I'm sure you can construct mobile project without it with the few commands in console.

  1. Create a project:

    cordova create MyCoolApp
    cd ./MyCoolApp
    
  2. Add required platforms:

    cordova platform add ios android
    
  3. Add plugins:

    cordova plugin add cordova-universal-links-plugin
    cordova plugin add <some-other-plugins>
    
  4. Then configure your config.xml.

I think after that you can open the resulting project in VC and it should work fine. Probably VC does the same thing under the hood.

@LukeHartcher
Copy link

Thanks. Earlier today I manually created a project using Cordova CLI on Mac OS X and successfully got the cordova-universal-links-plugin working and compiling in Xcode via the generated .xcodeproj file and the web links opening my app.

Visual Studio 2015 uses a TACO RemoteBuild service that is installed on a Mac and it listens for Build requests from VS, it does the build, then copies .ipa back to VS project folder on Windows. Its pretty cool as you can do all platform build on Windows. The issue is that you dont have any control over the build order and hence cant force the "add platform" before the "add plugin" as you suggest. I posted on the TACO github page about configuring the Build Order but it is not possible, the only suggestion is to do incremental builds in VS by doing an initial build prior to adding the plugin. But that is a pain to manage all the time.

A final question @nikDemyankov - I do not fully understand the Cordova CLI build order either. Once I get the config.xml file setup and working correctly will the app/plugin then build correctly every time i.e platform before plugin? i.e. what does "add platform" and "add plugin" actually do that impacts the build order?

Thanks in advance.

@nikDemyankov
Copy link
Member

add platform creates a native project in platforms/ folder of your Cordova project. If there are some plugins added to the project - they are also installed to the platform.

add plugin downloads plugin from the repo to the plugins/ folder, executes plugin JS hooks (if there is any) and installs plugin sources to the platforms/ folders.

Why there is an ordering problem with this plugin. To be honest, I'm not sure why you get

Error: ENOENT: no such file or directory, open '/Users/Keystoke/Desktop/new_preview_test/platforms/ios/CordovaLib/VERSION'

Usually it's another error, like can't find xml2js module. And that one occurs because UL plugin heavily depends on JS hooks, which are using some additional npm modules. These modules are installed, when you add plugin to the project. But, if you add it to the project without any platform - it's not get executed. Probably, because Cordova doesn't consider plugin as installed until it is added to the actual platform.

When you first add plugin, then add platform - Cordova for some reason executes plugin hooks in parallel: both before_plugin_install and after_prepare. And since after_prepare script depends on not-yet-installed modules - it crashes.

By the way, if TACO RemoteBuild doesn't support Cordova hooks - plugin will not work. If it does and you want to use VC - you can try some dirty hook:

  1. In your Cordova project create scripts/ folder and add there after_platform_add.js.

  2. In it add something like this:

    var spawnSync = require('child_process').spawnSync;
    
    module.exports = function(ctx) {
      // install plugin
      var result = spawnSync('cordova', ['install', 'cordova-universal-links-plugin']);
      if (result.error) {
        throw error;
      }
    };
  3. In your project's config.xml add:

    <platform name="ios"> 
      <hook type="after_platform_add" src="scripts/after_platform_add.js" />
    
      <!-- ... some other preferences for ios -->
    </platform>

As a result, it should install UL plugin only after iOS platform is added to the project. And, of course, you need to remove UL plugin from dependencies in project's config.xml, so it would not be installed by VC.

@LukeHartcher
Copy link

Great post, thanks for all the info.

FYI - I did get node missing module errors (on Mac only) but installed them manually (via sudo npm install -g) and once all were resolved the CLI add plugin worked.

Additionally, when I initially used TACO RemoteBuild the CordovaLib/VERSION file did not physically exist under the platforms folder and hence not found and the error was displayed. Not knowing enough about how/when the CordovaLib gets copied over I was not really sure how to resolve via VS. Another thing to note is that VS uses plugman to add the plugins, so not sure if that changes anything.

Regarding the Cordova hooks, can I still leave the block in config.xml and it will get picked up once the plugin is added by the hook? Or would the hook need to inject these also?

Overall I have found the plugin to be great! Building the web_hooks makes things so much easier and the hardest part is just the iOS/Apple side of things (which I always find more time consuming then Android).

Thanks once again, cheers.

@nikDemyankov
Copy link
Member

Regarding the Cordova hooks, can I still leave the block in config.xml and it will get picked up once the plugin is added by the hook? Or would the hook need to inject these also?

You can leave it in config.xml. Without the plugin it will be ignored by Cordova. When plugin installed - it will be used on each after_prepare stage. For example, when you build your project.

@LukeHartcher
Copy link

@nikDemyankov nikDemyankov added this to the v1.2.1 milestone Sep 8, 2016
@nikDemyankov
Copy link
Member

Released v1.2.1. Hope it works now. If not - will reopen the issue.

@mikegleasonjr
Copy link

mikegleasonjr commented Nov 22, 2016

Still getting the error with v1.2.1:

plugin: cordova-universal-links-plugin
source: npm://cordova-universal-links-plugin
installed version: 1.2.1
remote version: 1.2.1
$ cordova --version
6.4.0

EDIT: I have to follow these steps if I want to rebuild the project:

$ cordova plugin remove cordova-universal-links-plugin --save
$ rm -rf platforms plugins
$ cordova prepare
$ cordova plugin add cordova-universal-links-plugin --save
$ cordova build
$ ...

I also get errors like this...

Error: Cannot find module 'xml2js'

If I don't follow that order...

@nikDemyankov nikDemyankov removed this from the v1.2.1 milestone Nov 25, 2016
@nikDemyankov nikDemyankov reopened this Nov 25, 2016
@nikDemyankov
Copy link
Member

Super weird... Reopening then. The bad thing is that I can't reproduce it myself :(

@mikegleasonjr
Copy link

Should I have npm xcode module installed ?

@nikDemyankov
Copy link
Member

Plugin uses only:

"dependencies": {
    "mkpath": ">=1.0.0",
    "xml2js": ">=0.4",
    "rimraf": ">=2.4",
    "node-version-compare": ">=1.0.1",
    "plist": ">=1.2.0"
  }

And it should install them automatically when you install plugin.

So, if you see Error: Cannot find module 'xml2js' - this means, that in PROJECT_NAME/plugins/cordova-universal-links-plugin/node_modules/ it's missing.

You can try to run in this folder: npm i xml2js.

That might help.

@adityasaxena
Copy link

@nikDemyankov @mikegleasonjr I'm getting the same error as well. However, the same configuration config.xml file works for me on my local machine. Just that when I take this to a remote machine, things stop working.

One observation, my local machine has XCode 8 while the remote machine has XCode 7

@nikDemyankov
Copy link
Member

@adityasaxena the simplest solution would be to go to PROJECT_NAME/plugins/cordova-universal-links-plugin/ and type npm i to install dependency modules. After that it should work fine.

@ramaguduri-bursys
Copy link

@adityasaxena I have the same issue. Remote machine builds fail with xcode v7.2.1. Works with local machine with xcode 8.

Were you able to fix this issue?

@adityasaxena
Copy link

@ramaguduri-bursys yes, I managed to resolve it.
The idea is universal links only work on iOS if builds are created via XCode itself. If, however, you create builds via command line, then the builds will won't exhibit the universal links functionality.

@adityasaxena
Copy link

@nikDemyankov at the end of it, i put these modules as dependencies in my package.json

@ramaguduri-bursys
Copy link

@adityasaxena I am not able to get to even add ios platform using cordova cli when I have the plugins already added.

If I remove the plugin, add platform and then add plugin it works fine.

But if I try to add platform when the plugin is already added it fails with this error

Error: ENOENT: no such file or directory, open '/Users/Keystoke/Desktop/new_preview_test/platforms/ios/CordovaLib/VERSION'
Is there a work around for this? because my build process for all applications are setup up this way already.

Thanks for your help!

@ramaguduri-bursys
Copy link

for now I am going to remove plugin and add this plugin once the platform is added.

@nordnet-deprecation-bot
Copy link
Contributor

👋 Hi! Thank you for your interest in this repo.

😢 We are not using nordnet/cordova-universal-links-plugin anymore, and we lack the manpower and the experience needed to maintain it. We are aware of the inconveniece that this may cause you. Feel free to use it as is, or create your own fork.

🔒 This will now be closed & locked.

ℹ️ Please see #160 for more information.

@nordnet nordnet locked and limited conversation to collaborators Sep 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants