<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Rishi's Blog]]></title><description><![CDATA[I am a Software Development Engineer by profession. I build beautiful and useful boxes for all your screens - Web, Mobile, and Desktop. 💛]]></description><link>https://blog.rishikc.com</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 10:50:13 GMT</lastBuildDate><atom:link href="https://blog.rishikc.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Automate lighthouse audits for your Progressive Web App]]></title><description><![CDATA[We all know how valuable and helpful the insights are from lighthouse audits when we’re developing our web applications. But the way most of us check is manually through Chrome dev tools or the lighthouse extension, which in my opinion, is not very p...]]></description><link>https://blog.rishikc.com/automate-lighthouse-audits-for-your-progressive-web-app</link><guid isPermaLink="true">https://blog.rishikc.com/automate-lighthouse-audits-for-your-progressive-web-app</guid><dc:creator><![CDATA[Rishi Kumar Chawda]]></dc:creator><pubDate>Fri, 28 Jun 2019 22:30:50 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1598050041357/M6rJLfkq4.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>We all know how valuable and helpful the insights are from lighthouse audits when we’re developing our web applications. But the way most of us check is manually through Chrome dev tools or the lighthouse extension, which in my opinion, is not very productive.</p>
<p>For those of us who don’t know, there are mainly four ways of auditing our web application with lighthouse :</p>
<ul>
<li><p>via Chrome dev tools</p>
</li>
<li><p>Command-line</p>
</li>
<li><p>NPM module
( which we are going to use in a while )</p>
</li>
<li><p><a target="_blank" href="https://developers.google.com/speed/pagespeed/insights/">PageSpeed Insights</a></p>
</li>
</ul>
<p>To programmatically perform lighthouse audits, we can use the <a target="_blank" href="https://www.npmjs.com/package/lighthouse">lighthouse npm package</a>, <a target="_blank" href="https://mochajs.org/">mocha</a>, and <a target="_blank" href="https://www.chaijs.com">chai</a> for writing our tests and <a target="_blank" href="https://www.npmjs.com/package/chrome-launcher">chrome-launcher</a> for running our lighthouse tests.</p>
<p>First, let's install the above packages as dev dependencies in our project :</p>
<pre><code class="lang-bash">npm install lighthouse chrome-launcher chai mocha --save-dev
</code></pre>
<p>Now, let’s create a file named <code>lighthouse.tests.js</code> in our <code>tests</code> directory. We’ll run our lighthouse audits through this file. Here, we’ll import the lighthouse module and chrome launcher that helps us to open our webpage from the local development server and run the audits to test against a minimum threshold that we want our lighthouse scores to be.</p>
<p>While this might sound a lot to do, it isn’t much. Here’s what it looks like on actual code :</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> lighthouse = <span class="hljs-built_in">require</span>(<span class="hljs-string">"lighthouse"</span>);
<span class="hljs-keyword">const</span> chromeLauncher = <span class="hljs-built_in">require</span>(<span class="hljs-string">"chrome-launcher"</span>);

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">launchChromeAndRunLighthouse</span>(<span class="hljs-params">url, opts, conf = null</span>) </span>{
  <span class="hljs-keyword">return</span> chromeLauncher
    .launch({ <span class="hljs-attr">chromeFlags</span>: opts.chromeFlags })
    .then(<span class="hljs-function"><span class="hljs-params">chrome</span> =&gt;</span> {
      opts.port = chrome.port;
      <span class="hljs-keyword">return</span> lighthouse(url, opts, conf).then(<span class="hljs-function"><span class="hljs-params">res</span> =&gt;</span>
        chrome.kill().then(<span class="hljs-function">() =&gt;</span> res.lhr)
      );
    });
}
</code></pre>
<p>And it is as simple as that. We launch the chrome browser instance with the <code>chromeLauncher.launch</code> method and then run lighthouse tests with the site URL and configuration for our audits. After that, we close/kill the chrome instance and return the results. And this is how it looks like when in use :</p>
<pre><code class="lang-js">launchChromeAndRunLighthouse(testUrl, opts, config).then(<span class="hljs-function"><span class="hljs-params">res</span> =&gt;</span> {
  <span class="hljs-comment">// Results are available in `res`</span>
});
</code></pre>
<p>So now, we can put this call inside our <code>before</code> hook for the tests and then have tests for each metric, something like this :</p>
<pre><code class="lang-js">describe(<span class="hljs-string">"Lighthouse Audits"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-comment">// Timeout doesn't need to be same. It can be more or less depending on your project.</span>
  <span class="hljs-built_in">this</span>.timeout(<span class="hljs-number">50000</span>);
  <span class="hljs-keyword">let</span> results;
  before(<span class="hljs-string">"run test"</span>, <span class="hljs-function"><span class="hljs-params">done</span> =&gt;</span> {
    launchChromeAndRunLighthouse(testUrl, opts, config).then(<span class="hljs-function"><span class="hljs-params">res</span> =&gt;</span> {
      <span class="hljs-comment">// Extract the results you need for your assertions.</span>
      done();
    });
  });
  it(<span class="hljs-string">"performance test"</span>, <span class="hljs-function"><span class="hljs-params">done</span> =&gt;</span> {
    <span class="hljs-comment">// test your performance score against the threshold</span>
    done();
  });
  <span class="hljs-comment">// Some more tests..</span>
});
</code></pre>
<p>Still looks weird? Don’t worry! Check out this repository for an example setup of <a target="_blank" href="https://github.com/rishichawda/lighthouse-mocha-example">lighthouse tests with mocha</a> and try that out with your web application!</p>
<p>This method can be applied to automate the tests in continuous integration/deployment environments so that you don’t have to worry about manually auditing your web application and checking whether it meets the minimum satisfactory levels.</p>
<p>So there you go. That’s all we need to do for automating lighthouse audits for our progressive web applications to make sure they are always worthy of the internet and user’s data packets!</p>
<p><img src="https://i.imgur.com/bTB3UGn.gif" alt="worthy" /></p>
<p><br /></p>
<p><em>Did you like this article? Or did I miss something? Is there something that you have that can make it even better?</em>
<em>Please leave a comment below, or you can also contact me through my <a target="_blank" href="/">social media profiles</a>.</em></p>
<p><em>Thank you for reading!</em> 😄</p>
<p><br /></p>
<p>Happy hacking! Cheers! 🎉</p>
<hr />]]></content:encoded></item><item><title><![CDATA[Architecting React Applications - What I learned from my experience as a Web developer]]></title><description><![CDATA[React has always been popular for its short learning curve and easy to use APIs. But if you have been working with this popular javascript library for a while now, you might agree with me on this one as well -- If you don't pay attention to its struc...]]></description><link>https://blog.rishikc.com/architecting-react-applications-what-i-learned-from-my-experience-as-a-web-developer</link><guid isPermaLink="true">https://blog.rishikc.com/architecting-react-applications-what-i-learned-from-my-experience-as-a-web-developer</guid><category><![CDATA[React]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[architecture]]></category><dc:creator><![CDATA[Rishi Kumar Chawda]]></dc:creator><pubDate>Wed, 10 Apr 2019 22:48:50 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1598096291914/fE5FLfEev.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>React has always been popular for its short learning curve and easy to use APIs. But if you have been working with this <a target="_blank" href="https://reactjs.org/">popular javascript library</a> for a while now, you might agree with me on this one as well -- If you don't pay attention to its structure it will soon become an unmaintainable mess.</p>
<p>Before joining my first job, I had some experience as a freelancer but didn't know much about best practices and architecture apart from what I had come across either online or while development. And even as a freelancer, I didn't have experience with such large scale applications that we had to work with later in the job. This is when I started paying more attention to architecture. At the start, things used to get a little confusing sometimes - mostly because I was a bit more conscious about my code than before - which was obvious as I was part of a team now and not a solo freelancer.</p>
<p>So I started looking through GitHub, online articles, papers, and books. And as I kept working with React more and more on a large scale I had realized that</p>
<blockquote>
<p>The key to a robust, scalable, and easy to maintain React application is architecture.</p>
</blockquote>
<p>This applies to any application or software but with React, abstraction was a bit more difficult than other libraries/frameworks. This was until <a target="_blank" href="https://reactjs.org/docs/hooks-intro.html">Hooks were introduced</a> - but we will keep it out of the context for now as it is still fairly new and most of the applications are still built with older versions of React. Also, there are a lot of improvements to be made; a lot of do's and don'ts to be discovered with its usage.</p>
<p>As of now, I think the principle that I follow for structuring React applications will work fairly well with Hooks too! Since the focus was on a scalable web application architecture - not just React.</p>
<p><br /></p>
<p>Let's quickly take a look at the setup and then I'll walk you through it and try to explain why it is structured that way. So the root of the project looks something like this :</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1598096012072/xlmZ1IMTQ.png" alt="base structure one" /></p>
<p>And the <code>src</code> directory ( which will contain all the source code for our application, of course ) is structured like this :</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1598096034595/ud8ko-3yE.png" alt="base structure two" /></p>
<p>The first thing you might notice and wonder maybe - and if you don't, I'd recommend taking a look again - that we have two directories named <code>config</code> in our project. No, this isn't by mistake! It has an ( extremely ) simple reason.</p>
<p><br /></p>
<h2 id="heading-two-config-directories-for-a-single-web-application-why-though">Two config directories for a single web application?! Why though??</h2>
<p>The <code>config</code> directory at the root contains all the configuration files related to build - like our application's webpack config or any other bundler that we might use environment files, and other configs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1598096046858/ctvfAObcn.png" alt="config directory snapshot" /></p>
<p>You might also notice that it is nested and that the webpack configuration lives in its own directory. This makes the configurations more organized and easier to manage. This might seem trivial but when the application starts growing, and with that the build process might also get complex - which then demands a well-organized place of its own. Also, this brings peace of mind while working with it -- a large mess of configuration files is the last thing you might want while deploying your application in production! 👀</p>
<p><br /></p>
<p>The other <code>config</code> directory inside our <code>src</code> folder is for configurations related to our application, .i.e, the ones related to runtime. This may contain our JSON files ( or any other files ) that might shape the behavior or capabilities of our app. Although this may or may not be required as per your needs but for me, I have had this folder in most of the projects.</p>
<p><br /></p>
<h2 id="heading-but-wait-what-about-the-resources-and-assets-directories-arent-assets-also-a-part-of-the-resources-for-our-react-application">But wait, what about the <code>resources</code> and <code>assets</code> directories? Aren't assets also a part of the 'resources' for our react application?</h2>
<p><br /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1598096086129/PhfFHmnwo.jpeg" alt="good question" /></p>
<p>Well, the <code>assets</code> directory here is meant <strong><em>only</em></strong> for images and other media <em>, duhh,</em></p>
<p>whereas, <code>resources</code> is for data that might be required by our web application, for example, constants and other static data which basically doesn't have any or much logic associated with it. You can also add small methods to return the data, perhaps formatted to specific needs, and/or perform <strong><em>minor</em></strong> operations on them there which can be used by parts of our application, which by the way -- <em>trust me</em> -- will make your code a lot cleaner and more organized.</p>
<p>This directory may also contain data and other 'resources' which can be occasionally fetched, stored and updated; and maybe processed a little before they are used in certain parts of our web application. Well, I guess you get the idea.</p>
<p><br /></p>
<h2 id="heading-and-what-about-our-pages-and-all-the-react-components">And what about our pages and all the react components??</h2>
<p>So, here comes the interesting part. At least I think so. This is something that has been derived from a few other solutions on architecting react applications as well as other web applications along with some of my own practical experience. And by far, I'm pretty satisfied with it! 🤓</p>
<p>To start with, let's assume our web application contains a home page, a profile page for the users, and just for the sake of not having just two pages in the example, a third page that we will call -- the other page. So the directory structure would look something like this :</p>
<pre><code class="lang-js">-- src
----- components
----- config
----- pages
--------- home
----------- index.js
----------- index.scss          <span class="hljs-comment">// Mandatory sass file - I just wanted to make this look realistic!!</span>
--------- profile
----------- index.js
--------- other-page
----------- components
----------- index.js
----- resources
</code></pre>
<p>Notice how all the pages have their own separate directory with an entry point? And how that 'other' page has a component folder? Why do we need another component folder? Don't we already have a component folder in the root of <code>src</code> directory?</p>
<p>Wait, just hold on for a second! I'll explain it real quick! ☝</p>
<p>This is what I call the "branching" structure. Each page has their own directory, their own set of components which are not used anywhere else except in that specific page, their own styles rules and other stuff which are associated with only that page. If any component is shared by two pages, guess where they'd go? Yes, you guessed it right -- the <code>components</code> directory in the root of our <code>src</code> directory!</p>
<p>But.. you might wonder.. what is the point of doing that?</p>
<p>Let's say, one day you and your teammates decide to get rid of the 'other' page -- <em>maybe the name wasn't good enough?</em> -- so what do you do? Spend an entire afternoon or a day on removing code, breaking, and fixing the application? <strong>NO</strong>.</p>
<p>You just go ahead and delete the directory and remove its reference from where it was attached to / used in the web application. <em>And voila, it's done!</em> 💁🏻‍♂️</p>
<p>Nothing breaks in your app just because a bunch of code was deleted! Everything is independent of each other's existence even if they were bound together at some point! A lot less to work with and worry about, isn't it? And yeah, this principle can be applied to almost any application/software and not just some react application.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1598096108606/-x2boiMqe.jpeg" alt="welcome" /></p>
<p>Some of you might think -- Well no, our application/software is quite complex and stuff is just too interconnected with each other. They <strong><em>shared</em></strong> code, were <strong><em>bridged</em></strong> together, etc. But I guess you might understand now what to do with the "shared code" and "bridges" if you try to apply this principle to it! This is just a simple example to demonstrate and give you an idea of how parts of the product can be organized for convenience and maintainability.</p>
<p> <br /></p>
<h2 id="heading-a-little-tip-something-that-i-learned-while-developing-progressive-web-applications-with-gatsbyjs">A little tip -- something that I learned while developing progressive web applications with GatsbyJS</h2>
<p>You can also go ahead and add another directory to the <code>src</code> -- called <code>layouts</code> ( or maybe add it to the <code>components</code> directory, whichever feels more appropriate to you ) which contains a layout file which is global to the application or even has multiple layouts; each associated with certain parts of the application. For example, let's assume our application also has a fancy navbar and a decent footer that goes into all of our pages. Instead of having them shoved inside our <code>components</code> directory and then repeatedly used inside each page - we can have a layout file that contains the navbar and the footer and renders the <code>children</code> that are passed to it, like so :</p>
<pre><code class="lang-jsx">
&lt;Layout&gt;
 <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
   Yayy! This is my fancy home page!!
 <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/Layout&gt;

<span class="hljs-comment">// And in the profile page :</span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Layout</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
   This is the page of the user whose data we're secretly trying to steal!
   Please read our privacy policies (not so) carefully!!
 <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">Layout</span>&gt;</span></span>
</code></pre>
<p>And in our Layout file, we can have something similar to this :</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">const</span> Layout = <span class="hljs-function">(<span class="hljs-params">{ children }</span>) =&gt;</span> (
  <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">Navbar</span> /&gt;</span>
    {children}
    <span class="hljs-tag">&lt;<span class="hljs-name">Footer</span> /&gt;</span>
  <span class="hljs-tag">&lt;/&gt;</span></span>
);

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Layout;
</code></pre>
<p>Better now, isn't it? Even this website, with its simplicity, has a layout component! 🤓</p>
<p><br /></p>
<h2 id="heading-but-wait-theres-more-to-architecting-react-applications">But wait. There's more to architecting react applications!!</h2>
<p>Yes, I haven't forgotten about reducers, the lengthy sagas, services, a ton of action creators, and what not! But that's for the <a target="_blank" href="/articles/architecting-react-applications-redux-store-services-and-sagas/">second part of this article</a> since I don't want it to become too long and exhausting to read. Also, this first part might serve as a good starting point for beginners or other fellow developers who are new to React development.</p>
<p><br /></p>
<p><em>Did you like this article? Or did I miss something? Is there something that you have that can be added to this article -- that can make it even better?</em></p>
<p><em>Please leave a comment below or you can also contact me through my <a target="_blank" href="/">social media profiles</a>.</em></p>
<p><em>Thank you for reading!</em> 😄</p>
<p><br /></p>
<p>Happy hacking! Cheers! 🎉</p>
<hr />]]></content:encoded></item><item><title><![CDATA[How to Install, Setup and Use Android Emulator for Mac, Linux and Windows without installing Studio]]></title><description><![CDATA[So let me ask you first —
How many of you have installed Android Studio only to use the emulator for your native app? Oh, and don’t forget the way your system struggles when you try to run it!

And no, I’m not just talking about any average system — ...]]></description><link>https://blog.rishikc.com/how-to-install-setup-and-use-android-emulator-for-mac-linux-and-windows-without-installing-studio</link><guid isPermaLink="true">https://blog.rishikc.com/how-to-install-setup-and-use-android-emulator-for-mac-linux-and-windows-without-installing-studio</guid><category><![CDATA[React Native]]></category><category><![CDATA[Android]]></category><category><![CDATA[Android Studio]]></category><category><![CDATA[Mobile Development]]></category><dc:creator><![CDATA[Rishi Kumar Chawda]]></dc:creator><pubDate>Fri, 11 Jan 2019 21:55:07 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1598047348811/dz2RzoOJ2.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>So let me ask you first —</p>
<p>How many of you have installed Android Studio only to use the emulator for your native app? Oh, and don’t forget the way your system struggles when you try to run it!</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1598047288639/lHm6U_TcO.jpeg" alt="image1.jpg" /></p>
<p>And no, I’m not just talking about any average system — even my Macbook Pro with 8GB of RAM makes a lot of noise!</p>
<p>A lot of you might have also come across alternatives like Genymotion, Nox, BlueStacks, and a lot of others. Some are free, while a lot of others with really nice features and performance are paid.</p>
<p>So most of us stick to the free ones or end up downloading Android Studio for the excellent and easy to use emulator it provides.</p>
<p>But it gets worse when you already have Visual Studio Code, a few tabs on Google Chrome, and your music player running!</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1598047321592/SMreacXBb.png" alt="image2.png" /></p>
<p>Also, some of us are just lazy ( and too comfortable with the command line ) that we don't bother installing some fancy GUI application when we can do it with a few commands. 🤓</p>
<p>Okay, enough with the memes, let’s quickly set up Android Studio’s emulator for our react native app in a better way this time — without actually installing Android Studio! ✊</p>
<hr />

<h3 id="heading-step-1-install-java-development-kit-8">Step 1: Install Java Development Kit 8.</h3>
<p>First, you’ll need to install <a target="_blank" href="https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html">JDK 8</a>. Windows and Linux users can directly visit the link and download it after accepting the license.
For Mac users, I recommend installing via <a target="_blank" href="https://brew.sh/">Homebrew</a> :</p>
<pre><code class="lang-bash">brew tap caskroom/versions
brew cask install java8
</code></pre>
<p>Windows and Linux users should make sure that they have set up a path to their Java installation.</p>
<hr />

<h3 id="heading-step-2-install-the-android-sdk">Step 2: Install the Android SDK.</h3>
<p>Once we have installed and set-up Java in our system, we will need to install Android SDK so that we can get the necessary tools in our systems, including the android virtual device manager and the emulator itself!</p>
<p>Windows and Linux users can directly <a target="_blank" href="https://developer.android.com/studio/#downloads">download the command line tools</a> required for installing the android emulator.</p>
<p>Mac users can install it by running:</p>
<pre><code class="lang-bash">brew cask install android-sdk
</code></pre>
<p><strong>Note for Mac users:</strong> If you run into an error like this while installing android SDK :</p>
<pre><code class="lang-bash">Exception <span class="hljs-keyword">in</span> thread <span class="hljs-string">"main"</span> java.lang.NoClassDefFoundError: javax/xml/<span class="hljs-built_in">bind</span>/annotation/XmlSchema
at com.android.repository.api.SchemaModule<span class="hljs-variable">$SchemaModuleVersion</span>.&lt;init&gt;(SchemaModule.java:156)
at com.android.repository.api.SchemaModule.&lt;init&gt;(SchemaModule.java:75)
at com.android.sdklib.repository.AndroidSdkHandler.&lt;clinit&gt;(AndroidSdkHandler.java:81)
at com.android.sdklib.tool.SdkManagerCli.main (SdkManagerCli.java:117)
</code></pre>
<p>Then you simply need to run the below command and try installing android-sdk again :</p>
<pre><code class="lang-bash">touch ~/.android/repositories.cfg
</code></pre>
<p>After installing, make sure you have added <code>android-sdk</code> to your system path.</p>
<p>For Mac and Linux users, you need to add the following line to your <code>.bashrc</code> or <code>.zshrc</code> :</p>
<pre><code class="lang-bash"><span class="hljs-built_in">export</span> ANDROID_HOME=/path/to/android-sdk
</code></pre>
<hr />

<h4 id="heading-important-note-for-the-next-two-steps">Important note for the next two steps:</h4>
<p><em>Incase your system complains about not being able to find the command while trying to issue the next set of commands involving <strong>sdkmanager</strong> , <strong>avdmanager</strong> or <strong>emulator</strong> — you can navigate to the directory where it is present inside the android-sdk folder and run them as <strong>./sdkmanager</strong>, <strong>./avdmanager</strong> and <strong>./emulator</strong> respectively.</em></p>
<p><em>For those of you who are feeling lazy to find it yourself:</em></p>
<p><em><strong>sdkmanager</strong> and <strong>avdmanager</strong> will be located inside <strong>android-sdk/tools/bin</strong> whereas <strong>emulator</strong> can be found inside <strong>android-sdk/tools</strong>.</em></p>
<p>Now that we know this let’s continue towards a better development experience!</p>
<hr />

<h3 id="heading-step-3-install-platform-and-build-tools-required-for-react-native">Step 3: Install platform and build tools required for React Native.</h3>
<p>Now we can go ahead and set up platform and build tools to help us in creating and running our virtual device in an android emulator. We will use the <code>sdkmanager</code> that we just downloaded to our system as a part of <code>android-sdk</code>.</p>
<p>To do this, open your terminal and run the following command :</p>
<pre><code class="lang-bash">sdkmanager <span class="hljs-string">"platforms;android-23"</span> <span class="hljs-string">"build-tools;23.0.1"</span> <span class="hljs-string">"add-ons;addon-google_apis-google-23"</span>
</code></pre>
<p>Once we have downloaded the above packages, run the following command to list all the tools available :</p>
<pre><code class="lang-bash">sdkmanager --list
</code></pre>
<p>This command will fetch the complete list of the available packages on remote that you can download to your system. You can download packages from the list by running :</p>
<pre><code class="lang-bash">sdkmanager <span class="hljs-string">"sdk-path-for-package"</span>
</code></pre>
<p><em><strong>Note:</strong> sdk-path is the string in the leftmost column of the generated list. And it must be wrapped in quotes while running the above command. For example, let’s say we want to create a virtual device which requires <strong>Google APIs Intel x86 Atom System Image</strong> package, we can install the package by running:</em></p>
<pre><code class="lang-bash">sdkmanager <span class="hljs-string">"system-images;android-23;google_apis;x86"</span>
</code></pre>
<p>You can download the packages that you need from the list, and if you look closely, you’ll find the android emulator package there too! But don’t worry I won’t make you go through the long list in your terminal, here’s the command you need to run to download the android emulator package :</p>
<pre><code class="lang-bash">sdkmanager <span class="hljs-string">"emulator"</span>
</code></pre>
<p>That’s it! We’ve downloaded the android emulator, and we’re ready to set-up our Android virtual device!</p>
<hr />

<h3 id="heading-step-4-create-a-new-virtual-device">Step 4: Create a new virtual device.</h3>
<p>Let’s create an android virtual device with the help of <strong><em>Google APIs Intel x86 Atom System Image</em></strong> we downloaded through the previous command, which was :</p>
<pre><code class="lang-bash">sdkmanager <span class="hljs-string">"system-images;android-23;google_apis;x86"</span>
</code></pre>
<p>Now to create a virtual device, run the following command :</p>
<pre><code class="lang-bash">avdmanager create avd --force --name myTestDevice --abi google_apis/x86 --package <span class="hljs-string">'system-images;android-23;google_apis;x86'</span> --device <span class="hljs-string">"myTestDevice"</span>
</code></pre>
<p>This command will create a virtual device named <em>myTestDevice</em> using the <em>Intel x86 Atom system image</em> we downloaded.</p>
<p>To check if your device was created, you can run :</p>
<pre><code class="lang-bash">emulator -list-avds
</code></pre>
<p>This will list all the virtual devices present in your system.</p>
<hr />

<p>If you followed all the instructions correctly, you could see your device listed as well, and you must be able to start your virtual device by running :</p>
<pre><code class="lang-bash">emulator -avd myTestDevice
</code></pre>
<p>And now, your android emulator will start with the device you just created! But this time in a better way just like you always deserved — without wasting your precious storage space! 🎉</p>
<p><br /></p>
<p><em>Did you like this article? Or did I miss something? Is there something that you have that can be added to this article -- that can make it even better?</em></p>
<p><em>Please leave a comment below, or you can also contact me through my <a target="_blank" href="/">social media profiles</a>.</em></p>
<p><em>Thank you for reading!</em> 😄</p>
<p><br /></p>
<p>Happy Hacking! Cheers!</p>
<hr />]]></content:encoded></item><item><title><![CDATA[Shrink your React Native application size dramatically!]]></title><description><![CDATA[So you made a cool and awesome looking React Native app, and now you’re ready to build it and maybe publish it to the store —
But worried about it if the users would want to install it given its build size? Or maybe you just want to keep it lightweig...]]></description><link>https://blog.rishikc.com/shrink-your-react-native-application-size-dramatically</link><guid isPermaLink="true">https://blog.rishikc.com/shrink-your-react-native-application-size-dramatically</guid><category><![CDATA[React Native]]></category><category><![CDATA[Android]]></category><category><![CDATA[Mobile Development]]></category><dc:creator><![CDATA[Rishi Kumar Chawda]]></dc:creator><pubDate>Wed, 19 Sep 2018 21:14:54 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1598046621565/JVPnvLUVu.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>So you made a cool and awesome looking <a target="_blank" href="https://facebook.github.io/react-native/">React Native</a> app, and now you’re ready to build it and maybe publish it to the store —</p>
<p>But worried about it if the users would want to install it given its build size? Or maybe you just want to keep it lightweight and not take too much memory unnecessarily when it can be packed into a smaller size?</p>
<p>Or you’re just one of us who are paranoid about build sizes? Don’t worry, we got you covered! 😄 ✔️</p>
<hr />
<p>In this article, we will cover the following two things:</p>
<ul>
<li><p>Compress the react native application size - by compressing the java bytecode that is generated while building our app and also asking it to try and shrink all the resources that are bundled with the application.</p>
</li>
<li><p>Splitting our application bundle into multiple APKs to remove unnecessary code which is not required by the device which is going to run it - because a lot of code is bundled with the universal APK that is device-specific - meaning that we don't need a lot of code in the device we're going to install it in.</p>
</li>
</ul>
<hr />
<p>Let's get started! ✊</p>
<p>First of all, you’ll need to eject your native app if you’re using <a target="_blank" href="https://github.com/react-community/create-react-native-app">create-react-native-app</a> for your project ( You might have already done this if you’ve built your application before reading this article ). This is important since you don’t have access to configurations until you eject, as the build folder is where we have to make changes. If you haven’t, you can simply do this by :</p>
<pre><code class="lang-bash">npm run eject
</code></pre>
<p><strong>Note :</strong> Ejecting a react native application is a permanent action! ( Unless you’re using a version control system to keep track of previous versions of your app — from where you can recover the ‘unejected’ version of your app later if you need ). <a target="_blank" href="https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md%22">Learn more about ejecting.</a></p>
<p>Okay, so now we’re all set! Let’s get started and get that done fast. Don’t worry, it just takes a few minutes, and your app size will shrink dramatically!</p>
<p>Now, navigate to the <code>android/app</code> folder from your project root directory where you can find your <code>build.gradle</code> file.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1598045966858/v_lV8XVx4.png" alt="post" /></p>
<p>Here, you’ll find your default build configurations already set up, find the line which looks like this :</p>
<pre><code class="lang-plaintext">def enableProguardInReleaseBuilds = false
def enableSeparateBuildPerCPUArchitecture = false
</code></pre>
<p>and change their value to <code>true</code> like this :</p>
<pre><code class="lang-plaintext">def enableProguardInReleaseBuilds = true
def enableSeparateBuildPerCPUArchitecture = true
</code></pre>
<p>So you might be wondering what it does. Well, if you scroll down a bit you’ll see <code>enableProguardInReleaseBuilds</code> and <code>enableSeparateBuildPerCPUArchitecture</code> written at a few more places like here:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1598045991053/9pFDW9qPz.png" alt="post" /></p>
<p>As you can see, these variables are being used to enable or disable two build configurations —</p>
<ul>
<li>One for generating separate .apks for different device architectures,</li>
</ul>
<pre><code class="lang-plaintext">...
splits {
 abi {
 reset()
 enable enableSeparateBuildPerCPUArchitecture
...
</code></pre>
<p><em>Don't worry about having to handle different .apks for each architecture — Google takes care of distributing it to the users! And separating the builds according to architecture removes unnecessary code from your file which is not required on the device it is running.</em></p>
<ul>
<li>Another one for compressing the Java bytecode generated while building, as in,</li>
</ul>
<pre><code class="lang-plaintext">...
buildTypes {
 release {
 minifyEnabled enableProguardInReleaseBuilds
...
</code></pre>
<p>Phew, that was pretty easy! But wait, we’re not done yet! There’s one little thing we need to do.</p>
<p>Now let’s add this line right below the <code>minifyEnabled</code> configuration :</p>
<pre><code class="lang-plaintext">...
buildTypes {
 release {
 minifyEnabled enableProguardInReleaseBuilds
 shrinkResources true; /* &lt;-- Add this line */
...
</code></pre>
<p>And we’re done! Now build your app again and check the <code>output</code> directory. You’ll find two different APKs of your app, which is specified in the configuration by default, i.e., for <code>armebi</code> and <code>x86</code> architectures.</p>
<p>Oh, and by the way, if you need a universal APK that supports all device architectures — just set <code>universalApk</code> to true, and it’ll generate a universal APK next time you run build!</p>
<p>That’s all! Now you’ve set up your build configuration to shrink your code along with resources and create separate APK for different architectures — thus removing unnecessary code from the final build.</p>
<p>Thanks for reading! You can check out more resources on <a target="_blank" href="https://developer.android.com/studio/build/shrink-code">how to reduce the application build size</a>.</p>
<p><em>Did you like this article? Or did I miss something? Is there something that you have that can be added to this article -- that can make it even better?</em></p>
<p><em>Please leave a comment below, or you can also contact me through my</em> <a target="_blank" href="/"><em>social media profiles</em></a><em>.</em></p>
<p><em>Thank you for reading!</em> 😄</p>
<p>Happy Hacking! Cheers!</p>
<hr />
]]></content:encoded></item></channel></rss>