# Fetch does not work on Android 9 with SDK 28

**URL:** <https://forums.fusetools.com/t/fetch-does-not-work-on-android-9-with-sdk-28/7810>\
**Category:** How-to Discussions\
**Created:** [July 22, 2019, 7:35am UTC](https://forums.fusetools.com/t/fetch-does-not-work-on-android-9-with-sdk-28/7810 "2019-07-22T07:35:30Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enrico](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/enrico/32/144_2.png) [@Enrico](https://forums.fusetools.com/u/Enrico)\
**Post date:** [July 22, 2019, 7:35am UTC](https://forums.fusetools.com/t/fetch-does-not-work-on-android-9-with-sdk-28/7810/1 "2019-07-22T07:35:30Z")

</div>

This simple fetch always worked fine on my published app (SDK 26), since I rebuilt the app using SDK 28 (32bit). Since then it does not work on devices with Android 9 and it reports “connection error”. On other versions of Android (6, 7, 8) it works perfectly.  
Unfortunately I don’t have a Android 9 device to do any test.

I’m getting a lot of 1 star reviews because of this issue…

```
fetch(http://www.mindteq.com/api/cityfun/v2/api.php?category=home&debug)
    .then(function(response) {
        if (response.ok) {
            return response.json(); 
        } else {    
            throw Error(response.status);
        }
    })
    .then(function(json) {
        
        datas.replaceAll(json.settings);

        // Debug
        //datas.forEach(function(items) {
        // console.log(items);
        //});

    }).catch(function(error) {
        console.log(error);
    });

```

Could be that Android starting from SDK 28 wants HTTPS and not HTTP?

---

<div class="post-metadata">

**Author:** ![aeq](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/aeq/32/129_2.png) [@aeq](https://forums.fusetools.com/u/aeq)\
**Post date:** [July 22, 2019, 3:16pm UTC](https://forums.fusetools.com/t/fetch-does-not-work-on-android-9-with-sdk-28/7810/2 "2019-07-22T15:16:24Z")

</div>

Hmm, I also don’t have an Android 9 Device at the mo but you could try a simulator?

Then you could try testing SSL by fetching here: [https://jsonplaceholder.typicode.com](https://jsonplaceholder.typicode.com): `https://jsonplaceholder.typicode.com/todos/1`

---

<div class="post-metadata">

**Author:** ![aeq](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/aeq/32/129_2.png) [@aeq](https://forums.fusetools.com/u/aeq)\
**Post date:** [July 22, 2019, 3:22pm UTC](https://forums.fusetools.com/t/fetch-does-not-work-on-android-9-with-sdk-28/7810/3 "2019-07-22T15:22:33Z")

</div>

Oh wait, my one device can get a Pie update, will upgrade and let y’all know asap…

---

<div class="post-metadata">

**Author:** ![Cristian\_Karmy](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/cristian_karmy/32/480_2.png) [@Cristian\_Karmy](https://forums.fusetools.com/u/Cristian_Karmy)\
**Post date:** [July 22, 2019, 4:16pm UTC](https://forums.fusetools.com/t/fetch-does-not-work-on-android-9-with-sdk-28/7810/4 "2019-07-22T16:16:40Z")

</div>

I’m getting the same issue! The fetch on Android is broken! The XMLHttpRequest also with errors

---

<div class="post-metadata">

**Author:** ![Cristian\_Karmy](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/cristian_karmy/32/480_2.png) [@Cristian\_Karmy](https://forums.fusetools.com/u/Cristian_Karmy)\
**Post date:** [July 22, 2019, 4:29pm UTC](https://forums.fusetools.com/t/fetch-does-not-work-on-android-9-with-sdk-28/7810/5 "2019-07-22T16:29:00Z")

</div>

I change the url to HTTPS and problem solved

---

<div class="post-metadata">

**Author:** ![aeq](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/aeq/32/129_2.png) [@aeq](https://forums.fusetools.com/u/aeq)\
**Post date:** [July 22, 2019, 7:21pm UTC](https://forums.fusetools.com/t/fetch-does-not-work-on-android-9-with-sdk-28/7810/6 "2019-07-22T19:21:26Z")

</div>

Yep, its the SSL(https) connections in Pie, it looks like you can specify non-secure domains for “clear text traffic” through adding [Network Security Config](https://developer.android.com/training/articles/security-config.html) to your manifest:

```auto
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">insecure.example.com</domain>
        <domain includeSubdomains="true">insecure.cdn.example.com</domain>
    </domain-config>
</network-security-config>

```

> **[Protecting users with TLS by default in Android P](https://android-developers.googleblog.com/2018/04/protecting-users-with-tls-by-default-in.html)**
>
> Android is committed to keeping users, their devices, and their data safe. One of the ways that we keep data safe is by protecting all data that enters or leaves an Android device with Transport Layer Security (TLS) in transit. As we announced in our...

Manifest Ref: [Add values to AndroidManifest?](https://forums.fusetools.com/t/add-values-to-androidmanifest/7389/2)

---

<div class="post-metadata">

**Author:** ![Cristian\_Karmy](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/cristian_karmy/32/480_2.png) [@Cristian\_Karmy](https://forums.fusetools.com/u/Cristian_Karmy)\
**Post date:** [July 22, 2019, 7:42pm UTC](https://forums.fusetools.com/t/fetch-does-not-work-on-android-9-with-sdk-28/7810/7 "2019-07-22T19:42:29Z")

</div>

Great! Thanks for the info!

---

<div class="post-metadata">

**Author:** ![Enrico](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/enrico/32/144_2.png) [@Enrico](https://forums.fusetools.com/u/Enrico)\
**Post date:** [July 23, 2019, 7:08am UTC](https://forums.fusetools.com/t/fetch-does-not-work-on-android-9-with-sdk-28/7810/8 "2019-07-23T07:08:57Z")

</div>

Yes, I may confirm that now Google wants HTTPS connections. I purchased and installed a SSL certificate for my VPS, published a updated version of the app and now it works. Unfortunately in three days I got more negative reviews regarding this “network error” than all the other positive reviews.

---

<div class="post-metadata">

**Author:** ![Enrico](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/enrico/32/144_2.png) [@Enrico](https://forums.fusetools.com/u/Enrico)\
**Post date:** [July 23, 2019, 11:58am UTC](https://forums.fusetools.com/t/fetch-does-not-work-on-android-9-with-sdk-28/7810/9 "2019-07-23T11:58:49Z")

</div>

To add `cleartextTrafficPermitted` to Android Manifest I created a file named `domain.uno` with the following content

```
using Uno.Compiler.ExportTargetInterop;
 
[Require("AndroidManifest.RootElement", "<network-security-config>")]
[Require("AndroidManifest.RootElement", " <domain-config cleartextTrafficPermitted=\"true\">")]
[Require("AndroidManifest.RootElement", " <domain includeSubdomains=\"true\">triestenascosta.it</domain>")]
[Require("AndroidManifest.RootElement", " </domain-config>")]
[Require("AndroidManifest.RootElement", "</network-security-config>")]

```

but when I compile I get the error

```
dominio.uno(7.71): E0000: Expected type or block following ']' -- found <EOF> (unexpected end-of-file)
```

---

<div class="post-metadata">

**Author:** ![Cristian\_Karmy](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/cristian_karmy/32/480_2.png) [@Cristian\_Karmy](https://forums.fusetools.com/u/Cristian_Karmy)\
**Post date:** [July 23, 2019, 4:40pm UTC](https://forums.fusetools.com/t/fetch-does-not-work-on-android-9-with-sdk-28/7810/10 "2019-07-23T16:40:57Z")

</div>

@Enrico I solve the issue adding a uxl with:

```
	<Require Condition="Android" Gradle.BuildFile.End>
	    <![CDATA[
	      // define the task
	      task updateManifest(type: UpdateManifestTask)

	      // implement the task
	      class UpdateManifestTask extends DefaultTask {
	        @TaskAction
	        def update() {

	          // find the manifest and get the contents
	          // TODO: use gradle to find manifest path based on variant/flavor
	          def manifestPath = "app/src/main/AndroidManifest.xml"
	          def manifestFile = new File(manifestPath)
	          def content = manifestFile.getText()

	          // update content, in our case, find and replace some string
	          def updatedContent = content.replaceAll("<application ", "<application android:networkSecurityConfig=\"@xml/network_security_config\" ")
	          manifestFile.write(updatedContent)
	        }
	      }

	      // make processDebugManifest task depend on our new task to ensure the manifest is updated when it's needed
	      afterEvaluate {
	        processDebugManifest.dependsOn updateManifest
	      }
	    ]]>
	  </Require>
</Extensions>

```

To add `android:networkSecurityConfig="@xml/network_security_config"` to the manifest.  
And a network\_security\_config.xml file (you can edit this file as your demand):

```
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>
```

---

<div class="post-metadata">

**Author:** ![Enrico](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/enrico/32/144_2.png) [@Enrico](https://forums.fusetools.com/u/Enrico)\
**Post date:** [July 23, 2019, 5:11pm UTC](https://forums.fusetools.com/t/fetch-does-not-work-on-android-9-with-sdk-28/7810/11 "2019-07-23T17:11:52Z")

</div>

Thank you Cristian.  
Do you mean that I have to create a empty `.UXL` file and simply add the above `<Require>` condition and then create a `.XML` in the same folder of the `.UXL` file?

---

<div class="post-metadata">

**Author:** ![Cristian\_Karmy](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/cristian_karmy/32/480_2.png) [@Cristian\_Karmy](https://forums.fusetools.com/u/Cristian_Karmy)\
**Post date:** [July 23, 2019, 5:22pm UTC](https://forums.fusetools.com/t/fetch-does-not-work-on-android-9-with-sdk-28/7810/12 "2019-07-23T17:22:48Z")

</div>

No, the uxl must contain this to add `android:networkSecurityConfig="@xml/network_security_config"` to the manifest:

> [@Cristian\_Karmy](#):
>
> \<![CDATA[ // define the task task update

and create the .xml file with the config in the same folder as the uxl file
