-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreactnative-size.html
132 lines (132 loc) · 4.69 KB
/
reactnative-size.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>How I Reduced the Size of My React Native App by 86%</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
href="./styles/output.css"
type="text/css"
media="screen"
/>
<script
defer
data-domain="aswinmohan.me"
data-api="/stats/api/event"
src="/stats/js/script.js"
></script>
</head>
<body>
<div class="flex items-baseline justify-between">
<p>
<a href="/">back to home</a>
</p>
<p>2018-Feb-10</p>
</div>
<article>
<section>
<h1>How I Reduced the Size of My React Native App by 86%</h1>
<p>
I borrowed 25$ from my friend to start a Play Store Developer account
to put up my first app. I had already created the app, created the
assets and published it in the store. Nobody wants to download a todo
list app that costs 25mb of bandwidth and another 25 MB of storage
space.
</p>
<p>
So today I am going to share with you how I reduced the size of Tet
from 25 MB to around 3.5 MB.
</p>
</section>
<section>
<h3>Size Matters</h3>
<p>
Like any beginner, I wrote my app using Expo, the awesome React Native
platform that makes creating native apps a breeze. There is no native
setup, you write javascript and Expo builds the binaries for you.
</p>
<p>
I love everything about Expo except the size of the binaries. Each
binary weighs around 25 MB regardless of your app.
</p>
<p>
So the first thing I did was to migrate my existing Expo app to React
Native.
</p>
</section>
<section>
<h3>Migrating to React Native</h3>
<ul>
<li>
<code>react-native init</code> a new project with the same name
</li>
<li>Copy the source files over from Expo project</li>
<li>
Install all dependencies of the Expo project except Expo specific
libraries.
</li>
<li>Make neccesary adjustments to <code>app.json</code> file</li>
<li>Copy over your <code>.git</code> folder into the new project.</li>
<li>
Download the signing key of your Android app from Expo using
<code>exp fetch:android:keystore</code> and set it up
</li>
<li>Build and test your app</li>
</ul>
<p>
This reduces the size to around 7.5 MB, thin but we can go thinner.
</p>
</section>
<section>
<h3>Reducing size of React Native App (Android)</h3>
<p>This is what you have been waiting for, I know.</p>
<ul>
<li>Open up <code>android/app/build.gradle</code></li>
<li>
Set <code>def enableProguardInReleaseBuilds = true</code> this would
enable Progaurd to compress the Java Bytecode. This reduces the app
size by a tad bit
</li>
<li>
Set <code>def enableSeparateBuildPerCPUArchitecture = true</code> .
Android devices support two major device artitectures armebi and
x86. By default RN builds the native librariers for both these
artitectures into the same apk.
</li>
</ul>
<p>
Setting the last function creates two distinct apk in the build
folder. You have to upload both of this apk to Play Store and Google
would take care of distributing the app to the correct architectures.
</p>
<p>
Using this split generates version numbers for both apks in the order
of 104856 and such. This is auto-generated by the build to avoid
version conflicts, so don’t freak out (I did).
</p>
<p>
This split reduced the apk size from around 7MB to 3.5MB for arm and
5MB for x86 respectively.
</p>
</section>
<section>
<h2>Conclusion</h2>
<p>
So that’s how you lose weight. Reducing the size of your app has many
added benefits, the best being more users will be willing to download
your app.
</p>
<p>
Be sure to check out
<a href="https://www.producthunt.com/posts/tet"
>https://www.producthunt.com/posts/tet</a
>
if you feel like seeing slim stuff.
</p>
</section>
</article>
</body>
</html>