Android: Deviceready has not fired after 5 seconds
Asked Answered
W

15

34

After update Cordova to v6.4.0 and Android platform to 6.0.0, my app don't work any more. I'm getting this:

deviceready has not fired after 5 seconds. cordova.js:1223
Channel not fired: onCordovaInfoReady cordova.js:1216
Channel not fired: onCordovaConnectionReady cordova.js:1216

I tried to remove all plugins and add it one by one. I found that is a problem with cordova-plugin-device and cordova-plugin-network-information. All my plugins are up to date

Workbook answered 1/11, 2016 at 1:24 Comment(11)
I'm having the exact same issue...Topotype
That was on mac, now I'm trying on a PC, and is worst...Teagan
The problem is with those plugins (cordova-plugin-device && cordova-plugin-network-information). Those plugins fire the onCordovaInfoReady and onCordovaConnectionReady "channels" respectively. If they don't fire, then deviceready doesn't fire. Must be something that changed in cordova-android 6.0.0, which is preventing those plugins from firing their channels...Topotype
@Topotype do you know if is already reported on cordova issues?Teagan
I couldn't see anything. I've since downgraded to cordova-android 5.2.2, and that seems to work OK, even with cordova 6.4.0. Maybe try that for now.Topotype
@Topotype what about iOS, i'm getting white screen, I tried fallback to iOS 4.2.1 and is still happening..Teagan
Not sure, I'm not having that issue. It's working OK for me with cordova-ios 4.3.0. I'd say that's a separate, unrelated issue. Check your console for errors, and make sure your Content-Security-Policy meta tag is set correctly - esp make sure you've added gap://ready as that is now required.Topotype
Ionic guys say that I should remove the CSP meta tag...wich one I should use?Teagan
You're right, was not related..some ionic problem, but not the CSP meta tagTeagan
@SebastiánRojas are you by chance using crosswalk? I just came across this as I am experiencing the same issue following installation of cordova-android 6.0.0. The solutions says the npm version is missing patch a patch and they suggest installing from the github repo crosswalk-project.org/jira/browse/XWALK-7422Nicaea
ionic team suggests to uninstall & reinstall all plugins & platform and thread is locked for discussion github.com/ionic-team/ionic-cli/issues/259, that's a quite bit of work and not a solution to the problem thru'Amorous
N
9

If you happen to be running the Crosswalk plugin in your app I just confirmed that uninstalling it and reinstalling via;

cordova plugin add https://github.com/crosswalk-project/cordova-plugin-crosswalk-webview

Gets rid of

deviceready has not fired after 5 seconds. cordova.js:1223 Channel not fired: onCordovaInfoReady cordova.js:1216 Channel not fired: onCordovaConnectionReady cordova.js:1216

You can see the issue at Crosswalk's Jira issue listing here.

https://crosswalk-project.org/jira/browse/XWALK-7422

Nicaea answered 10/11, 2016 at 20:48 Comment(1)
When switching to cordova android 6.0.0 the primary bridge was changed to the EVAL_BRIDGE. Crosswalk adds that support in version 2.2.0 github.com/crosswalk-project/cordova-plugin-crosswalk-webview/…Netti
W
7

Solution:

put the call "cordova.js" to the last line in the page.

<script type="text/javascript" src="cordova.js"></script>
</body>
</html>

Greeting...

Washout answered 18/5, 2018 at 18:22 Comment(1)
I was facing similar issue in my Cordova ios application.After struggling a lot, finally this solution did the magic. Thanks a lot.Lander
B
4

This should be fixed in cordova-android 6.1.0. It has not been added to the npm-registry yet, so you can use it by placing this to your config.xml:

<engine name="android" spec="https://github.com/apache/cordova-android.git#6.1.0"/>

Broom answered 4/11, 2016 at 10:58 Comment(6)
Thank you, I'm gonna wait the official releaseTeagan
6.1.0!! a lot or bugs I supose...so bad, cordova makes me lost 3 daysTeagan
I just updated to 6.1.0 via command line platform remove and platform add. It fixed an issue with seeing the default Cordova icon as my splash screen instead of the one I had setup. But the splash screen doesn't hide unless I force the app to the background and then re-open it. Also the deviceready has not fired after 5 seconds and Channel not fired: for onCordovaInfoReady and onFileSystemPathsReady messages continue to show up in my console.Nicaea
Thank you so much. I was fighting issues with icons, splashscreens, deviceReady events, push notifications, and much much more on Android. I went with 6.1.1 and thsi fixed everything!Reno
Is there any specific location to add this line in config.xmlFlocky
@YokeshVaradhan There is not, I normally add it to the end of the config <engine name="android" spec="https://github.com/apache/cordova-android.git#6.1.0"/> </widget>Undersigned
C
3

I recently encountered this same issue on iOS. Eventually what worked for me was a simple remove and add of the ios platform:

cordova platform remove ios
cordova platform add ios

It had been quite a while since I had completely re-built the ios platform and, just like you, I had made other major changes during that time (Cordova upgrade, XCode upgrade, etc). My theory is that my config.xml or existing ios build was somehow incompliant with the latest Cordova requirements. Doing a platform remove and platform add will clear out the build files and update config.xml.

I doubt this applies to the OP, but for others who've encountered this same issue, please ensure that you've included cordova.js in your index.html file. If you've not done so, add this line:

<script src="cordova.js"></script>

It's a very common omission when just getting started with Cordova.

Crouch answered 7/6, 2017 at 18:57 Comment(0)
N
3

Update your cordova-android.

I updated cordova-android to 10.1.0 and didn't have this problem any more.

cordova platform remove android
cordova platform add [email protected]
Nummular answered 9/11, 2021 at 14:9 Comment(0)
F
1

Make sure you included cordova.js on the bottom of the body of your index.html

And don't ever forget about the type="text/javascript" that need to be located along with src=""

<!DOCTYPE html>
<html>
    <head></head>
    <body>
        ...
        <script type="text/javascript" src="cordova.js"></script>
    </body>
</html>

Also include this meta tags on the html head

<meta http-equiv="X-UA-Compatible" content="IE=edge">

Then remove the current installed platform and then add it again

cordova platform remove android
cordova platform remove browser
cordova platform remove ios

cordova platform add android
cordova platform add browser
cordova platform add ios

Serve it then refresh your browser or build it

If that doesn't solve your problem, then try remove some plugin one by one or remove your scripts to find out the bugs..

Fourth answered 28/3, 2018 at 4:29 Comment(2)
Why is type="text/javascript" required (it should be the default?) and required in a certain order?Warga
@Warga As I remember it's required to help the browser to recognize the external script as text/javascript in case if the server send incorrect content-type. At that time I was using Phonegap from PlayStore as a client for testing on real device and my problem was fixed by doing that, and debugging on real device was difficult. About the order, I will edit my English regarding that.Fourth
D
1

I dont know the real reason of this issue, But I tried removing cordova-plugin-whitelist and cordova-plugin-device from the plugins list and added them again. luckily that solved the issue,

Digestant answered 30/9, 2018 at 6:0 Comment(0)
L
1

If you are testing on iphone , the problem is related to Content-Security-Policy , either remove it , or change the rules so it can run !

Also make sure cordova.js is added to the end of the html file .

<script type="text/javascript" src="cordova.js"></script> 
</body>
</html>
Llano answered 13/11, 2019 at 6:16 Comment(0)
O
1

Ran into this with cordova-android 10.1.2, where it should have been fixed, I guess. Removing and re-adding the android platform didn't help, either.

(FWIW: I'm using cordova via Quasar (v1), and I observed that the quasar dev -m cordova live mode (with HMR) worked, but the "regular" quasar build/cordova run deploys didn't.)

What "fixed" it, for whatever reason, was this change to config.xml, suggested by user judevian in a ionic webview issue:

So if u defined it like this:

<preference name="Scheme" value="app" />
<preference name="Hostname" value="localhost" />

Also set

<allow-navigation href="http://app/*"/>
<allow-navigation href="https://app/*"/>
<allow-navigation href="http://localhost/*"/>
<allow-navigation href="https://localhost/*"/>
Overweigh answered 1/9, 2022 at 7:2 Comment(0)
M
0

For someeone (like me) who would not like to downgrade Cordova, please follow my guide (I successfully did after a whole day trying):

  • Back up your current (cordova root, not platforms/android) project.
  • Open cordova CLI from root: cordova platform remove android

  • After removing: cordova platform add android. Your package project (structure) folders are kept, so don't worry.

  • cordova plugin ls and then remove every cordova plugin execpt Notfication and Whitelist (Cordova's default installed plugins).
  • Use cordova plugin add <plugin-id> to add back your using plugins one by one.
  • Go back to you backup-ed folder: Clone back AndroidManifest.xml and everything in app/src/main. This includes: assets, java, libs and res. One file you only need (actually I suggest) to leave out is res/xml/config.xml. Do not clone this. Let Cordova build later.

  • Cordova CLI (from root cordova project, not platforms/android): cordova build android

  • If you have any 3rd party plugins, or using different content src, properties, please copy them (features, content src, author,...) back into app/src/main/res/xml/config.xml . Cordova won't be able to detect your 3rd plugin
  • Open Android Studio, import your "repaired" project --> Make project, then Run App. Enjoy!
Muntin answered 10/2, 2018 at 9:36 Comment(0)
P
0

I'm running Visual Studio and have this error in the Chrome emulator. I found that firing up the Web Inspector would allow Visual Studio to prompt for some of the hooks that various plugins were asking for, and clicking through the various popups got me past this. It must be something to do with the way that Visual Studio sets up the Cordova Plugin Simulation, but with my setup it was getting blocked from presenting the popups.

Papain answered 10/5, 2018 at 14:54 Comment(0)
D
0

In case this is still relevant to anyone:

What worked for me was removing and then adding again a plugin, namely, "katzer cordova-plugin-local-notifications".

Dialectal answered 18/9, 2020 at 20:18 Comment(0)
O
0

in my case my working project suddenly stopped and displayed above error

My project started work

1 . uninstall mobile debug api

2 . Clear project folder

For android users

cd android
./gradlew clean

or

gradlew clean

for ios users

cd ios
xcodebuild clean
Odelia answered 25/6, 2021 at 18:4 Comment(0)
C
0

I had the same issue and I solved it by putting the right middleware to provide plugin files in the server. Check if you forgot it even though you need it.

app.use("plugin location", (req, res) => res.sendFile("plugin location"))
Cal answered 18/7, 2023 at 1:55 Comment(0)
B
-1

I added below preference in config.xml and it worked for me.

I have updated my project to Cordova 11

Burdette answered 14/12, 2022 at 12:51 Comment(1)
You must specifically say which preferences that you added and by which user by his name. Better way is, you must specify the preferences you added in your answer. Since later what happens if the other user may edited his answer and changed its content.Shaveling

© 2022 - 2024 — McMap. All rights reserved.