2016-01-07 371 views
7

我今天升级到最新的科尔多瓦 - 5.4.1。 iOS上的应用程序保持正常工作状态,但不适用于Android。所有请求都返回了404错误,因此我深入了解该主题并发现需要“cordova-plugin-whitelist”。我安装了它,并添加 <meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' 'unsafe-eval'"> Cordova Android无法加载资源:net :: ERR_NAME_NOT_RESOLVED

到的index.html以及<access origin="*" /><allow-navigation href="*"/>头对config.xml

和现在对外部世界的每一个请求返回的“网:: ERR_NAME_NOT_RESOLVED”

在AndroidManifest.xml我有这两行,所以我想这不是一个Internet访问问题。 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

我通过对因此与科尔多瓦 - 插件白名单,但没有很多问题就似乎工作

我的config.xml ```

<?xml version='1.0' encoding='utf-8'?> 
<widget id="app" version="1.1.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> 
    <name>app</name> 
    <description> 
     A sample Apache Cordova application that responds to the deviceready event. 
    </description> 
    <author email="[email protected]" href="http://cordova.io"> 
     Apache Cordova Team 
    </author> 
    <content src="index.html" /> 
    <allow-navigation href="*" /> 
    <platform name="ios">...splash screens and icons</platform> 
    <platform name="android">...splash screens and icons</platform> 
    <icon src="resources/android/icon/drawable-xhdpi-icon.png" /> 
    <preference name="SplashScreen" value="screen" /> 
    <preference name="SplashScreenDelay" value="3000" /> 
    <preference name="Orientation" value="default" /> 
    <feature name="phonegap-parse-plugin"> 
     <param name="id" value="org.apache.cordova.core.parseplugin" /> 
     <param name="url" value="https://github.com/fastrde/phonegap-parse-plugin" /> 
    </feature> 
    <feature name="Insomnia (prevent screen sleep)"> 
     <param name="id" value="nl.x-services.plugins.insomnia" /> 
     <param name="url" value="https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin.git" /> 
    </feature> 
    <feature name="Toast"> 
     <param name="id" value="cordova-plugin-x-toast" /> 
     <param name="url" value="https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git" /> 
    </feature> 
    <feature name="Cordova SMS Plugin"> 
     <param name="id" value="com.cordova.plugins.sms" /> 
     <param name="url" value="https://github.com/cordova-sms/cordova-sms-plugin.git" /> 
    </feature> 
    <feature name="OpenTokCordovaPlugin"> 
     <param name="id" value="com.tokbox.cordova.opentok" /> 
     <param name="url" value="https://github.com/doxyme/cordova-plugin-opentok" /> 
    </feature> 
</widget> 

```

+0

您是否在使用cordova-plugin-whitelist并配置了Content-Security-Policy?你之前使用的是什么版本的cordova? – QuickFix

+0

我遇到过这个问题。发现它发生在互联网缓慢时。 – Yusuf

回答

13

我不知道是什么问题,但重新启动设备解决它。与应用程序没有任何关系,只是手机在连接到互联网时遇到了困难,即使它已连接到Wi-Fi并且信号强度似乎最大。

+0

好的。事实上,奇怪的是,涉及'cordova-whitelist-plugin',因为带有空的* Content-Security-Policy *的'应该让所有内容都通过。很高兴你解决了你的问题 – arainone

+0

我有一个空的内容安全策略,它没有工作,直到我rsetarted设备。 我不能相信重新启动设备也解决了我的问题。 – alicona

+1

因为我忘记启用wi-fi而导致同样的问题,因此提升。 –

3

在你的应用的'config.xml'中,只有这个:

<allow-navigation href="*" /> 

并删除您添加到您的index.html标题。 然后,如果它仍然不起作用,这意味着您的问题与白名单插件无关。

我在不同的Android项目中使用了这个插件,从来没有做过更多的事情来允许我的应用程序与后端进行通信。

希望有帮助!

+1

不幸的是,它并没有帮助。我编辑了我的问题并添加了config.xml –

+0

那么,你试过了吗?并有同样的问题? – arainone

+0

啊,我跳过了部分“并删除了你添加的index.html”。当我这样做时,我得到“没有找到Content-Security-Policy元标记,请在使用cordova-plugin-whitelist插件时添加一个。”和请求返回完全相同的错误“net :: ERR_NAME_NOT_RESOLVED” –

1

我们遇到了一个类似的问题,那就是在使用Cordova 6.4.0和版本25(7.1.1)的HAXM中运行的android模拟器的两个不同系统上收到“无法加载资源net :: ERR_NAME_NOT_RESOLVED” android SDK。只需删除并添加whilelist插件就可以解决我们的问题而不需要更改任何配置文件。

0

我有同样的问题,似乎没有解决......我知道,在我的情况是飞溅图像尺寸太大(约3.2MB)...我用this website来压缩文件和他们工作。