7

In the android network security docs , it says to create a network_security_config.xml file in res/xml folder.

In order to make an entry in manifest file, it says to make an entry in this way

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
    <application android:networkSecurityConfig="@xml/network_security_config"
                    ... >
        ...
    </application>
</manifest>

But I am getting the error No resource identifier found for attribute 'networkSecurityConfig' in package 'android'

I also checked for the valid attributes in application tag ( android docs ), there is no attribute as "networksecurityconfig"

4 Answers 4

14

You need to set your compileSdkVersion to 24 or higher and set your buildToolsVersion to 24.0.0 or higher.

With regards to the documentation, that's a documentation bug.

Sign up to request clarification or add additional context in comments.

Comments

4

The documentation is fixed, the xml should live inside res/xml which is not in the root but inside android/app:

android/app/src/main/res/xml/network_security_config.xml

From minimumSDK 20 you will need the file and be sure to whitelist localhost and 10.0.2.2 and 10.0.3.2 or you'll have trouble on development

Comments

2

Severity Code Description Project File Line Suppression State Details Error APT2260 resource xml/network_security_config (aka com.companyname.NextGenCloudLibrary.MobileMauiApp:xml/network_security_config) not found.

This error is likely caused by an issue with the AndroidManifest.xml file or an Android manifest generation attribute in a source code file.

NextGenCloudLibrary.MobileMauiApp

C:\Users\ASUS\source\NextGenCloudLibrary\NextGenCloudLibrary.MobileMauiApp\Platforms\Android\AndroidManifest.xml 1

Solution :

Step 1: Select network_security_config.xml -> Properties

Select file as below image and select properties from menu

enter image description here

Step 2: Change build property to AndroidResource

Change build action to AndroidResource

enter image description here

Stpe3: Build Solution - should work

Comments

0

If none of the solutions above worked for you (as they did not for me), probably you have SSL issues, but not on the server side

During development our SSL certs are self-signed, those certs are invalid in the point of view of an Android (so they are for emulators to)

When creating the instance of your httpclient for the MAUI app, do this:

  public class APIService : IAPIService
    {
        HttpClient _httpClient;
        JsonSerializerOptions _jsonSerializerOptions;
        string _baseURI;
        HttpClientHandler handler = new HttpClientHandler();

        public APIService()
        {
#if DEBUG
            handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) =>
            {
                if (cert != null && cert.Issuer.Equals("CN=localhost"))
                {
                    return true;
                }
                return errors == System.Net.Security.SslPolicyErrors.None;
            };
            _httpClient = new HttpClient(handler);
#else
             _httpClient = new HttpClient();
#endif
            _jsonSerializerOptions = new JsonSerializerOptions
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                WriteIndented = true,
            };
            _baseURI = DeviceInfo.Platform == DevicePlatform.Android ? "https://10.0.2.2:5001" : "https://localhost:5001";
        }

}

on your launchSettings.json API file, add a local profile:

"local": {
    "commandName": "Project",
    "dotnetRunMessages": true,
    "launchBrowser": true,
    "launchUrl": "swagger",
    "applicationUrl": "https://localhost:5000;https://localhost:5001",
    "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
    },

I recommend 0.0.0.0:5000 & 0.0.0.0:5001 because your API will listen to all address, useful when running multiple applications

worked for me.

But, just in case you have troubles, add a subdomain. By default 10.0.2.2 should work but I saw people complaining.

On your Platforms/Android folder, create a folder named xml, then create a .xml file called network_security_config.xml and add this:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">10.0.2.2</domain>
    </domain-config>
</network-security-config>

Go to your Androidmanifest file, right-click him and select "Open with" => xml editor, then add this to your manifest tag:

android:networkSecurityConfig="@xml/network_security_config"

with all that set, things should be fine.

Hope it helps

You can see the fully explained tutorial here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.