TLDR : Why aren't my Cordova plugins being installed in a clean Visual Studio build?
I have a Cordova app that is being developed using Visual Studio 2015. I thought everything was fine, but when the Android version was built on a TFS build server, although there are no errors the resulting app did not include the configured plugins. I thought this was a problem with the build server but have now been able to reproduce it on my development machine.
The version of Cordova is 5.4.1 and the Android platform is 4.1.1.
The platforms
folder is not under version control, so when a build on the build server is performed the folder will not exist, so the Android platform should be added by the build process. To replicate this I deleted it on my development machine. When I ran the first build from Visual Studio, debug or release makes no difference, all appears to go okay. The build output contains
1> ------ Adding platform: android
1> Executing "before_platform_add" hook for all plugins.
1> No version supplied. Retrieving version from config.xml...
1> Adding android project...
1> Failed to require PlatformApi instance for platform "android". Using polyfill instead.
1> Running command: cmd "/s /c "C:\Users\XXXX\.cordova\lib\npm_cache\cordova-android\4.1.1\package\bin\create.bat "D:\ZZZZ\My App\platforms\android" uk.co.domain.myapp "My App" --cli""
1> Creating Cordova project for the Android platform:
1> Path: platforms\android
1> Package: uk.co.domain.myapp
1> Name: My App
1> Activity: MainActivity
1> Android target: android-22
1> Copying template files...
1> Android project created with cordova-android@4.1.1
1> Command finished with error code 0: cmd /s /c "C:\Users\XXXX\.cordova\lib\npm_cache\cordova-android\4.1.1\package\bin\create.bat "D:\ZZZZ\My App\platforms\android" uk.co.domain.myapp "My App" --cli"
After this build I noticed that the platforms\android\assets\www
folder does not contain cordova_plugins.js
or a plugins
folder, although the platforms\android\src
folder contains all the plugin sub-folders and Java class files.
The next time I perform a build the output contains
1> ------ Platform android already exists
1> ------ Copying native files from D:\ZZZZ\My App\res\native\android to platforms\android
1> ------ Copied D:\ZZZZ\My App\res\native\android\ant.properties to platforms\android\ant.properties
1> ------ Done copying native files to platforms\android
1> ------ Updating plugins
1> ------ Currently installed plugins: cordova-plugin-file@4.1.0,cordova-plugin-file-opener2@2.0.2,cordova-plugin-file-transfer@1.5.0,cordova-plugin-whitelist@1.2.1
1> ------ Currently installed dependent plugins:
1> ------ Currently configured plugins:
Now the platforms\android\assets\www
folder does contain the plugin information, and the plugins function correctly in the app.
I tried to see if I could reproduce the problem via the Cordova command line, so I deleted the platforms
again and ran
%appdata%\npm\node_modules\vs-tac\node_modules\cordova\5.4.1\node_modules\.bin\cordova build android
Error: No platforms added to this project. Please use `cordova platform add <platform>`.
So I added the platform
%appdata%\npm\node_modules\vs-tac\node_modules\cordova\5.4.1\node_modules\.bin\cordova platform add android
Adding android project...
Running command: cmd "/s /c "C:\Users\XXXX\.cordova\lib\npm_cache\cordova-android\4.1.1\package\bin\create.bat "D:\ZZZZ\My App\platforms\android" uk.co.domain.myapp "My App" --cli""
Creating Cordova project for the Android platform:
Path: platforms\android
Package: uk.co.domain.myapp
Name: My App
Activity: MainActivity
Android target: android-22
Copying template files...
Android project created with cordova-android@4.1.1
Finished executing "before_prepare" hook for android
Installing "cordova-plugin-file" for android
The Android Persistent storage location now defaults to "Internal". Please check this plugins README to see if you application needs any changes in its config.xml.
If this is a new application no changes are required.
If this is an update to an existing application that did not specify an "AndroidPersistentFileLocation" you may need to add:
"<preference name="AndroidPersistentFileLocation" value="Compatibility" />"
to config.xml in order for the application to find previously stored files.
Installing "cordova-plugin-file-opener2" for android
Installing "cordova-plugin-file-transfer" for android
Dependent plugin "cordova-plugin-file" already installed on android.
Installing "cordova-plugin-whitelist" for android
This plugin is only applicable for versions of cordova-android greater than 4.0. If you have a previous platform version, you do *not* need this plugin since the whitelist will be built in.
If I build it now in Visual Studio the plugins are added correctly to the app. So based on the difference in the output, it seems that when Visual Studio adds the platform it is not correctly adding the plugins.
Can anyone explain why this might be, and how to remedy the situation?