I've added material icons to ionic2 app , and since then I get error ""The connection to the server was unsuccessful. (file:///android_asset/www/index.html)"" although the css and fonts file of MaterialIcons are in the assets folder (I've install it locally) there is no call to "https://fonts.googleapis.com/icon?family=Material+Icons" what can I do ? Can I fix it or know why the timeout suddenly .
How to fix the connection to the server was unsuccessful. (file ///android_asset/www/index.html)
55.6k views Asked by Haddar Macdasi AtThere are 8 answers
Adding that ...value="70000" or "60000" line in config.xml isn't the best solution and it doesn't always work nor the creation of main.html file .
I was dealing with the same issue. These two solutions did not work for me.
SOLUTION
-Make sure you build with
ionic cordova build --prod and not ionic cordova build
-Check if one of your file or folder name doesn't contain Uppercase in it's context before building
like for example in "pages"
templateView (instead of "templateview)
- -templateview.ts
- -templateview.html
- -templateview.scss
and rename it (otherwise you will have errors)
When building finished, your app runs correctly without the "(file:///android_asset/www/index.html)" error.
As of now above solutions will work but the app will take time to load, instead of that you can simply add below in your MainActivity.java super.loadUrl("file:///android_asset/www/index.html");
In MainActivity.java you have to comment below code loadUrl(launchUrl);
public class MainActivity extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// enable Cordova apps to be started in the background
Bundle extras = getIntent().getExtras();
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
moveTaskToBack(true);
}
// Set by <content src="index.html" /> in config.xml
//loadUrl(launchUrl);
super.loadUrl("file:///android_asset/www/index.html");
}
}
Add
<preference name="loadUrlTimeoutValue" value="60000" />
To config.xml