Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Maxim_P_2
Beginner
100 Views

Platform dependent plugin management

Hello, 

We are building a Cordova hybrid application. The platforms are iOS and Android. XDK version is 3641. 

Is it possible to add Cordova plugins per specific platform? For example Android platform has plugins A and B, whereas iOS has plugins A, B and C. It appears that Plugin Management section adds plugins for all available platforms regardless the platform selector. 

If it is not possible to achieve this through user interface, is it OK to manually edit configuration files, ie removing plugin C from intelxdk.config.android.xml or android.json files. 

Thanks,

Max 

 

 

Tags (2)
0 Kudos
9 Replies
PaulF_IntelCorp
Employee
100 Views

Max -- the XDK does not offer an easy way to manage plugins on a per platform basis. We are using the standard Cordova model (the XDK builds standard Cordova apps) and, as you have noted, the plugin manager installs the plugins for all platforms. Attempting to edit the config files will do not good, because they are recreated with each build you perform, your edits are removed. We no longer support specifying plugins in the additions.config.xml file, because it causes issues with the build system and will not work at all in a future release of the build system.

I think the "simplest" approach is to build two projects, one is your active app that you are working on and the second is a mirror image. Link the "www" folder in the master project to the mirrored project. I recommend using hard links, as some aspects of the XDK do not work properly with soft links. In other words, create a second project (from blank project) and replace the "www" folder in it with a link to the "www" folder in the existing project. Then setup the settings and plugins independently for each project.

Maxim_P_2
Beginner
100 Views

Thank you for a quick response! So there is no way to employ something similar to Plugman which allows more control over plug in management? 

PaulF_IntelCorp
Employee
100 Views

We use plugman in the backend, but we do not distinguish between platforms within the project on the front-end, at least as far as plugins are concerned. It is not our goal to support all scenarios that developers might desire. If you need to go beyond what we provide we recommend that you use Cordova CLI directly.

Maxim_P_2
Beginner
100 Views

Thanks for clarification! Just one last bit of a puzzle. What about platform specific plugins. For example we use `cordova-plugin-wkwebview-engine`. The plugin is supported/relevant only on iOS. However it appears in 'android.json' and 'intelxdk.config.android.xml' as well. Will it be ignored for Android builds? We actually use Crosswalk on Android. 

PaulF_IntelCorp
Employee
100 Views

Yes, platform-specific plugins will be ignored by other platforms. If you inspect the plugin.xml file inside the plugin you can see which platforms are supported. Only those platforms that have corresponding support inside the plugin.xml will actually get the plugin included in their system. They may still see the JavaScript side of that code, which means you should test the platform and avoid calling those APIs (detecting for the presence of the API may not be sufficient, I don't recall precisely what happens, been a while since I last checked this out). You can check a platform using something like what is used in this code snippet:

app.windowEventOrientationChange = function() {
    "use strict" ;
    var fName = "windowEventOrientationChange():" ;

    var str = "" ;
    var screenOrientation = "unknown" ;

    if( window.cordova ) {
        if( cordova.platformId.match(/ios/i) )
            screenOrientation = screen.orientation ;
        else if( cordova.platformId.match(/android/i) )
            screenOrientation = screen.orientation.type ;
    }

    str = "Screen orientation is: " + screenOrientation ;
    app.consoleLog(fName, str) ;
//    app.alert(str, 1000) ;
} ;
window.addEventListener("orientationchange", app.windowEventOrientationChange) ;

 

Maxim_P_2
Beginner
100 Views

This is great. Thank you very much for your help and support! 

Hamilton_Tenório_da_
Valued Contributor I
100 Views

Paul> Let me ask you a thing. I use in one app in my config.xml one statement to remove a plugin in iOS build. It is:

<!-- Remove a plugin from the �ios� build configuration: -->
<!-- -iOS --><intelxdk:plugin intelxdk:name="cordova-plugin-background-mode" />

You said "We no longer support specifying plugins in the additions.config.xml ...". It means that this statement above won´t work more?

Thanks.

PaulF_IntelCorp
Employee
100 Views

Hi Hamilton -- I forgot about that trick! Yes, it will still work, because it causes the part of the XDK that generates those platform-specific to remove the tag that was specified by the "-iOS" pseudo-tag. The dynamic code-checking approach is probably better, because if you need to move your app to Cordova CLI the additions.xml trick you are using will no longer work, but the dynamic platform check will still work.

Maxim_P_2
Beginner
100 Views

Thank you Hamilton and Paul! We ended up using the '-iOS' tag along with dynamic code checking. 

Reply