Cordova Connection to server was Unsuccessful
Solution 1
For latest Cordova (4+) this a setting in config.xml
:
e.g.
<preference name="LoadUrlTimeoutValue" value="70000"/>
Increases default timeout to 70 seconds (default is 20), reducing the chance of timing out.
Docs: https://cordova.apache.org/docs/en/latest/config_ref/index.html#preference
When loading a page, the amount of time to wait before throwing a timeout error.
Solution 2
This may asked here many times.. This issue can fix by adding a timeout to the webview call (index.html). In your project_name.java class just add this
super.setIntegerProperty("loadUrlTimeoutValue", 5000);
And in Cordova latest, just use this to timeout
super.loadUrl(Config.getStartUrl(), 5000);
Also go through these so questions
UPDATE :
One more solution, try this
Create a main.html and put your code there, and in your index.html just redirect to main.html
<script>
window.location='./main.html';
</script>
Solution 3
This blog post from Robert Kehoe:
- Seemed to be EASY to me
- Made sense to me
- WORKED for me
Rename your index.html to "main.html"
Create a new "index.html" and put the following content into it:
<!doctype html>
<html>
<head>
<title>the title</title>
<script>
window.location='./main.html';
</script>
<body>
</body>
</html>
Rebuild your app! No more errors!
Robert also said,
Another good idea is to give your application a “splash screen”, so that the user gets instant feedback that your app is loading/working, before it is fully ready.
Solution 4
The main problem for this issue is take more time to load your page.
yes it's can a hack to solve this issue, make a html page name index.html and your existing index page name to be change as a main.html or any other one give a redirection to this page like this
<script>
window.location='main.html';
</script>
am sure it's work very much
Admin
Updated on June 13, 2022Comments
-
Admin almost 2 years
The Connection to the server was unsuccessful(file:///android-asset/www/index.html)
is showing when i run my android application. please let me know how to resolve this issue.
-
Admin about 10 yearsmanukv thanks for ur answer but it will not work i am still getting the same error after modified my .java class.please let me know any other solution
-
manukv about 10 yearswhich cordova version are you using and are you trying to run app in emulator or device?? answer updated pls check it
-
viskin over 7 yearsSadly I don't have cordova and its plugins injected into main.html
-
markj over 7 yearsThis one solved my problem for the latest version of Cordova. Much more simple than other workarounds.
-
user1568901 almost 7 yearsIn my case, it's the splash screen that's timing out. :-(
-
Bharath almost 7 yearswere to add this tag
-
driconmax over 6 yearsIn config.xml, in the root folder of your project