1
00:00:04,600 --> 00:00:06,000
Good day, everyone. Welcome back.

2
00:00:06,600 --> 00:00:10,600
Everything we've done so far in the course has been using the debug build.

3
00:00:11,400 --> 00:00:13,200
That's great while developing,

4
00:00:13,200 --> 00:00:16,860
as it allows all our debug log entries to appear in the logcat.

5
00:00:17,740 --> 00:00:20,940
You wouldn't normally want to take up space on the user's phone

6
00:00:20,940 --> 00:00:22,240
with huge log files,

7
00:00:22,640 --> 00:00:26,080
and the debug log entries are stripped out of the release build.

8
00:00:26,880 --> 00:00:30,240
As I mentioned, any code that's dependent on

9
00:00:30,240 --> 00:00:33,600
buildConfig.DEBUG being true

10
00:00:34,000 --> 00:00:37,600
also won't be compiled into the release version of the app.

11
00:00:38,400 --> 00:00:39,800
It gets better than that.

12
00:00:40,400 --> 00:00:43,200
Any classes you put into that debug folder,

13
00:00:43,200 --> 00:00:47,000
the one we created, and that's showing with (debug) in parentheses

14
00:00:47,000 --> 00:00:49,800
after the package name in the project pane

15
00:00:50,300 --> 00:00:53,500
those classes won't be compiled into the release version either.

16
00:00:54,800 --> 00:00:57,160
We can check that to make sure.

17
00:00:57,520 --> 00:00:59,120
From the build menu,

18
00:01:01,220 --> 00:01:04,879
choose the option build bundles/apks

19
00:01:05,239 --> 00:01:07,440
and then build apks.

20
00:01:09,740 --> 00:01:13,740
When the build is finished, a dialog pops up at the bottom

21
00:01:13,740 --> 00:01:15,540
of the android studio window.

22
00:01:16,340 --> 00:01:19,140
Click the link to analyze the apk. The apk,

23
00:01:22,800 --> 00:01:27,300
by the way, is the file that's used to deploy your package.

24
00:01:27,700 --> 00:01:30,580
You may have noticed messages about apk

25
00:01:30,580 --> 00:01:32,780
when running your apps from android studio.

26
00:01:33,080 --> 00:01:35,680
An apk file is just a zip file,

27
00:01:35,680 --> 00:01:38,680
containing everything that the app needs in order to run.

28
00:01:39,180 --> 00:01:43,170
All your classes and resources are included in the apk file.

29
00:01:44,070 --> 00:01:46,570
In earlier versions of android studio,

30
00:01:46,570 --> 00:01:50,370
you had to extract the contents of the apk zip file

31
00:01:50,370 --> 00:01:53,370
and examine it using your computer's file manager

32
00:01:53,700 --> 00:01:57,300
or a terminal session. Now things are much easier.

33
00:01:57,660 --> 00:02:00,960
Android studio has an apk analyzer.

34
00:02:01,320 --> 00:02:04,620
This gives a neat summary of the sizes of the various parts.

35
00:02:05,420 --> 00:02:07,220
You can see, for example,

36
00:02:07,580 --> 00:02:11,680
if your res folder is making up a large percentage of the overall size.

37
00:02:12,340 --> 00:02:16,140
The raw file size of this app is around 2.5 megabytes

38
00:02:16,500 --> 00:02:20,000
with our resources, icons, images and so forth

39
00:02:20,000 --> 00:02:22,500
making up nearly 400 kilobytes of that.

40
00:02:23,380 --> 00:02:26,980
If you've got a lot of images, that value might be a lot higher.

41
00:02:27,780 --> 00:02:30,280
We'll look at reducing the value a bit later.

42
00:02:30,280 --> 00:02:34,580
When we use vector graphics for our icons instead of png files.

43
00:02:35,240 --> 00:02:38,040
Okay. Most of the app size

44
00:02:38,040 --> 00:02:40,240
is the classes.dex.

45
00:02:40,640 --> 00:02:44,740
So click on that to get a more detailed breakdown in the bottom part of the window.

46
00:02:48,940 --> 00:02:51,940
That shows the various packages that make up the app.

47
00:02:52,440 --> 00:02:55,340
Android x makes up a lot of the total space used

48
00:02:55,640 --> 00:02:59,240
and that's things like the new support libraries that we're using in our app,

49
00:02:59,540 --> 00:03:01,340
the recyclerview, for example.

50
00:03:01,740 --> 00:03:05,940
Google are working on ways to share things like android x amongst apps.

51
00:03:06,490 --> 00:03:10,930
At the moment, those libraries are compiled into each app that uses them.

52
00:03:11,430 --> 00:03:13,230
Obviously that's not very efficient,

53
00:03:13,730 --> 00:03:16,230
but there are problems with allowing them to be shared.

54
00:03:16,730 --> 00:03:20,630
When google sorts it out, app sizes will shrink substantially.

55
00:03:21,290 --> 00:03:23,290
Expand the android x entry.

56
00:03:25,950 --> 00:03:29,850
And you'll see that appcompat is a substantial amount of the total.

57
00:03:31,210 --> 00:03:34,100
That will be support in the android package

58
00:03:34,100 --> 00:03:37,500
if you haven't converted your app to use android x.

59
00:03:38,000 --> 00:03:39,900
These figures don't add up by the way.

60
00:03:39,900 --> 00:03:43,300
So don't try to balance the sizes in the bottom part of the screen

61
00:03:43,300 --> 00:03:44,600
with those in the top part.

62
00:03:45,400 --> 00:03:48,700
There's all sorts of clever compression techniques going on here.

63
00:03:48,700 --> 00:03:52,690
Use the sizes as a relative measure of the various packages

64
00:03:52,690 --> 00:03:56,680
and don't try to equate those bottom figures with the top ones.

65
00:03:57,560 --> 00:04:01,060
What we're really interested in are the entries for our packages.

66
00:04:01,660 --> 00:04:06,360
I called my package learnprogramming.academy.doxtimer.

67
00:04:06,660 --> 00:04:09,660
So I have to expand that to see more details about it.

68
00:04:10,460 --> 00:04:14,060
If you used a different domain, expand the relevant entry in the list.

69
00:04:27,420 --> 00:04:30,320
The entry we're interested in at the moment under

70
00:04:30,320 --> 00:04:34,620
learnprogramming.academy.doxtimer is a debug entry.

71
00:04:37,120 --> 00:04:39,920
In there, we can see our testData class.

72
00:04:40,720 --> 00:04:43,720
So in the debug build that class is included.

73
00:04:44,120 --> 00:04:47,620
Close the window then go to build,

74
00:04:51,620 --> 00:04:53,220
select build variant.

75
00:04:54,580 --> 00:04:56,940
You may need to click in an editor window

76
00:04:56,940 --> 00:04:58,740
to enable that entry in the menu.

77
00:04:59,640 --> 00:05:04,040
Although it doesn't look like it, the build variant box on the left is a drop down.

78
00:05:04,700 --> 00:05:06,700
Click it, then select release.

79
00:05:11,200 --> 00:05:15,200
We can now create a release apk, using build,

80
00:05:17,800 --> 00:05:21,600
build bundles build apks again.

81
00:05:22,800 --> 00:05:26,800
All we could do if we didn't have an error in main activity.

82
00:05:27,300 --> 00:05:29,900
The test data class is no longer available.

83
00:05:29,900 --> 00:05:33,900
When you create a release build, anything in the debug directory

84
00:05:33,900 --> 00:05:35,260
doesn't get included.

85
00:05:35,660 --> 00:05:37,360
That means the release build

86
00:05:37,360 --> 00:05:39,960
has no knowledge of our testData class.

87
00:05:40,560 --> 00:05:43,360
In fact, if you check the project pane,

88
00:05:50,860 --> 00:05:53,360
the debug package isn't even showing up.

89
00:05:53,760 --> 00:05:55,960
Main activity is showing two errors.

90
00:05:56,420 --> 00:05:59,920
There's one when we try to use the testData class in the

91
00:05:59,920 --> 00:06:01,920
on options item selected,

92
00:06:02,280 --> 00:06:04,480
and the others in the import section

93
00:06:04,480 --> 00:06:07,080
when the program tries to import that class.

94
00:06:10,680 --> 00:06:13,680
In a release build, anything in debug

95
00:06:13,680 --> 00:06:15,580
just doesn't exist effectively.

96
00:06:16,080 --> 00:06:20,440
So there's no chance of us accidentally, including these debug classes,

97
00:06:20,640 --> 00:06:24,540
testData and test timing in the release version of our app.

98
00:06:25,040 --> 00:06:27,040
The app just won't compile.

99
00:06:27,640 --> 00:06:30,440
This isn't the most sophisticated way of handling this.

100
00:06:30,800 --> 00:06:33,400
If you work for a company developing android apps,

101
00:06:33,650 --> 00:06:36,850
you'll probably find they have more advanced processes in place.

102
00:06:37,510 --> 00:06:40,610
But as a developer, this technique is a good start

103
00:06:41,010 --> 00:06:44,010
to make sure you don't include debug classes

104
00:06:44,010 --> 00:06:45,510
in the apps that you deploy.

105
00:06:45,870 --> 00:06:48,470
Create a debug package as we've done here,

106
00:06:48,470 --> 00:06:52,270
and there's no chance of messing up by giving users things

107
00:06:52,270 --> 00:06:53,870
they really shouldn't be seeing.

108
00:06:54,530 --> 00:06:58,890
When you want to deploy your app, comment out the code that's giving the error.

109
00:07:17,690 --> 00:07:21,350
You may also have an error whenever buildConfig is used.

110
00:07:21,350 --> 00:07:25,350
If that happens, rebuild the project from the build menu.

111
00:07:30,350 --> 00:07:34,710
To check what's in our release apk, go to the build menu again

112
00:07:34,710 --> 00:07:36,910
and choose build bundles,

113
00:07:39,210 --> 00:07:40,570
build apks.

114
00:07:43,930 --> 00:07:47,130
Then click the analyze link in the dialog.

115
00:07:50,230 --> 00:07:52,730
It may take a while to create a release build.

116
00:07:53,030 --> 00:07:55,630
Keep an eye on the progress at the bottom of the screen.

117
00:07:55,630 --> 00:07:57,330
Click classes.dex.

118
00:08:00,130 --> 00:08:02,030
Then expand your package name

119
00:08:02,030 --> 00:08:05,390
learnprogramming.academy.doxtimer.

120
00:08:11,190 --> 00:08:14,790
Learnprogramming.academy.doxtimer in my case.

121
00:08:15,340 --> 00:08:17,940
Notice that the debug entry isn't present.

122
00:08:18,440 --> 00:08:20,640
That class just doesn't exist in build.

123
00:08:23,940 --> 00:08:27,040
The raw file size is also smaller than it was.

124
00:08:27,840 --> 00:08:31,200
A lot of other debug stuff has been stripped out of the release version,

125
00:08:31,200 --> 00:08:33,900
including all our log.d calls.

126
00:08:34,500 --> 00:08:36,700
Okya. Close the analyzer.

127
00:08:38,900 --> 00:08:41,500
Then make sure you set the build type back to debug.

128
00:08:42,799 --> 00:08:43,600
Build,

129
00:08:45,600 --> 00:08:47,100
select build variant,

130
00:08:48,350 --> 00:08:49,250
debug.

131
00:08:49,910 --> 00:08:53,610
That's important because you can't run a release build without signing it

132
00:08:53,610 --> 00:08:55,910
and we'll be covering that in a later video.

133
00:08:56,900 --> 00:08:59,500
I better uncomment those two lines as well.

134
00:09:10,860 --> 00:09:13,660
We've now got a way to generate test data in our app,

135
00:09:14,060 --> 00:09:19,050
and we've seen how to avoid accidentally giving users access to the testData class.

136
00:09:19,750 --> 00:09:23,750
Even if we somehow ship a version with that generate menu item enabled,

137
00:09:24,110 --> 00:09:25,710
it won't work for our users.

138
00:09:26,570 --> 00:09:27,570
That's a good thing

139
00:09:27,930 --> 00:09:31,430
because trying to unscramble test data from their live data

140
00:09:31,430 --> 00:09:32,930
would be far from trivial.

141
00:09:33,830 --> 00:09:36,330
If you make a mistake and ship a version of the app

142
00:09:36,330 --> 00:09:39,930
with that menu option enabled, it'll crash when they tap it.

143
00:09:40,430 --> 00:09:41,420
That's not good.

144
00:09:41,820 --> 00:09:44,320
What all you have to do is deploy a fixed version.

145
00:09:44,920 --> 00:09:48,720
If you left the testData class in, the app wouldn't crash.

146
00:09:49,080 --> 00:09:53,380
Instead, it would add a load of rogue records to their database,

147
00:09:53,740 --> 00:09:57,040
explaining to your users that the data they've collected over the last

148
00:09:57,040 --> 00:10:00,400
year is useless isn't something you want to have to do.

149
00:10:01,500 --> 00:10:06,000
In the next video, we'll make a start on displaying reports about the data that we've got.

150
00:10:06,360 --> 00:10:07,360
I'll see you there.

