简体   繁体   中英

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 Inte.net access. <uses-permission android:name="android.permission.INTE.NET" /> <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="dev@cordova.apache.org" 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>

```

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.

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!

We ran into a similar issue where we received the "Failed to load resource net::ERR_NAME_NOT_RESOLVED" error on two different systems from the android emulator running in HAXM using Cordova 6.4.0 and the version 25 (7.1.1) android SDK. Simply removing and adding the whilelist plugin resolved our issue without changing any configuration files.

I was having the same issue and nothing seemed to solve... And I figured out that in my case was the splashscreen image size that was too big (about 3.2MB)... I used this website to compress the file and then worked.

Restarting Device seems to resolve this problem for me locally, but this piece of work always comes back to me from support. So would like to have a fix for the solution not a workaround.

The whitelist plugin also has Content Security Policy declarations:

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

This seems to have resolved the issue for me, but only time will tell as I can never get this issue to replicate on demand.

For me, none of the mentioned solutions worked. What worked for me was adding the plugin directly from the repo:

cordova plugin rm cordova-plugin-inappbrowser --force
cordova plugin add https://github.com/apache/cordova-plugin-inappbrowser.git

If the problem persists you can go ahead and remove and add the platform again:

cordova platform save
cordova platform rm <platform>
cordova platform add <platform>

It seems you are trying to send requests yet you are offline, try to check inte.net connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM