问题
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 .
回答1:
Add <preference name="loadUrlTimeoutValue" value="60000" />
To config.xml
回答2:
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.
回答3:
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");
}
}
回答4:
Please check your device version ionic not properly work on android < 4.4.4 version you could try this above 4 version if you want to work with 4.* version you could install cordova-crosswalk plugin
回答5:
Just need to also make sure that your mobile device is connected to the same wifi as your computer.
回答6:
So I added manually the following tags in config.xml right at the beginning:
<allow-navigation href="*" />
<content src=“index.html” />
<content original-src=“index.html” />
it’s working.
回答7:
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!
回答8:
I add plugin:
cordova plugin add cordova-plugin-crosswalk-webview
then,
ionic cordova platform rm android
ionic cordova platform add android
ionic cordova build android (or Run)
来源:https://stackoverflow.com/questions/41487348/how-to-fix-the-connection-to-the-server-was-unsuccessful-file-android-asset