Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova Android Failed to load resource: net::ERR_NAME_NOT_RESOLVED

I upgraded today to the newest Cordova - 5.4.1. App on iOS kept working just fine but not on Android. All requests were returning 404 error, so I dig into the topic and found out that I need "cordova-plugin-whitelist". I installed it and added <meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' 'unsafe-eval'">

to the header of index.html as well as <access origin="*" /><allow-navigation href="*"/> to config.xml

and now every request to external world is returning "net::ERR_NAME_NOT_RESOLVED"

In AndroidManifest.xml I have those two lines so I guess it's not a problem with Internet access. <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

I went through many questions on SO related to cordova-plugin-whitelist but nothing seems to work

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

```

like image 543
Paweł Wszoła Avatar asked Jan 07 '16 18:01

Paweł Wszoła


People also ask

What is Cordova Plugin whitelist?

Domain whitelisting is a security model that controls access to external domains over which your application has no control. Cordova provides a configurable security policy to define which external sites may be accessed.


2 Answers

I have no idea what the issue was but restarting device resolved it. Nothing related to the app, just the phone had difficulties with connecting to Internet even though it was connected to Wi-Fi and signal strength seemed to be on max.

like image 53
Paweł Wszoła Avatar answered Sep 18 '22 13:09

Paweł Wszoła


In your app's 'config.xml', place only this:

<allow-navigation href="*" />

And remove what you added to your index.html header. Then if it still doesn't work that means your problem is not related to the whitelist plugin.

I used this plugin in different Android projects and never had to do more than this to allow my app to communicate with the back-end.

Hope that helps!

like image 25
arainone Avatar answered Sep 17 '22 13:09

arainone