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

AndroidCordova

Android Problem Overview


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.

Android Solutions


Solution 1 - Android

In your config.xml file add this line:

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

Solution 2 - Android

As you said, there are many duplicate questions on the same topic. Any how explaining your situation.

The problem might be solved by adding a timeout to call your index.html

ie you need to add super.setIntegerProperty("loadUrlTimeoutValue", 70000); in your activity.java file ( inside src/com/yourProj/--/youractivity.java) above this line: super.loadUrl("file:///android_asset/www/index.html");

Explanation:

This can be happened due to the following reasons

The core reason: the problem is likely due to the speed of the emulator so the network is too slow complete the communication in a timely fashion.

This can be due to:

  1. Your code/data/image is of too much of size ( I guess in your case you are using some images ,as you said you made some UI modifications, may be the size of images are high)

  2. Your script may have a infinite or long loop, so that it takes too much of time to load.

  3. You will be using too much of scripts (jQuery, iscroll, etc etc.. more number of plugins or scripts )

Solution 3 - Android

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.

Solution 4 - Android

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

Solution 5 - Android

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>

Solution 6 - Android

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...

Solution 7 - Android

Try this,

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

> 2.Create a new “index.html” and put the following content into it: > > > > > tittle > > > > > > 3.Rebuild your app! No more errors!

Solution 8 - Android

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">

Solution 9 - Android

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

Solution 10 - Android

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.

Solution 11 - 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.

Solution 12 - Android

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

Solution 13 - Android

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.

Solution 14 - Android

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.

Solution 15 - Android

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 :)

Solution 16 - Android

It's quite a niche situation but thought I'd post it here in case it saves somebody else the hours I spent going round in circles.

I reverted to [email protected] after trying out [email protected] and started getting this error when trying to run my app in dev mode.

What I had forgotten is that when I upgraded to 10.0.1 I had to remove the whitelist plugin since it's now part of cordova-android.

Reinstating cordova-plugin-whitelist got everything working again for me!

Solution 17 - Android

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!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1654414View Question on Stackoverflow
Solution 1 - AndroidSoufieneView Answer on Stackoverflow
Solution 2 - AndroidAnhSirk DasarpView Answer on Stackoverflow
Solution 3 - AndroidRobin C SamuelView Answer on Stackoverflow
Solution 4 - Androidsharma_kunalView Answer on Stackoverflow
Solution 5 - AndroidRaugaralView Answer on Stackoverflow
Solution 6 - AndroidAvinashView Answer on Stackoverflow
Solution 7 - AndroidNithin Krishnan PView Answer on Stackoverflow
Solution 8 - AndroidAdeojo Emmanuel IMMView Answer on Stackoverflow
Solution 9 - AndroidDeanoView Answer on Stackoverflow
Solution 10 - AndroidjjyepezView Answer on Stackoverflow
Solution 11 - AndroidAlexey MuravyovView Answer on Stackoverflow
Solution 12 - AndroidChong Lip PhangView Answer on Stackoverflow
Solution 13 - AndroidFernandoZView Answer on Stackoverflow
Solution 14 - AndroidcaglabaranView Answer on Stackoverflow
Solution 15 - AndroidAbir.dView Answer on Stackoverflow
Solution 16 - AndroidskmbrView Answer on Stackoverflow
Solution 17 - AndroidDirkView Answer on Stackoverflow