Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ondeviceready won't fire because plugin does not cleanup after itself properly when removed(?) #927

Open
3 tasks done
igorsantos07 opened this issue Oct 15, 2023 · 4 comments
Labels

Comments

@igorsantos07
Copy link

igorsantos07 commented Oct 15, 2023

Bug Report

Originally reported at apache/cordova-plugin-device#125

Problem

If an application has this plugin installed and, for some reason, it's not needed anymore and removed, ondeviceready won't fire anymore.
This seems to be caused by some leftover code... That's probably why the previous reporter mentioned the usual shenanigans of add/remove platform/plugins solved it.

What is expected to happen?

The event should fire as usual, since it's seemingly unrelated to this plugin.

What does actually happen?

ondeviceready never gets fired:
image

Logcat displays the following (easier to find if you filter logcat by the package name):

2023-10-14 22:59:13.783 29167-29267 PluginManager           io.cordova.hellocordova              D  exec() call to unknown plugin: Device
2023-10-14 22:59:13.834 29167-29167 chromium                io.cordova.hellocordova              I  [INFO:CONSOLE(80)] "[ERROR] Error initializing cordova-plugin-device: Class not found", source: https://localhost/plugins/cordova-plugin-device/www/device.js (80)
2023-10-14 22:59:18.645 29167-29167 chromium                io.cordova.hellocordova              I  [INFO:CONSOLE(1237)] "deviceready has not fired after 5 seconds.", source: https://localhost/cordova.js (1237)
2023-10-14 22:59:18.645 29167-29167 chromium                io.cordova.hellocordova              I  [INFO:CONSOLE(1230)] "Channel not fired: onCordovaInfoReady", source: https://localhost/cordova.js (1230)

Command or Code

$ cordova create sample-reproduction
$ cd sample-reproduction
$ cordova platform add android
$ cordova plugin add cordova-plugin-device
$ cordova plugin rm cordova-plugin-device
$ cordova run android

Environment, Platform, Device

  • cordova-android: 12.0.0 and 12.0.1
  • plugin: 2.1.0 (as in clean install below), and also our actual project had it installed on 1.1.4, upgraded to 2.1.0, then realized it's not used and thus, got removed. We also removed other plugins and didn't had this kind of trouble.
  • device: Android emulator, API 30

Version information

Nothing besides what was described above seems relevant.

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@igorsantos07 igorsantos07 changed the title ondeviceready won't fire because plugin does not clean after itself properly when removed(?) ondeviceready won't fire because plugin does not cleanup after itself properly when removed(?) Oct 15, 2023
@TheNotorius0
Copy link

I just had this bug too. I updated the plugin using cordova plugin remove cordova-plugin-device --force and then cordova plugin add cordova-plugin-device and I got this bug.

It worked again after I did cordova platform remove android, cordova plugin remove cordova-plugin-device, cordova plugin add cordova-plugin-device, and then cordova platform add android, but it was a bit of a hassle.

@breautek breautek added the bug label Jul 26, 2024
@breautek
Copy link
Contributor

I've confirmed that the repro steps reliably reproduces the issue. Seems weird it would only affect this plugin though.

There are 3 main paths (relative to the root of the cordova project) that cordova tracks installed plugins:

  1. /plugins/android.json
  2. /plugins/fetch.json
  3. /platforms/android/platform_www/cordova_plugins.js
  4. also /platforms/android/platform_www/plugins/cordova-plugin-device/

The first 2 is cleaned up as expected.
The third one instructs the cordova runtime about what is "installed" and that isn't being cleaned up, so as far as the app runtime is concerned the plugin does exist.
The 4th bonus one is the plugin JS code which is also not cleaned up.

The native java code however is cleaned up as expected.

@breautek
Copy link
Contributor

Some additional information I've found when testing other plugins and will explain:

We also removed other plugins and didn't had this kind of trouble.

So first this bug does occur on all plugins it seems like. However only the last plugin removed is left in a "broken" state.

So what I did was did the steps to reproduce the issue on the device plugin, and had my environment in a broken state with the device plugin.

I repeated the steps for the file plugin. When I removed the file plugin, it ended up "correcting" the state with the device plugin, but the file plugin state was broken (all the file plugin JS modules and module entries were lingered).

Repeating the steps for the device plugin again, fixed the broken state of the file plugin, but the broken state of the device plugin returned.

This bug is probably more suitable for cordova-lib so I'll move it.

@breautek breautek transferred this issue from apache/cordova-plugin-device Jul 26, 2024
@TheNotorius0
Copy link

The bug is reproducible on the iOS platform as well, not just on Android.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants