 Hi everybody, Dr. Lehman here. So today what we'll talk about, one of the things that we'll talk about is the Google service, which is called Firebase. So Firebase is a backend for mobile applications and also other web applications that provides a whole variety of services to your application that it might need. So what we will do in this class is we are going to use Firebase to kind of service the back end for your application. You've gotten a lot of experience built in the interface side with the user, but now we are going to want to do some more interesting things with those user interactions in terms of storing data, getting data from the cloud, maybe accessing location information, and Firebase is one of the tools that we will use to do that. So as you know, having being veteran users of mobile applications is that mobile apps are more than just what you see on the screen. Mobile apps need to be supported to store data somewhere. And also you have apps that share data between different users. And that's kind of the dominant thing that you see with mobile apps. They share data between different people, certainly all of the most popular applications do it. But then your apps also do a lot of other things, like, hey, I've got a login feature, username and password, or maybe you've seen those little buttons. It's like, sign in with Facebook or sign in with Google, sending messages between people. Whenever a crash happens, you'd like to be able to upload that, or at least the developer asks you to be able to upload that. So apps do all of these things. And the question is, well, how in the world do they do them? Because mobile apps in particular, they're connecting. They share data, they store data. And even between different devices that you may have, if you have a tablet and a desktop and a phone, you expect that your data, say for your email or your Snapchat account or whatever, Instagram account, it's easy to share that information amongst even your own devices. Well, all these things are connected. And Firebase is what's going to give us some tools to do that. Now, in the early days of mobile development, of computing, of web application development, you had to write it all. If you want to store data in some remote location, like your Snaps or your Instachats or whatever, where you want to send messages to, say, another person on the other side of the planet, you, the developer, you still have to write that code. And that code is hard to write. It's error-prone, it can fail, network connections are not reliable, if you've taken the network class, you know this. So fortunately, though, nowadays, everything is in a library. And in particular, for mobile apps, we have these guys called Cloud Service Providers. And you have heard of at least Amazon Web Services, or AWS. Microsoft has one called Azure. Firebase is Google's kind of cloud service product. And what they allow you to do is they provide what's a cloud service provider? Well, what's a service? Well, a service is things like a database in the cloud or a messaging between different users of your app or authentication. These are services. Every app needs these things, not every app. But a lot of apps need these things. And so Amazon, Microsoft, and Google said, hey, we've got cloud. We've got technology. Let's allow people to use our cloud and then charge them for it, right? This is Amazon's big business model. That's where they earn most of their monies in the margins of their AWS service. So it's insanely profitable. And what makes them good, why we use them and why they're so profitable for these companies is they're relatively easy to use. And you'll see some examples of this. But that's it, right? These companies, by putting things like database, messaging in the cloud, and then you, the app developer, all you have to do is make some Java calls to like say, hey, send this message to Joe in China. That's easy, right? And it's in their best interest to make these things easy because if it's easy, then you can build it and they can charge you for it. All right, so the one that we are going to use in this class for making your mobile apps a little more meaty is called Firebase, okay? So Firebase, as I mentioned, is Google's product and it's not free. If you are the big boys, like Snapchat or Instagram and those sorts of people, they get charged a lot to use these cloud services like storing pictures and storing files, storing data, et cetera, et cetera, et cetera. But all of the services, including Firebase, they do have a free tier and that's usually gonna be enough, should be enough for us in our class. Pricing is a little different for these services. They don't charge you, say, $15 a month. They all kind of look at how many operations are you doing within a service? So say, oh, I make 50,000 database calls each month, read or write, or I upload 100,000 files for my users to share. That's how they say. They will look and see how many things that you did with their service and charge you for that. But their pricing is pretty generous at the free tier, at least for Firebase, certainly enough for us in our class. So when you sign up for Firebase and you create an account and we use it for our apps, you're not gonna incur any costs. So don't worry about that. So how are we gonna get this thing in your mobile app? And I'll show you an example of this here in just a minute. It's pretty easy. So one of the reasons that we're using Firebase is, A, it comes from Google. Google owns Android or used to curate Android anyway. They have a big hand in Android. So Firebase was kind of made with Android in mind. Consequently, the documentation is really friendly for Firebase for Android developers. And it just works. If you have any experience with Amazon's web services, their documentation is a little rough, right? So we're using Firebase because it just works and it's pretty good. And it's really easy to integrate into your app. All we will have to do is to add some necessary libraries in build.gradle, which you've done a few times already. And you need to add this private configuration file. So this configuration file is called GoogleServices.json. We get it from Firebase and I'll show you how to do that in a minute. And basically this file is your key, right? It's private, it's yours. Whenever you put this configuration file in your app, your app will talk to Firebase and that's how Firebase knows that it is you, Joe Blow, that's actually making this request. So you have to keep this key, this configuration file private. It cannot go and get hub. You shouldn't share it with anyone unless they're a teammate because it's this key that tells Google or Firebase, excuse me, who's using their services and who to bill, okay? So if your private configuration file gets out there and the world say, you've accidentally put it on GitHub, there are people who go scan in GitHub for these things and they'll suck it into their app and they'll run your bills up, okay? So you gotta keep this file safe and private. For GitHub, you shouldn't need to worry about it for your project because your project is already configured to not put that file in GitHub. So anyway, let's take a look at this thing. Here's the URL for Firebase. In your lab for this week, you're gonna do everything that we're gonna do here, but I would just wanna show it to you as well. All right, so I'm gonna click on this link and it's popped up on my other screen. All right, let me close my other tabs. All right, so when you come to the Firebase page, you may need to log in, right? So you need a Gmail account in order to use Firebase. Gmail accounts are free for sign up. Make sure it's something you'll remember though. If you make an account, you know, write it down, you're gonna need it later, okay? So you'll see something that looks like this and I'll click on get started and it's gonna take us to the console, the Firebase console. You can see here, I already have a couple of projects, personal things I've worked on, things from past semesters. But let me first go back over to Android Studio. So I have a very, I've created in Android Studio a blank application, the empty application that just shows hello world. That's all this is. But I'm anticipating, for purposes of teaching you all, that I'm gonna wanna connect to Firebase, okay? So what do I need to do next? I've already got my application created, I go into Firebase and what I need to do is I need to add a project, okay? So I click on add a project, let's give it a name. You can call it whatever you want. Here, the name doesn't matter or it says add to one of your existing products. So let's just say Firebase example one, okay? So I'm gonna create this project, Google Analytics, do you wanna enable Google Analytics? I'm gonna leave this checked, you don't need to, it's up to you. Choose a Google Analytics account. Okay, you can pick something here if you want. Let me turn this off, that might be easier. There we go, less options. Okay, so it's creating a project for me and what you should do is basically for every app that you make in your career, you are gonna want a separate cloud project for that. Okay, you don't necessarily wanna share resources. Okay, so here's my Firebase example project and they've got these wonderful, cool little graphics. If you look over here on the left, these are the different services that Firebase provides. An authentication service for handling users logging into your app, a database, storage, file storage, hosting functions ML Kit, we won't use these things. Crashlytics, we will get into that so your app crashes in the field. What are you gonna do? You don't have it attached to a debugger. Crashlytics is the answer and there's a whole bunch of other things over here. We're not gonna get into all these things yet. In the labs in the future, we will talk about authentication because you will need that for your project. We will talk about database and we will talk about storage, okay? But before we do any of that, you have to get started by adding your Firebase to your app, okay? So I am going to click on the little Android icon. Now, and I'm taking to the screen. So the first thing I need to do is I need to register my app and for this I need my Android package name, okay? So it tells me here, the package name is generally the application ID in your app level build.gradle file. So let's go to that. So I'm over in Android Studio. Gonna go to my build scripts. Here is my app. I'm in the Android view here at the top. Gonna go into my build.gradle and here's what it's talking about. Application ID. So I'm just gonna grab this. Now it's gonna be important at this point that you not change this application ID. If you do, you're gonna run into all sorts of trouble in the future. So whatever your, remember, your application, your package name, which is generally also your application ID needs to be the same for the life, the entire lifespan of your app. So before you go through this process of setting up Google services.json, make sure this application ID and make sure your package names are what you want them to be, okay? So I'm gonna take this. This doesn't need to be globally unique amongst all apps ever developed. That doesn't need to be that way. I'm gonna copy this, paste it in here, give it a nickname. This can be whatever you want and we're gonna leave this blank and click register. And it's gonna think for a few minutes. And now, here is our configuration file. This is the thing that you will need, okay? This is the thing you need to keep safe. You should keep a copy of it somewhere but not in GitHub, okay? So keep it on your desktop, keep it in a shared folder, whatever, that's fine. Let me grab a copy of it here. I'm gonna save it. Let me get it from my downloads folder, all right? So the next thing that you can need to do, you might be able to see this, you might not, let me zoom in a little bit, is you have to take this file you just downloaded and drop it into your app folder right here, okay? So let me go to my downloads folder and grab the file. So I'm getting it off my other screen here. Just give me one second, okay? Turns out I already have a Google services.json file. So let me rename it, get rid of the other one, okay? So I'm grabbing my file and I'm copying it. Let me go over to Android Studio, paste it in. Now I'm pasting it into the app folder. That's where it's gotta go, okay? I get this confirmation dialog, here it is. Here's this file. Normally this information would be private. You don't wanna share this with anyone. I'm showing it to you. If you were a malicious person, you could do bad things with my account. I'm not gonna let you do that because I'm gonna delete this project. But this stuff is private. Do not share it with anyone, okay? So, but now the file is here, right? If you wanna see the file, you have to switch to the project view and open the app folder and there it is, okay? So that's where it needs to be. All right, let me go back, okay? We have to make a few changes to our Gradle files, all right? So in the project level build dot Gradle, project slash build dot Gradle, we need to add this line. I'm gonna click here and copy it. I'm gonna go back and add that file. Build Gradle at the project level, okay? Pop this in here. And again, don't worry if you're trying to follow along, don't worry right now. You have a lab that goes through all of this stuff, okay? I'm gonna pop that in here and let me go back because there's another step. Google's Maven repository, they're already in there. We don't need to worry about that. But in my app level build dot Gradle, I do need to grab this line of applying the plugin. Okay, switch to my app level build dot Gradle and I'm gonna dump it right here, okay? Now we go back and it wants me to sync my Gradle files, so let's do that. Hopefully we won't have any errors. Thinking, thinking, green check marks, usually a good thing, all right? So now we go to next and let's see. Usually, sync it, continue to the console and we're done, that's it. We should be good to go, all right? So in the next video, what I will show you is gonna be how to add authentication over here to a Firebase project, right? Let me switch back to my slides real fast for you. So main takeaways from all this. First, know what Firebase is. It's Google's app development platform and it provides all sorts of services like user authentication, file storage, database, et cetera. Each Firebase service has a different pricing model. You don't need to know that, but you can do a lot with a free tier. So whenever you sign up for Firebase and it says you need to add a credit card, don't freak out unless you're really irresponsible or you share your Google services.json with someone malicious, you'll be fine. The way that we are gonna interact with these Firebase services is through Java libraries. So you're gonna make Java calls and some of them will be simple, some of them will be a little more sophisticated, but it's just Java code, okay? And finally, you need to register your app at console.firebase.google.com before you can use any of these services that will generate for you Google services.json and then you will be able to access Firebase, all right? So next time we will talk about an example of this using Firebase authentication.