如何修复与服务器的连接不成功。 (文件///android_asset/www/index.html)
How to fix the connection to the server was unsuccessful. (file ///android_asset/www/index.html)
我已将 material 图标添加到 ionic2 应用程序,然后我收到错误消息“"The connection to the server was unsuccessful. (file:///android_asset/www/index.html)"”
尽管 MaterialIcons 的 css 和字体文件在资产文件夹中(我已经在本地安装了),但没有调用“https://fonts.googleapis.com/icon?family=Material+Icons”
我能做什么 ?我可以修复它还是知道为什么突然超时。
添加<preference name="loadUrlTimeoutValue" value="60000" />
至 config.xml
1- 将您的 index.html 重命名为“main.html”
2-新建一个“index.html”,将以下内容放入其中:
<!doctype html>
<html>
<head>
<title>tittle</title>
<script>
window.location='./main.html';
</script>
<body>
</body>
</html>
3- 重建您的应用程序!没有更多错误!
我添加插件:
cordova plugin add cordova-plugin-crosswalk-webview
然后,
ionic cordova platform rm android
ionic cordova platform add android
ionic cordova build android (or Run)
请检查您的设备版本 ionic 在 android < 4.4.4 版本上无法正常工作 您可以在 4 版本以上尝试
如果你想使用 4.* 版本,你可以安装 cordova-crosswalk 插件
所以我在 config.xml 开头手动添加了以下标签:
<allow-navigation href="*" />
<content src=“index.html” />
<content original-src=“index.html” />
有效。
在 config.xml 中添加 ...value="70000" or "60000" 行不是最佳解决方案,它并不总是有效,也不会创建 main.html 文件。
我遇到了同样的问题。这两个解决方案对我不起作用。
解决方案
-确保使用
构建
ionic cordova build --prod and not
ionic cordova build
-在构建之前检查您的文件或文件夹名称是否在其上下文中不包含大写字母
例如 "pages"
templateView(而不是“templateview”)
- -templateview.ts
- -templateview.html
- -templateview.scss
并重命名(否则会报错)
构建完成后,您的应用可以正常运行,不会出现“(file:///android_asset/www/index.html)”错误。
截至目前,以上解决方案都可以使用,但应用程序需要一些时间来加载,您可以在 MainActivity.java 中简单地添加以下内容
super.loadUrl("file:///android_asset/www/index.html");
在MainActivity.java中你必须在下面的代码中注释
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");
}
}
还需要确保您的移动设备连接到与计算机相同的 wifi。
我已将 material 图标添加到 ionic2 应用程序,然后我收到错误消息“"The connection to the server was unsuccessful. (file:///android_asset/www/index.html)"” 尽管 MaterialIcons 的 css 和字体文件在资产文件夹中(我已经在本地安装了),但没有调用“https://fonts.googleapis.com/icon?family=Material+Icons” 我能做什么 ?我可以修复它还是知道为什么突然超时。
添加<preference name="loadUrlTimeoutValue" value="60000" />
至 config.xml
1- 将您的 index.html 重命名为“main.html”
2-新建一个“index.html”,将以下内容放入其中:
<!doctype html>
<html>
<head>
<title>tittle</title>
<script>
window.location='./main.html';
</script>
<body>
</body>
</html>
3- 重建您的应用程序!没有更多错误!
我添加插件:
cordova plugin add cordova-plugin-crosswalk-webview
然后,
ionic cordova platform rm android
ionic cordova platform add android
ionic cordova build android (or Run)
请检查您的设备版本 ionic 在 android < 4.4.4 版本上无法正常工作 您可以在 4 版本以上尝试 如果你想使用 4.* 版本,你可以安装 cordova-crosswalk 插件
所以我在 config.xml 开头手动添加了以下标签:
<allow-navigation href="*" />
<content src=“index.html” />
<content original-src=“index.html” />
有效。
在 config.xml 中添加 ...value="70000" or "60000" 行不是最佳解决方案,它并不总是有效,也不会创建 main.html 文件。
我遇到了同样的问题。这两个解决方案对我不起作用。
解决方案
-确保使用
构建ionic cordova build --prod and not ionic cordova build
-在构建之前检查您的文件或文件夹名称是否在其上下文中不包含大写字母
例如 "pages"
templateView(而不是“templateview”)
- -templateview.ts
- -templateview.html
- -templateview.scss
并重命名(否则会报错)
构建完成后,您的应用可以正常运行,不会出现“(file:///android_asset/www/index.html)”错误。
截至目前,以上解决方案都可以使用,但应用程序需要一些时间来加载,您可以在 MainActivity.java 中简单地添加以下内容 super.loadUrl("file:///android_asset/www/index.html");
在MainActivity.java中你必须在下面的代码中注释 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");
}
}
还需要确保您的移动设备连接到与计算机相同的 wifi。