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

Does this plugin work with Phonegap Build? #28

Closed
benmcmaster opened this issue Dec 19, 2015 · 71 comments
Closed

Does this plugin work with Phonegap Build? #28

benmcmaster opened this issue Dec 19, 2015 · 71 comments

Comments

@benmcmaster
Copy link

I can't seem to get this to work for Phonegap Build for iOS 9.2. Are the entitlements getting set correctly with PGB?

When I add my .ipa file into
https://limitless-sierra-4673.herokuapp.com/

it complains: Must be able to find entitlements. I looked and there is no archived-expanded-entitlements.xcent at the root of the app contents.

Has anyone got it to work with Phongap Build. Or am I missing something?

@benmcmaster
Copy link
Author

@nikDemyankov
Copy link
Member

Sorry for long answer.

Never tried it with Phonegap Build, so can't tell. Entitlements file is generated by cordova hooks, that are in this plugin. So maybe they are not executed properly. Are there any build logs that can help?

Also, entitlements file is stored in Resources folder of the Xcode project. Maybe validator expects it to be in the root, doesn't find it there and complain? You can try to install .ipa file on your test device and check, if UL is really working. To install it - use iOS device and iTunes on your Mac/Windows machine.

@nikDemyankov
Copy link
Member

Regarding the link you provided. Well, there is another plugin, that had problems with Phonegap Build: nordnet/cordova-hot-code-push#68 . It is also on npm, uses cordova hooks and native code. But the problem was that Phonegap Build didn't include gradle files from the plugin. This was resolved by adding one line in projects config.xml (not the plugins).

So I would say, that plugin should be installed in your app, hooks should be executed. I'd suggest to check if UL really doesn't work by installing builded .ipa, and look for build logs. I'll check the docs for Phonegap Build.

@benmcmaster
Copy link
Author

Hey @nikDemyankov Thank you for the reply!

It's not working when I build it with Phonegap Build. When I open the .ipa and view the .app contents, I see that the plugin's JavaScript code is installed correctly, but I don't see any other entitlement files. When I test the .ipa on my iPhone 6 with iOS 9.2, links are not opening the app. I have Associated Domains in my provisioning profile. And I have an apple-app-site-association file being served correctly.

Another clue... When I tried to load the IPA to iTunes via Application Loader I got this error:

ERROR ITMS-90046: "Invalid Code Signing Entitlements. Your application bundle's signature contains code signing entitlements that are not supported by iOS. Specifically, the value '*' for key 'com.apple.developer.associated-domains' in 'Payload/Vimify.app/Vimify' is not supported."

It's like there are no associated domains are being added from the <universal-links> tag...?

@benmcmaster
Copy link
Author

Also @nikDemyankov here is a link to my Phonegap Build Log:

https://drive.google.com/file/d/0B8jgm2FTXgPSSkNaWURjcm4yeVE/view?usp=sharing

Thank you!

@nikDemyankov
Copy link
Member

Thanks for the logs. I think I found the problem.

According to the logs - PGB (Phonegap Build) doesn't execute plugins JS hooks. It installs the plugin, but after that - just builds the project. Normally in Cordova projects they are executed before the actual build. They task it to configure iOS project and generate entitlements file before the build.

According to the comment from the question about PGB support for Cordova hooks we can see, that they doesn't support them. That's why no entitlements file is found. There are also similar requests in PGB: here and here. I'm afraid, there is nothing I can do about it: it's a PGB issue.

Although, you can try to tweak it:

  1. Create [PROJECT_NAME].entitlements file in your projects root directory. For example, Vimify.entitlements.

  2. Put in it the following:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>com.apple.developer.associated-domains</key>
        <array>
            <string>applinks:[YOUR_HOST]</string>
            </array>
    </dict>
    </plist>

    Replace [YOUR_HOST] with your hostname. For example:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>com.apple.developer.associated-domains</key>
        <array>
            <string>applinks:foobar.com</string>
            </array>
    </dict>
    </plist>
  3. In the projects config.xml add the following:

    <platform name="ios">
        <resource-file src="[PROJECT_NAME].entitlements" />
    </platform>

    For example:

    <platform name="ios">
        <resource-file src="Vimify.entitlements" />
    </platform>

So, the idea is to manually create entitlements file and tell PGB to copy it in the project. Maybe this would work, because that is close to the thing, that hooks are doing.

@nikDemyankov
Copy link
Member

But this is iOS-only hack.

@benmcmaster
Copy link
Author

I followed your instructions above. And built my IPA using PGB. I loaded my resulting IPA into this universal link validator: https://limitless-sierra-4673.herokuapp.com/ I get this errors:

Must be able to find entitlements (looking in VimifyDev/Payload/VimifyDev.app/archived-expanded-entitlements.xcent)

Should I change the file name from Vimify.entitlements to archived-expanded-entitlements.xcent?

Trying that now...

@benmcmaster
Copy link
Author

Another problem is that PGB won't put the entitlements file at the root of the .IPA. It seems that the <resource-file> tag is not copying the file from www folder into the root of the IPA.
Here's is an issue on phonegap's build repo:
phonegap/build#472

@nikDemyankov
Copy link
Member

No, you don't have to change the name to archived-expanded-entitlements.xcent, that would not work. It should not, at least.

If PGB doesn't support cordova hooks and there is no way to include custom resource files - then I guess there is nothing that can be done at the moment...

@nikDemyankov
Copy link
Member

Closing it, since this is a PGB issue, nothing can be done at the moment.

@jskrepnek
Copy link

@benmcmaster were you able to discover a workaround to get the plugin working with Build?

@benmcmaster
Copy link
Author

@jskrepnek No. Not using Universal Links yet with my app. I just pointed all my links in emails and such to a redirect page that called a customURL. It's ghetto and one extra tap for the user... but it works for now. I am very close to just using Xcode to build my app. I am hoping PGB will add the features needed to get this working.

@VanVan
Copy link

VanVan commented Jun 27, 2016

Phonegap Build support now Cordova Hooks :
http://stage.docs.phonegap.com/tutorials/configure/04-using-hooks/

Your plugin should be compatible with Phonegap Build

@benmcmaster
Copy link
Author

@VanVan Do you mean that this plugin should just work in it's current state? Or is there any work that needs to be done?

@nikDemyankov
Copy link
Member

@benmcmaster I think it should work as it is. Only concern is that I had some reports, that PGB removes custom tags from the config.xml. If it's not gonna do that - it should be fine.

@gazzaf
Copy link

gazzaf commented Jul 27, 2016

I would love to know if anyone has got this plugin working with PhoneGap Build? If so did you do anything special to get it working with iOS and Android? Thanks in advance.

@kimras
Copy link

kimras commented Aug 28, 2016

Hi,
I am experiencing same issue - Any one have it working with Phonegap Build ?
Thanks
Kim

@LarsVoith
Copy link

PhoneGap build needs to support this! We need a real answer why PGB wont support it.

@lanista-training
Copy link

Any news ?

@yoav-zibin
Copy link

Nope, I've just tried and it doesn't work with phonegap build system (and I'm using gradle, not PGB).

I think the issue is that hooks are not supported in phonegap build.
I've found these discussions on phonegap build forums (many people are trying to use this plugin with phonegap build :))
https://forums.adobe.com/message/8871386
https://forums.adobe.com/message/8976135

This is my config.xml:
https://github.com/yoav-zibin/phonegap-tictactoe/blob/gh-pages/www/config.xml
You can see I'm using gradle:
preference name="android-build-tool" value="gradle"

When I looked in the generated android manifest:
AndroidManifest copy.xml.txt
I was expecting to see:
intent-filter android:autoVerify="true"
but it's not there.

What do the hooks do exactly?
I've seen above, in comment "nikDemyankov commented on Dec 22, 2015" that the hooks modify the android manifest and ios property list. (But it mentions PGB, and I'm using gradle.)
Phonegap build has mechanisms to modify these:
http://phonegap.com/blog/2014/01/30/customizing-your-android-manifest-and-ios-property-list-on-phonegap-build/
If hooks are used just for that, then I can try to manually do these customizations and unblock a lot of people that want to use this plugin in phonegap build :)

@nikDemyankov
Copy link
Member

@yoav-zibin Hooks are used to generate platform-specific preferences depending on the things you define in config.xml. The idea is that you define which links you want to handle in the app - and hooks generate all the configurations for you.

For iOS:

  • apple-app-site-association file, that you deploy on your server.
  • .entitlements file with domain settings.
  • modifies .xcodeproj settings, mainly to point native project to the entitlements file.

For Android:

  • generates settings in AndroidManifest.xml.
  • generates template/example for your web site integration.

Sure, I think that can be done manually, although hooks are really simplifying developer's life :)

But the problem with PGB is not only in the hooks. As I remember, it also removes custom tags from the config.xml. And plugin need these preferences to understand, what event to fire and send data to JS side when app is launched via the link.

Even if you configure everything manually - event is not gonna be triggered, unless you modify native code as well by defining urls in it. But yeah, everything can be done :) Although, it will require some hacking.

@VanVan
Copy link

VanVan commented Oct 12, 2016

@benmcmaster I mean Phonegap build support now everything needed for it to works, but there are some changes to do.

  • You can use Hooks during build

    - Javascript
    - Non-Javascript via Node
    
  • You can customize AndroidManifest.xml and iOS params without Hooks

<gap:config-file platform="ios" parent="FOO"> <string>BAR</string> </gap:config-file>

<config-file platform="ios" target="*-Info.plist" parent="UISomething"></config-file>

<gap:config-file platform="android" target="AndroidManifest.xml" parent="/manifest"></gap:config-file>

  • You can transmit custom tags/params, just put it in plugin config (without gap:plugin)

<plugin name="cordova-universal-links-plugin" source="npm"> <param name="FOO" value="BAR" /> </plugin>

@benmcmaster
Copy link
Author

@VanVan That's encouraging! But, I don't quite understand your answer... Do you have this plugin working on your app built with PGB? Can you please share example config code? Thank you!

@nikDemyankov nikDemyankov reopened this Oct 12, 2016
@kimras
Copy link

kimras commented Oct 13, 2016

I have discussed this with PGB support - they say, and might I add I understand, that they the see hooks as a Security risk for them as you could put anything in the Hooks that messe up the Build machine.
I have asked for an alternative way to change this, and are hoping that they will implement some other way to manipulate the project entitlement file.

@VanVan
Copy link

VanVan commented Oct 13, 2016

@benmcmaster I didn't do the change needed.
@nikDemyankov You can now include platform dependent custom resources file in merges/android, or merges/ios

We are also supporting the merges directory that enables you to include platform specific assets in your project. During build the merges directory for each platform will be copied over your www directory.

If we look at cordova-universal-links-plugin/hooks/afterPrepareHook.js
You should customize AndroidManifest.xml and iOS params without Hooks helped by gap config.xml
<gap:config-file platform="ios" parent="FOO"> <string>BAR</string> </gap:config-file>

<config-file platform="ios" target="*-Info.plist" parent="UISomething"></config-file>

<gap:config-file platform="android" target="AndroidManifest.xml" parent="/manifest"></gap:config-file>

If we look at cordova-universal-links-plugin/hooks/beforePluginInstallHook.js it seems to check dependency of

  • mkpath
  • xml2js
  • rimraf
  • node-version-compare
  • plist

If we look at cordova-universal-links-plugin/hooks/iosBeforePrepareHook.js it seems related to .entitlements file. (not required for android)

phonegap-plugin-push for example is compatible with phonegap build and removed hooks :
https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PHONEGAP_BUILD.md

Is there something on this plugin that can't be done without hooks on android ? I didn't look at .entitlements on ios, but is it really the only way to do ?

@kimras
Copy link

kimras commented Nov 4, 2016

same here, I am happy to test it as well..

Thanks in advance
Kim

On Fri, Nov 4, 2016 at 1:27 PM, Yoav Zibin notifications@github.com wrote:

PGB pretty please :)
I'll follow the instructions myself to add it to my PGB project and give
you feedback :)
On Fri, Nov 4, 2016 at 5:01 AM Nikolay Demyankov <notifications@github.com

wrote:

@simpleekare https://github.com/simpleekare you want me to write this
docs on how to do that via PGB build, or just in general in native
project?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://github.com/nordnet/cordova-universal-links-
plugin/issues/28#issuecomment-258376005>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/
ABzZHX4rjH7NzhfK0MiDJ7TzjPlJ-5NIks5q6vRpgaJpZM4G4kcK>
.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#28 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AEx-FxNkEdeyy4Lh8SWFxGqpHrsW10UEks5q6ySYgaJpZM4G4kcK
.

Kim Rasmussen
geoQuestor IVS
Tel: +45 30500110

https://www.geoQuestor.com

@ghost
Copy link

ghost commented Nov 7, 2016

@nikDemyankov for PGB build. I am happy to test.

@nikDemyankov
Copy link
Member

Understood, will do :)

@yoav-zibin
Copy link

@nikDemyankov , I don't even need a doc if you have an example of a config.xml that's working on PGB :)
E.g., here is my config.xml example:
https://github.com/yoav-zibin/phonegap-tictactoe/blob/gh-pages/www/config.xml

@raymondelferink
Copy link

I'm very happy to test

@ghost
Copy link

ghost commented Nov 21, 2016

Hi @nikDemyankov, did you get chance to work on this?

@nikDemyankov
Copy link
Member

Hi @simpleekare,
No, not much. Swamped with work right now...

@maktibab
Copy link

No news? How can we help you?
It will be pretty cool if the plugin can work with PGB :)

@nikDemyankov
Copy link
Member

nikDemyankov commented Jan 25, 2017

@maktibab didn't have time to work on any of the github stuff lately because of the releases at work. But now it's done, so was planning to start with PGB on UL plugin first this weekend, and then continue with CHCP plugin v2. Sorry for the delay, everyone...

@maktibab
Copy link

@nikDemyankov it's the better news I'have read from 2017! I will test your stuff as soon as I can.

nikDemyankov added a commit that referenced this issue Jan 29, 2017
…l.json, and if it doesn’t exist - use preferences from config.xml as before. iOS only for now.

#28
@maktibab
Copy link

maktibab commented Feb 1, 2017

@nikDemyankov everythink is okay for a test? Or you need to do dev another. Do you have a doc to use?

@nikDemyankov
Copy link
Member

@maktibab In the last commit I've added code for iOS to load plugin's config from www/ul.json file. From now on native side of the plugin will try to load preferences from that config. If it doesn't exist - it will use config.xml as before. And when the plugin captures the event - it will redirect it to the web as usual. So that part is solved (for iOS for now, Android is coming soon).

To test this instead of putting preferences in config.xml - you create a www/ul.json config with the following structure:

[{
    "host": "domain.com",
    "event": "general_event",
    "path": [{
         "url": "/first/path",
         "event": "first_event_name"
    }, {
         "url": "/second/path"
    }]
}]

As you can see - it is similar to what we have right now in config.xml.

Now we need to understand how to put things in .entitlements file. I know that in Cordova iOS platform v4.3 you can add stuff to Entitlements-Release.plist and Entitlements-Debug.plist files though plugin.xml. But not sure how you can do that through the config.xml.

Also, they have messed it up a bit: these files should have extension .entitlements instead of .plist in order for Xcode to see them. They a issue for that: CB-12316. But it should work anyways. It's just a heads up for those who will open project in Xcode and not gonna see entitlement files in the project and Associated Domains feature as activated.

So now the plan is:

  1. Understand, how to add stuff to entitlement files.
  2. Implement json config loading in Android.
  3. Understand, how to add properties to the root activity in the AndroidManifest.xml.

The second one is the easiest :) One and three are the most painful since we don't have hooks support.

@yoav-zibin
Copy link

You can do (3) like this:
http://docs.phonegap.com/phonegap-build/configuring/config-file-element/
E.g.,
https://github.com/phonegap/phonegap-plugin-push/blob/00c67cb2c85e97dfe4f7020f28ad4d954458599f/plugin.xml#L29

I used it to remove permissions I don't use like this:
<config-file platform="android" parent="/manifest" mode="delete"> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> </config-file>

I'm not sure about (1), but I looked at a push-notification plugin that I use, and they pass the entitlement key in the .plist file like this:
https://github.com/phonegap/phonegap-plugin-push/blob/00c67cb2c85e97dfe4f7020f28ad4d954458599f/plugin.xml#L98
<config-file target="*-Debug.plist" parent="aps-environment"> <string>development</string> </config-file> <config-file target="*-Release.plist" parent="aps-environment"> <string>production</string> </config-file>

Note that aps-environment is a Notification entitlement key see
https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingLocalAndPushNotifications.html#//apple_ref/doc/uid/TP40011195-CH3-SW1

Can you try that to see if it will work for (1)?

@nikDemyankov
Copy link
Member

@yoav-zibin not really.

Your first link is to PGB configuration documentation. According to it you can specify additional preferences for app configuration files in your project's config.xml. But it will only work for two of them, as stated in their docs:

platform: currently supported values are ios (Info.plist) and android (AndroidManifest.xml)

So, we can't use that for entitlements - iOS. Although, it can be used for Android.

About the second link - yes, you can add preferences to entitlements via plugin.xml config. But the problem is, that these preferences should be app-specific. To be able to add your own domains - you will have to:

  1. Fork this repo.
  2. Modify plugin.xml by adding app-specific preferences.
  3. In config.xml tell PGB to fetch plugin from your git url.

That should work, but it feels like a hack. That's why I said that 1 and 3 are the trickiest. But if someone wants to try out the plugin.xml approach - they can for iOS.

Let's say you had these preferences before in config.xml:

<universal-links>
  <host name="mywebsite.com">
    <path url="/first/path" event="first_event_name" />
    <path url="/second/path" event="second_event_name" />
  </host>
</universal-links>
  1. Fork this repo.
  2. In your new repo open plugin.xml and add the following:
<config-file target="*/Entitlements-Debug.plist" parent="com.apple.developer.associated-domains">
      <array>
        <string>applinks:mywebsite.com</string>
      </array>
</config-file>

<config-file target="*/Entitlements-Release.plist" parent="com.apple.developer.associated-domains">
      <array>
        <string>applinks:mywebsite.com</string>
      </array>
</config-file>
  1. In your project create www/ul.json file with the following content:
[{
    "host": "mywebsite.com",
    "path": [{
        "url": "/first/path",
        "event": "first_event_name"
    }, {
        "url": "/second/path", 
        "event": "second_event_name"
    }]
}]
  1. In your project's config.xml define link to the UL plugin:
<plugin spec="https://github.com/YOUR_ACCOUNT_NAME/cordova-universal-links-plugin.git" source="git" />
  1. Now the project should be configured and you can try it out.

@yoav-zibin
Copy link

I'm not sure you have to fork: you can pass parameters to the plugin, and then use them in plugin.xml like this:
<string name="google_app_id" translatable="false">$SENDER_ID</string>

The most common use case is just have a single universal link that you want to handle, e.g., for me it's https://friendlygo.com/
I think passing one parameter for your domain and using it in plugin.xml is an acceptable first step that will satisfy most users (no need to support all the plugin features on PGB :))

@nikDemyankov
Copy link
Member

@yoav-zibin yes, but the problem is not in passing parameters to the plugin. The problem is that we need to add some preferences to the native config - .entitlements file. And these preferences tell native platform (iOS) that we are supporting Universal Links technology.

Right now for non-PGB projects this is handled by the plugin's JS hooks: when you build the project - they generate this .entitlements file and add it to the native project. But since we don't have hooks support - we need other ways to add preferences in there. And for now the only way I found to do that is with forking, because you can't inject preferences in .entitlements file via config.xml. At least I didn't find it in the documentation...

@maktibab
Copy link

maktibab commented Feb 10, 2017

@nikDemyankov I have try the fork solution. Not yet working on android and ios.

On Android after pgb generate the apk file, I did not find some intent reference in the AndroidManifest.xml.
On IOS after pbg generate the ipa file, nothing in the info.plist. No folder ul_web_hooks / ios found...

Do I miss something?

@nikDemyankov
Copy link
Member

@maktibab

On Android after pgb generate the apk file, I did not find some intent reference in the AndroidManifest.xml.

At the moment fork solution is only for iOS. Wanted to test it first.
Also, you should use Cordova iOS platform version 4.3 or above.

On IOS after pbg generate the ipa file, nothing in the info.plist.

It should not be in the info.plist. It should be in Entitlements-Debug.plist and Entitlements-Release.plist. But if these files are not allowed by the PGB - then we are screwed.

No folder ul_web_hooks / ios found...

That folder is generated by the plugin's JS hooks. And it's just for developer's convenience so he/she would not need to generate apple-app-site-association file manually. It is not bundled with the app but placed manually in the root of your site. If you already have this file on your site - good. If not - you can create it as described here or here.

@maktibab
Copy link

@nikDemyankov

It should not be in the info.plist. It should be in Entitlements-Debug.plist and Entitlements-Release.plist. But if these files are not allowed by the PGB - then we are screwed.

Only info.plist found in the ipa file generated by PGB :(

@nikDemyankov
Copy link
Member

nikDemyankov commented Feb 16, 2017

@maktibab Okay, thanks for testing, I'll see what can be done.

@maktibab
Copy link

maktibab commented Mar 9, 2017

@nikDemyankov some news about this issue?

@nikDemyankov
Copy link
Member

@maktibab no, sorry, didn't have time to do anything lately... I'm really struggling right now with supporting plugins.

@harymitchell
Copy link

For those working on a stopgap or the permanent fix, there are going to be some obstacles for iOS. This is the most recent reference I can offer: https://forums.adobe.com/thread/2290461

@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.
Projects
None yet
Development

No branches or pull requests