[android] Application Error - The connection to the server was unsuccessful. (file:///android_asset/www/index.html)

App Dies On Startup (connection to the server was unsuccessful)

I have an Android application that I'm writing using PhoneGap BUILD. The app was working fine earlier, but now it seems I am getting this error after refining my app (some UI changes only)

1) When I start the app I (usually) get:

Application Error - The connection to the server was unsuccessful. (file:///android_asset/www/index.html)

Sorry if this is duplication of any question. I have seen some similar questions here, but i couldn't find a perfect answer or solution. As in my case it was working fine until my last changes.

This question is related to android cordova

The answer is


I was facing the same issue. I noticed that in my index i had both the "on device ready" and the "document.ready" function, so removing one of them fixed my problem :)


In your config.xml file add this line:

<preference name="loadUrlTimeoutValue" value="700000" />

Another reason this error might occur is: there is no index.html in .../YourApp/www/ !

I just followed the ionic guide, and one of the steps is:

$ rm www/index.html

On iOS this is no problem as during the build the compiler takes some default HTML instead. However, when building for android, NO example index.html is used. Took me sometime to find out ("WHY does it work on iOS, but not on android...?)

Easy solution: create a index.html, save it under .../YourApp/www, rebuild ...et voila!


Try this,

1.Rename your index.html to “main.html”

2.Create a new “index.html” and put the following content into it:

<!doctype html>
<html>
  <head>
   <title>tittle</title>
   <script>
     window.location='./main.html';
   </script>
  <body>
  </body>
</html>

3.Rebuild your app! No more errors!


fixing this on an ionic app, simply add

<preference name="loadUrlTimeoutValue" value="700000" />

to your config.xml file immediately after this line

<platform name="android">

Check you index.html file. If you use external resources, that not available when you run application then you can get this error.

In my case I forgot to delete link on debugger script (weinre).

<script src="http://192.168.0.102:8080/target/target-script-min.js#anonymous"></script>

So application worked on emulator because http://192.168.0.102:8080/ was on my localhost and available for emulator.

But when I setup application on mobile phone I had same error, because 192.168.0.102 was not available from mobile network.


I had the same on my project.

I tried " super.setIntegerProperty("loadUrlTimeoutValue", 70000); " but to no avail.

I ensured all files were linked properly [ CSS, JS files etc ], validated the HTML using w3c validator [ http://validator.w3.org/#validate_by_upload ] , and cleaned the project [ Project -> Clean ]

It now loads and executes without the same error.

Hope this helps


I had a similar issue and based on above suggestions I first added "super.setIntegerProperty("loadUrlTimeoutValue", 70000);" but that did not help. So I tried Project -> Clean, that worked and I can launch the app now !

Avinash...


Here is the working solution

create a new page main.html

example:

<!doctype html>
<html>
  <head>
   <title>tittle</title>
   <script>
     window.location='./index.html';
   </script>
  </head>
  <body>
  </body>
</html>

change the following in mainactivity.java

super.loadUrl("file:///android_asset/www/index.html");

to

super.loadUrl("file:///android_asset/www/main.html");

Now build your application and it works on any slow connection

refernce.

NOTE: This is a workaround I found in 2013.


In my case I am using ionic and I simply closed the dialog went to apps in the emulator and ran my app from there instead. This worked. I got the idea of that from here since it was just a time out issue.


Extending loading Timeout Limit will not solve the problem which caused the error, it just will avoid the system to show the message but performance will be affected whatsoever.

Actual reason: You may be linking files or images to remote locations, and those resources are taking too long to load. (this is likely the most common error)

Definitive solution: move all the scripts, images and css needed to some local folders and load them locally ...

Performance will be increased and error will be effectively solved.


Remove the external scripts in your index.html

Change this:

<script src="http://code.highcharts.com/highcharts-more.js"></script>

to

<script src="project_folder/highcharts-more.js"></script>

Please remove remotely linked jQuery files such as: https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js

Instead, download this file and load it from your local js folder, making the URI:

js/jquery.min.js


If you are using visual studio. After changing config.xml sometimes you need this

clean build solution rebuild your app

It is working for me.


For my case, the problem was due to losing of the internet connection in my WiFi.