Category
📚
LearningTranscript
00:00Welcome back guys. Now in this lesson we're going to just go through a few
00:06explanations of how our emulators work and some configurations that are needed.
00:13So up until now clearly we've been focusing on Android development mostly
00:18because of the environment that I have which is a Windows PC and it would be a
00:22bit more difficult to do this with Mac OS and I haven't turned on developer
00:26mode in my Windows. So I'm focusing on Android development. So the the main of
00:32our concern really is how the Android emulator interacts with other networks.
00:37So the fact is that this Android emulator actually is running like in
00:44its own little network as it stands right. So yes it reaches out to the
00:49internet and whatever but it cannot see localhost on my machine as easily
00:55especially if it's broadcasting from Visual Studio. So I had a round of
01:02difficulties trying to get that to work and especially with SSL certificates and
01:06all sorts of things and in a development environment there's a lot of
01:11configuration overhead when it comes to getting and trusting certs and you know
01:16for development purposes. So to spare all of that we just publish the API to IIS
01:22and it is not protected by SSL. That's what we did in the previous lesson.
01:28Now what we need to do is let the Android emulator know that it can
01:35actually connect to certain addresses without needing SSL because it in itself
01:43is actually looking for a secure connection point. So what I'm about to do
01:48if we were integrating with a fully secured third-party SSL secured third
01:54party API we wouldn't necessarily have to do this but for development purposes
01:59and for our own local testing then it is necessary. So after that monologue let me
02:06get to it. The first thing I want to do is go to platforms. Remember that with
02:11MAUI we have a platforms folder which allows us to configure specific
02:17manifest files and you know device specific files for the different
02:24operating systems. So we're dealing with Android right now if I expand
02:30Android then I'm going to see that I have a file called Android manifest. So
02:36the red tick here means that I have modified it since the last time we were
02:39here and that's fine I'm going to walk you through everything. What I want you
02:43to do is in the resources folder create a new folder and we're going to call it
02:48XML. Then inside of the XML folder go ahead and add a new file new item and
02:55it's an XML file that I'm calling network underscore security underscore
03:01config dot XML. So make sure you get that name correctly right network underscore
03:07security underscore config dot XML. Inside this file and let me comment it
03:15out some of it remove what is not absolutely necessary inside this file we
03:20want this text and I'm going to explain what all of this is saying. So open up
03:26this node network hyphen security hyphen config and then inside of that we want
03:33domain hyphen config and then it's going to say clear text traffic permitted
03:39is equal to true. So clear text traffic is essentially saying well if traffic is
03:48not encrypted by SSL or protected by SSL then it is what we call clear text. So
03:54the Android emulator Android phone Android devices in general do not take
03:59kindly to connecting to a source that is not sending over an encrypted message
04:04right. So this is why we have to go in manually and say I am allowing it yes
04:10please permit it allow to be connected to an endpoint that is not SSL secured.
04:18Then we go on to specify domains that are allowed to do this clear text
04:25traffic. So I say domain include subdomains equal true so the domain and
04:32any subdomain of this main domain and then I have 10.0.0 sorry 10.0.2.2
04:42now 10.0.2.2 is essentially a loopback Android address for localhost. So like I
04:52said the Android the emulator can't really see localhost that way if I'm
04:56running it from Visual Studio. So if you have done other courses with me when I
05:01teach API development and consuming the API you would run both projects and then
05:05you know one project would talk to the other. Android phone is not a really like
05:09a project it's by itself so it can't really see the Visual Studio localhost.
05:14So that and localhost is really more going to be seen as 10.0.2.2
05:2210.0.2.2 as opposed to 198.168.0.1 or 127.0.0.1
05:30so those are the usually the IP addresses associated with localhost on a
05:35Windows machine. This is localhost on an Android so what I'm saying here now is
05:40allow any traffic coming from this address to be seen by the domain allow
05:46to be to be allowed for clear text rather allow any localhost domain
05:52traffic to be seen and I added this one because I did an IP config on my machine
05:57I saw that my localhost or my IIS localhost is actually broadcasting from
06:03that but I don't really use that one in the course so that one is optional and
06:06this one is actually relative to your machine configuration so make sure that
06:10you capture at a bare minimum these two but just as a contingency to get to that
06:16one if I go to my command prompt and then say IP config IP config then the
06:29address that I selected would have been underneath the Ethernet adapter and the
06:35IPv4 address. So I selected this one and that is what I added to this
06:43config file so as a contingency just to make sure that we're all on the same
06:48page you can also take that step. Now after you've done all of that
06:55what we want to do is go to the Android manifest and we're going to modify the
07:00application section let me break lines so it's easier to see my modification
07:07and this line would be the modification I made this one. So we add
07:16android-networksecurityconfig and then it's equal to and we put at sign
07:22and the path so at sign and our path is XML because of the XML folder slash the
07:28name of the file which was network security config but not XML just the
07:33name not the extension right and then we can do that and then we save and with
07:40that configuration made we can proceed now to start writing code confidently
07:47that will talk to our API