Search code examples
codenameonepubnub

Codename One - How to (correctly) add the PubNub library and use it


I'm trying to do the first steps with Codename One + PubNub. I guess that the default and best supported way to install a library is using the "Extensions" in the "Codename One Preferences": it installs the PubNub library 3.7.8 and requires a previous install of BouncyCastleCN1Lib.

But the last version of the PubNub CodenameOne SDK is 3.7.11? https://www.pubnub.com/docs/codename-one-java/pubnub-java-sdk

No, maybe something is wrong in the documentation, because clicking on the link to Pubnub-CodeNameOne-3.7.11.cn1lib opens a GitHub repository with the 3.7.8 version: https://github.com/pubnub/java/tree/master_3x/codenameone

Moreover, in the example it's asked to import org.json.*;, but that package is not available in the Codename One API, as you can check here: https://www.codenameone.com/javadoc/

So I'm confused. Can somebody explain how to correctly add the PubNub library to a Codename One project? A working code example should be great.


Solution

  • Pubnub has their own JSON cn1lib which is a bit of a hack where they rely on org.json. We made that work for this and they have their own cn1lib to match that.

    I suggest downloading it directly from their site and not through the extension manager. I think we need to remove it from there as the extension has some problematic dependencies.

    Currently I'm not sure what's the status of pubnub as most users left it. WebSockets made this type of networking much easier and we currently recommend using that.