ondeviceready won't fire because plugin does not cleanup after itself properly when removed(?)
- Dominant language
- JavaScript
- Stars
- 231
- Forks
- 242
- Avg merge
- 2h 51m
- Merged PRs (30d)
- 7
Description
# 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:

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
```cli
$ 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
- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above
Contributor guide
Research direction
Reproduce the issue with the listed Cordova CLI commands on Android, then inspect the generated cordova.js and the removed plugin's www/device.js alongside the PluginManager log entries. Done means removing cordova-plugin-device no longer produces an unknown Device or class-not-found error and ondeviceready fires normally.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- mobile-dev, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100