question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing cordova_plugins.js after platform add/prepare

See original GitHub issue

When adding android platform 7.0.0/7.1.4 on an existing project I can build/install the app, but it is non-functional because cordova_plugins.js is missing. All is fine using android platform 6.3.0/6.4.0.

I did some debugging and what I can see when I do cordova platform add android@7.1.4:

  1. PluginManager# writes www and not platform_www because options.usePlatformWww is not truthy? On platform 6.3.0/6.4.0 it does.
  2. During merging the cordova_plugins.js version in www is deleted, because it does not exist in platform_www.
Merging and updating files from [www, platforms/android/platform_www] to platforms/android/app/src/main/assets/www
...
  delete platforms/android/app/src/main/assets/www/cordova_plugins.js (no source)

When I subsequently add a plugin using cordova plugin add the cordova_plugins.js is being created in both www and platform_www and everything is fine again.

From CB-11022 I got that the usePlatformWww was added as an optimization, but Iḿ not clear how this should work here (or why it breaks).

version disclosures: node@v6.9.5 npm@3.10.10 cordova@8.1.2 (cordova-lib@8.1.1)

edit1: Adding a plugin using cordova plugin add does not solve it. The resulting apk does now contain a full cordova_plugins.js , but the plugin resources themselves actually have not been added. So now I get these messages:

019-01-23 15:25:23.767 6710-6788/com.equestic E/AndroidProtocolHandler: Unable to open asset URL: file:///android_asset/www/plugins/cordova-plugin-appminimize/www/AppMinimize.js
2019-01-23 15:25:23.773 6710-6788/com.equestic E/AndroidProtocolHandler: Unable to open asset URL: file:///android_asset/www/plugins/cordova-plugin-background-mode/www/background-mode.js

edit2 The plugin resources are missing for the same reason. They are being deleted during the merge.

  rmdir  platforms/android/app/src/main/assets/www/plugins/cordova-plugin-camera (no source)
  rmdir  platforms/android/app/src/main/assets/www/plugins/cordova-plugin-camera/www (no source)
  delete platforms/android/app/src/main/assets/www/plugins/cordova-plugin-camera/www/Camera.js (no source)
  delete platforms/android/app/src/main/assets/www/plugins/cordova-plugin-camera/www/CameraConstants.js (no source)
  delete platforms/android/app/src/main/assets/www/plugins/cordova-plugin-camera/www/CameraPopoverHandle.js (no source)
  delete platforms/android/app/src/main/assets/www/plugins/cordova-plugin-camera/www/CameraPopoverOptions.js (no source)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
bramkcommented, Jan 23, 2019

Took another look and found what seems to be the source of my problem, but still not sure how to proceed and/or solve this in the correct way.

Cordova Lib during prepare#restoreMissingPluginsForPlatform calls removePlugin followed by addPlugin for each plugin to be installed on the platform api. It sets pluginOptions.usePlatformWww to true, but notice how it reuses that object for both calls! This code has not changed in the last couple of releases.

https://github.com/apache/cordova-lib/blob/a478ce39b44a957ba1f960f380c75b6353213aa4/src/cordova/prepare.js#L162-L170

Cordova Android during removePlugin conditionally sets uninstallOptions.usePlatformWww to false and if it does during prepare the subsequent call to addPlugin will have that also receive that value. That particular logic has changed a lot over the last couple of releases.

In 6.4.0 it seems the condition was never met due to a broken AndroidStudio.isAndroidStudioProject check and therefore uninstallOptions.usePlatformWww was left thruthy.

In 7.0.0 and beyond the AndroidStudio.isAndroidStudioProject was modified several times, in 7.1.4 it just defaults to true and in master it has been removed. In all these case it means that the condition is met and uninstallOptions.usePlatformWww is set to false for removePlugin and, in the prepare case, also the subsequent addPlugin call.

https://github.com/apache/cordova-android/blob/a68f9fd752a25bb680da96414a3b956357c2dfcb/bin/templates/cordova/Api.js#L274-L277

I think there is some code smell here? One could argue that Cordova lib should make a defensive copy, but tbh I also simply do not understand why usePlatformWww is set to false at all in the removePlugin code.

0reactions
breautekcommented, May 18, 2022

Closing as stale.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cordova.js is missing on a new project - Stack Overflow
No, you're all good. Cordova.js will be generated when you build a specific platform (i.e. cordova build android ).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found