TLDR : Why aren't my Cordova plugins being installed in a clean Visual Studio build?
我有一个正在使用 Visual Studio 2015 开发的 Cordova 应用程序。我认为一切都很好,但是当 Android 版本在 TFS 构建服务器上构建时,虽然没有错误,但生成的应用程序不包含配置的插件。我认为这是构建服务器的问题,但现在已经能够在我的开发机器上重现它。
Cordova 的版本是 5.4.1,Android 平台是 4.1.1。
该platforms
文件夹不受版本控制,因此在构建服务器上执行构建时该文件夹将不存在,因此应在构建过程中添加Android平台。为了复制它,我在我的开发机器上删除了它。当我从 Visual Studio 运行第一个构建时,调试或发布没有区别,一切似乎都正常。构建输出包含
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"
在此构建之后,我注意到该platforms\android\assets\www
文件夹不包含cordova_plugins.js
文件plugins
夹,尽管该platforms\android\src
文件夹包含所有插件子文件夹和 Java 类文件。
下次我执行构建时,输出包含
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:
现在该platforms\android\assets\www
文件夹确实包含插件信息,并且插件在应用程序中正常运行。
我试图查看是否可以通过 Cordova 命令行重现该问题,所以我platforms
再次删除并运行
%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>`.
所以我添加了平台
%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.
如果我现在在 Visual Studio 中构建它,插件会正确添加到应用程序中。因此,根据输出的差异,似乎 Visual Studio 添加平台时没有正确添加插件。
谁能解释为什么会这样,以及如何纠正这种情况?