1 00:00:01,090 --> 00:00:05,130 There is a ton of useful information on the Android developer site about how to 2 00:00:05,130 --> 00:00:06,220 publish an app. 3 00:00:06,220 --> 00:00:08,840 Just click on Distribute up here at the top, and 4 00:00:08,840 --> 00:00:11,110 then Google Play over here on the left. 5 00:00:11,110 --> 00:00:14,250 This can be a little overwhelming though, navigating all this documentation. 6 00:00:14,250 --> 00:00:15,500 Which is why I'm here. 7 00:00:15,500 --> 00:00:19,050 Just know that you can find lots of information about anything not covered in 8 00:00:19,050 --> 00:00:19,930 these videos. 9 00:00:19,930 --> 00:00:24,060 And, as always, check out the Treehouse forum for additional help or discussion. 10 00:00:24,060 --> 00:00:26,990 Now, there's also a helpful publishing overview document in 11 00:00:26,990 --> 00:00:28,590 the Develop section here. 12 00:00:28,590 --> 00:00:31,930 So lets navigate to Develop > Tools. 13 00:00:31,930 --> 00:00:36,130 And then on the left we want to select Workflow and in here, one more time, 14 00:00:36,130 --> 00:00:38,880 go down to Publishing. 15 00:00:38,880 --> 00:00:43,428 Now specifically, we want to look at this section called Preparing for Release. 16 00:00:43,428 --> 00:00:47,830 Now see [LAUGH] I told you there was a lot of information in here about publishing. 17 00:00:47,830 --> 00:00:49,260 Maybe too much. 18 00:00:49,260 --> 00:00:52,430 Anyhow, I wanna highlight a section down here that says, 19 00:00:53,640 --> 00:00:56,280 turn off logging and debugging. 20 00:00:56,280 --> 00:00:59,750 We want to make sure we disable any calls to any log methods, 21 00:00:59,750 --> 00:01:01,780 because they can affect performance of our app. 22 00:01:01,780 --> 00:01:03,870 And we don't wanna clutter the log head either. 23 00:01:03,870 --> 00:01:07,100 So we need to change a few settings in our app before we publish it. 24 00:01:07,100 --> 00:01:09,780 It seems like a pain, but thankfully, there's an easy way to do this. 25 00:01:09,780 --> 00:01:13,700 Where we don't have to go in and remove every single call to a log method. 26 00:01:13,700 --> 00:01:17,330 Now you're wondering yes, we can publish an app without doing this step, but 27 00:01:17,330 --> 00:01:19,880 it's recommended that we do it for those performance reasons. 28 00:01:19,880 --> 00:01:23,670 It's also a nice safety for us as developers in case we accidentally left in 29 00:01:23,670 --> 00:01:27,550 a bunch of verbose logging that would really impact how the app runs. 30 00:01:27,550 --> 00:01:30,390 In the fun facts app, we only have one log statement, so 31 00:01:30,390 --> 00:01:33,930 it would be easy to either comment it out or remove it, it's not important. 32 00:01:33,930 --> 00:01:37,530 But often on bigger applications, we might have hundreds of log statements or more. 33 00:01:37,530 --> 00:01:40,030 And we don't want to change all that code every time we publish and 34 00:01:40,030 --> 00:01:41,100 update to the app. 35 00:01:41,100 --> 00:01:44,270 Now fortunately, there's a very easy way to do this automatically with our 36 00:01:44,270 --> 00:01:46,070 tools and Android studio. 37 00:01:46,070 --> 00:01:47,960 Android developer tools include something called, 38 00:01:47,960 --> 00:01:52,440 ProGuard, that can be configured to affect our final APK in different ways. 39 00:01:52,440 --> 00:01:54,190 There's a lot we can do with the ProGuard tool. 40 00:01:54,190 --> 00:01:57,460 But for now, all we are concerned about is adding some statements to 41 00:01:57,460 --> 00:02:00,220 strip calls to any of the log methods. 42 00:02:00,220 --> 00:02:02,310 To do this, we need to change two files. 43 00:02:02,310 --> 00:02:06,930 First, open up the build.gradle file, here in the app modules. 44 00:02:06,930 --> 00:02:08,350 So, here, under App. 45 00:02:08,350 --> 00:02:11,010 It's, you can find it under the source directory and 46 00:02:11,010 --> 00:02:13,120 then double click on build.gradle. 47 00:02:13,120 --> 00:02:17,887 In here notice the build type section and inside is a section for release builds. 48 00:02:17,887 --> 00:02:20,060 Which is again, what we're about to build. 49 00:02:20,060 --> 00:02:23,812 By default, ProGuard is turned off with this run Proguard line which is 50 00:02:23,812 --> 00:02:24,870 set to false. 51 00:02:24,870 --> 00:02:28,110 So, let's enable it by changing false to true. 52 00:02:28,110 --> 00:02:31,510 The next line here gets some standard default Proguard settings from 53 00:02:31,510 --> 00:02:36,280 the file listed right here, get default Proguard file, pro-guardandroid.txt. 54 00:02:36,280 --> 00:02:39,880 The second file listed over here is where we can add some custom commands. 55 00:02:39,880 --> 00:02:43,710 But wait, we actually need to switch to a different standard file. 56 00:02:43,710 --> 00:02:45,590 This may be a a little confusing, but 57 00:02:45,590 --> 00:02:48,160 hopefully it makes sense here at the end when we get it working. 58 00:02:48,160 --> 00:02:54,777 So here where it says proguard-android, before the .txt add -optimize. 59 00:02:54,777 --> 00:02:58,710 This uses a different default ProGuard file that is better suited for 60 00:02:58,710 --> 00:03:00,340 optimizing our APK file. 61 00:03:00,340 --> 00:03:04,780 Okay, now let's sync these gradle changes using this sync gradle button up here. 62 00:03:05,800 --> 00:03:07,800 Anytime we make a change to gradle settings in here, 63 00:03:07,800 --> 00:03:08,974 we need to sync the changes. 64 00:03:08,974 --> 00:03:10,517 Okay, now it's working down here. 65 00:03:10,517 --> 00:03:13,520 And okay, it finished without any errors. 66 00:03:13,520 --> 00:03:14,080 Cool. So now we 67 00:03:14,080 --> 00:03:17,230 can edit the proguard-rules file listed over here. 68 00:03:17,230 --> 00:03:19,460 This is located in our project directory as well. 69 00:03:19,460 --> 00:03:20,800 Once again, it's in the app module, 70 00:03:20,800 --> 00:03:23,080 and it's right here below our build.gradle file. 71 00:03:23,080 --> 00:03:24,720 So let's double click on this. 72 00:03:24,720 --> 00:03:28,410 Now, when we open this we see everything is commented out with the hash tags here 73 00:03:28,410 --> 00:03:30,060 at the beginning of the lines. 74 00:03:30,060 --> 00:03:33,820 I'm going to paste in some lines that are available in the teacher's notes below for 75 00:03:33,820 --> 00:03:34,930 you to copy and paste as well. 76 00:03:36,230 --> 00:03:40,300 So, this is an option for Proguard called assumenosideeffects. 77 00:03:40,300 --> 00:03:42,450 This is only applicable when optimizing. 78 00:03:42,450 --> 00:03:44,745 Which is why we had to switch to that other default file. 79 00:03:44,745 --> 00:03:49,795 But the basic idea is that these methods listed here from the log class, 80 00:03:49,795 --> 00:03:53,030 named up here, will be removed by proguard. 81 00:03:53,030 --> 00:03:55,591 Okay, let's save the changes to this file, and 82 00:03:55,591 --> 00:03:58,156 now we're ready to build our release ready APK. 83 00:03:58,156 --> 00:03:59,377 I should note though, 84 00:03:59,377 --> 00:04:03,690 that if you are logging sensitive information, like sensitive user details. 85 00:04:03,690 --> 00:04:06,768 You will need to use a different method to remove the strings that 86 00:04:06,768 --> 00:04:09,060 are actually logged in the log methods. 87 00:04:09,060 --> 00:04:12,747 APK files can be de compiled and people can actually look at your code. 88 00:04:12,747 --> 00:04:16,920 So you need to remember this if you're ever coding sensitive information. 89 00:04:16,920 --> 00:04:19,480 The actual calls to these log methods are stripped, but 90 00:04:19,480 --> 00:04:22,550 the code is still in here and it would be visible when decompiled.