Missing cordova_plugins.js after platform add/prepare
See original GitHub issueWhen 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
:
PluginManager#
writeswww
and notplatform_www
becauseoptions.usePlatformWww
is not truthy? On platform 6.3.0/6.4.0 it does.- During merging the
cordova_plugins.js
version inwww
is deleted, because it does not exist inplatform_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:
- Created 5 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
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
callsremovePlugin
followed byaddPlugin
for each plugin to be installed on the platform api. It setspluginOptions.usePlatformWww
totrue
, 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 setsuninstallOptions.usePlatformWww
tofalse
and if it does during prepare the subsequent call toaddPlugin
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 brokenAndroidStudio.isAndroidStudioProject
check and thereforeuninstallOptions.usePlatformWww
was left thruthy.In
7.0.0
and beyond theAndroidStudio.isAndroidStudioProject
was modified several times, in7.1.4
it just defaults totrue
and in master it has been removed. In all these case it means that the condition is met anduninstallOptions.usePlatformWww
is set tofalse
forremovePlugin
and, in the prepare case, also the subsequentaddPlugin
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 tofalse
at all in theremovePlugin
code.Closing as stale.