Building a Release-Ready APK4:25 with Ben Jakuben
We need to digitally sign and export our app, but fret not, it is easier than it sounds! In this video we'll see how to use the built-in tool in Android Studio to build the APK.
Digitally signing and exporting an app is actually easier than it sounds. 0:00 There's a wizard built into Android studio. 0:04 Yay. 0:06 So, what exactly is a release ready APK? 0:07 When we build our App in Android studio, it creates a file with a .APK extension, 0:11 which stands for Android Application Package. 0:15 Now, while we are writing and testing the app in Andriod Studio, 0:18 this APK file is digitally signed with something called a debug certificate and 0:21 it's all taken care of in the background for us. 0:25 We don't even have to worry about. 0:27 The debug certificate allows us to run the app on an emulator or on a test device. 0:28 But it's not an official certificate, and the APK cannot be 0:33 uploaded to an app store like Google Play when compiled with the debug certificate. 0:36 When it's time to publish, we need a real certificate. 0:41 Every Android application needs to be digitally signed to 0:43 help protect end users from Malicious Software or Malware. 0:46 For publishing where users install it through Google Play, 0:50 we need to digitally sign the APK with a self-signed certificate. 0:53 Self-signing guarantees that our app is from us and only us. 0:56 It prevents hackers or 1:01 bad guys from impersonating us or publishing apps under our name. 1:02 Cuz only we have that private self-signed certificate. 1:05 Once again, this is all taken care of for us in Android Studio. 1:09 So, with your apps project open, click on the Build menu up here, 1:12 and then click on Generate Signed APK. 1:16 So, first select the module that has your app code. 1:20 Ours is just called app for FunFacts. 1:23 Click Next. 1:26 Now, we need to create a new key store. 1:27 Note that the next time we do this we would want to choose an existing one but 1:29 for now we are going to click on Create new. 1:32 The key store holds the private digital key that we need to sign all of our apps. 1:34 We need to use the same key store to sign any updates to the same app. 1:38 Now, for different apps we could generate a new key store for each app. 1:42 But the recommended approach is to create one key store for yourself or 1:46 your organization and then sign all of your apps with that same key store. 1:49 Okay. So, finally let's click on this button. 1:53 And we're going to create a new key store and 1:55 store it in a common location so that we can use it in future apps. 1:57 So, click on the Browse here for 2:00 the path and I'm just going to put mine right in my home directory. 2:02 That's fine. And 2:05 down here at the bottom we have the file name. 2:06 And I'm just gonna use treehouse. 2:08 Keystore as mine, and then click OK. 2:11 Now, enter a secure password, then confirm it and next we 2:14 want to enter an alias or a name for the key we want to create in this key store. 2:21 Now, I know this might be a little confusing with keystores and 2:25 keys and certificates. 2:28 All these words are kinda referring to the same thing but 2:29 as long as you use the wizard like this it keeps everything organized, and 2:32 it's pretty simple, especially once we set it up. 2:35 For the name I'm gonna type treehouse_key, and then again, another password. 2:37 Now this could be the same password or a different one, it's up to you. 2:42 And next we need to enter the number of years that this key should be valid. 2:48 We want this certificate to be valid as long as our app is in existence. 2:52 The default value of 25 years is probably just fine. 2:56 But just to be safe lets pick a really high number like I don't know 900 and 99. 3:00 Yeah that should work. 3:04 Okay next you can add the rest of the organizational details so 3:06 I'll quickly fill out nine. 3:09 Okay and once you have those filled in you need at least field filled in here at 3:13 the certificate but you don't have to fill out everything. 3:16 Then click OK when you're done. 3:18 Okay, I'm going to remember the password, but make sure you remember your 3:20 password and the location that you're saving the key store. 3:23 You might wanna even copy this key store file and maybe put it on a USB stick or 3:26 upload it somewhere or maybe even email it you yourself. 3:31 You do not wanna lose this. 3:33 Okay, we click Next and the APK destination folder is 3:34 where the APK file will be generated, and it's going to be in our app module so 3:38 we'll be able to see it here in the project as soon as it's done. 3:42 Make sure the build type is set to release. 3:45 We don't wanna do debug, 3:46 that's what we're normally building whenever we're testing our app. 3:47 So as of release, we can go ahead and click Finish. 3:50 Okay, we see some messages down here about gradall executing the tasks and 3:53 in a moment it should be done. 3:57 Okay, success. 3:59 There's a message up here, generate signed APK and it tells us where it is. 4:00 It's also down here at the bottom in case you need it. 4:03 And, check this out there's a new file in here, our new APK, very cool. 4:06 So, this is in our file structure for our project and 4:09 if I Right-click on here, I can even go to Reveal In Finder and 4:12 it shows up here in the file explorer in our project, very cool. 4:16 Okay, make a mental note of the location here as were going to 4:20 upload this file from here in just a few moments. 4:23
You need to sign up for Treehouse in order to download course files.Sign up