apache / apache/cordova-android
onDeviceReady doesn't run
- Dominant language
- JavaScript
- Stars
- 3.8k
- Forks
- 1.6k
- Avg merge
- 16h 18m
- Merged PRs (30d)
- 11
Description
# Bug Report
## Problem
### What is expected to happen?
onDeviceReady function should fire
### What does actually happen?
For at least some Android devices, the onDeviceReady function does not initiate, although it works fine in Android Studio.
## Information
This may relate to this reported unresolved issue: https://github.com/apache/cordova-android/issues/604
Strangely, the issue does not exist on another app I have with, as far as I can tell, exactly the same settings, versions and code, so this may be related to some upgrade step that I missed for a given project. Both apps I recreated from scratch after upgrading.
### Command or Code
I tested with this index.html file, without plugins.
```
$(document).ready(function(){
alert('before onDeviceReady');
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert('onDeviceReady fired.'); //this doesn't fire for some devices
}
});
This is a test of onDeviceReady.
```
### Environment, Platform, Device
Cordova 12.0.0
Gradle 8.7
Android Gradle Plugin 8.5.1
Jetbrains Runtime 17.0.11
Target version 34
Using minify/proguard
Testing with BrowserStack due to reported issues from actual users. The output from BrowserStack log appears to be the same for a working app vs. non-working app. Pixel 6 Pro, Pixel 8, Pixel 5, etc. from Android versions (at least) 11 to 14. My device is a Galaxy Tab A7 SM-T500 and everything works fine on it, so it seems this issue is either device specific or else it happens after going through Google Play Store. (I cannot reproduce the problem in Android Studio so that may be the case.)
* This was not a problem until after I upgraded Android Studio (2021.3.1?), Cordova (11.0.0), Java (11), Gradle (7.6), and Gradle Plugin (7.5.1).
### Version information
See above.
Not using Ionic
Windows 11
Android Studio Koala 2024.1.1 Patch 1
## 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
Start with the supplied index.html and its cordova.js loading and deviceready listener, then compare behavior across the working and failing Android environments listed. Reproduce the issue in BrowserStack and compare with Android Studio, including the minify/ProGuard configuration. Done means onDeviceReady fires reliably on the affected devices and the difference is covered by a verified reproduction or test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, javascript
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100