Android debug

Is there any way to debug a net maui application from Android visual studio emulator ?

my application is trying to access a service from localhost and the connection can't be established

I tried everthing i found in the web unsuccessfully because this file 

network_security_config.xml is never found

this is the Android manifest first line:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application android:allowBackup="true" android:networkSecurityConfig="@xml/network_security_config" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>

this is the  network_security_config.xml content:

<?xml version="1.0" encoding="utf-8"?>

<network-security-config>

<base-config cleartextTrafficPermitted="true">

<trust-anchors>

<certificates src="system" />

</trust-anchors>

</base-config>

  <domain-config cleartextTrafficPermitted="true">

    <domain includeSubdomains="true">10.0.2.2</domain>

  </domain-config>

</network-security-config>

I saved this file inside Platforms/Android/Resources/xml folder but nothing

then I tried in this path

my Project/Resources/Android/xml but nothing

and in the build action I wrote nothing but the file is never found

The android application has this base url: https://10.0.2.2 

It's one month I try to find a solution....

Do you 







3 Replies

BV Brundha Velusamy Syncfusion Team April 12, 2024 09:52 AM UTC

Hi Walter Martin,

 

We have not come across the reported issue in our end. We have shared the below general points that can be ensured.

 

  1. Location of network_security_config.xml: Ensure that the network_security_config.xml file is located in the correct directory within your .NET MAUI project. The correct location for this file is usually within the Resources/xml directory of your Android project. The path should be ProjectName/Platforms/Android/Resources/xml, where ProjectName is the name of your .NET MAUI project. Make sure the file is placed in this location.
  2. Build Action: Set the build action for network_security_config.xml to AndroidResource. This tells .NET MAUI to include the file in the resources of the Android project when building the app. To set the build action:
    • Right-click on network_security_config.xml.
    • Select "Properties".
    • In the Properties window, set the "Build Action" to "AndroidResource".
  3. Emulator Network Configuration: Make sure the Android emulator is properly configured to allow connections to localhost or 10.0.2.2. Check emulator settings or firewall settings that might block such connections.
  4. Debugging: If the issue persists, you may need to debug the network traffic to identify the problem. Tools like Fiddler, Wireshark, or Android's built-in network inspection tools can help you monitor network traffic for errors or issues.

 

If you still face any issues, you can try creating a discussion in the MAUI community: dotnet/maui · Discussions · GitHub

 

Regards,

Brundha V



WM Walter Martin April 29, 2024 09:22 PM UTC

I don't know if this is the source of problem but in the list of options of the "build action" I don't have the " AndroidResource" selection

I selected "MauiAsset" 



PI Prithis Iyyappan Syncfusion Team April 30, 2024 01:04 PM UTC

Hi Walter,

 

Since the issue you are facing is at the application level, Can you please try raising a query in the public forums or .NET MAUI discussion community that we previously shared?

 

Regards,

Prithis I


Loader.
Up arrow icon