<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Aqeeb Imtiaz Harun</title>
    <description>The latest articles on Forem by Aqeeb Imtiaz Harun (@aqeebimtiaz).</description>
    <link>https://forem.com/aqeebimtiaz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F258826%2F06c7b230-20e0-4e44-8bc2-417b53f4f8b2.jpeg</url>
      <title>Forem: Aqeeb Imtiaz Harun</title>
      <link>https://forem.com/aqeebimtiaz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/aqeebimtiaz"/>
    <language>en</language>
    <item>
      <title>React Native Installation</title>
      <dc:creator>Aqeeb Imtiaz Harun</dc:creator>
      <pubDate>Sun, 05 Jan 2020 06:24:49 +0000</pubDate>
      <link>https://forem.com/aqeebimtiaz/react-native-installation-lh1</link>
      <guid>https://forem.com/aqeebimtiaz/react-native-installation-lh1</guid>
      <description>&lt;p&gt;The purpose of this guide is to demonstrate how to install &amp;amp; setup React Native in Ubuntu 18.04.&lt;br&gt;
This article was partly inspired by &lt;a href="https://medium.com/dooboolab/running-react-native-app-in-ubuntu-18-04-7d1db4ac7518"&gt;this&lt;/a&gt; tutorial:&lt;/p&gt;

&lt;h2&gt;
  
  
  Install instructions:
&lt;/h2&gt;

&lt;p&gt;Install Node.js:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install nodejs
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;
  
  
  Install &lt;strong&gt;nvm&lt;/strong&gt;
&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get update
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Install** c++ compiler*&lt;em&gt;.&lt;/em&gt; It may already exists, but just in case.*&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apt-get install build-essential libssl-dev
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Install nvm&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Reload bash&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;After installation close and reopen terminal and check nvm version&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;nvm --version&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Install &lt;strong&gt;node&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Install latest node&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nvm install node
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Set default node version for nvm&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nvm alias default node
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Check version of node and npm&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node -v
npm -v
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  Install Android Studio
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Install Java
&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install openjdk-8-jre openjdk-8-jdk
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;
  
  
  Install android studio
&lt;/h4&gt;

&lt;p&gt;In ubuntu 18.04, snap command is provided which is &lt;br&gt;
containerised software packages that are simple to create and &lt;br&gt;
install on all linux distributions.&lt;br&gt;
&lt;a href="https://snapcraft.io/"&gt;https://snapcraft.io/&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo snap install android-studio --classic 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;While installing Android Studio use  Classic Snap version&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;--classic 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Configure build path in your &lt;em&gt;.bash_profile&lt;/em&gt; or &lt;em&gt;.zshrc&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/emulator
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now check whether the paths were exported using: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;echo $PATH&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Set alias to shorten command to run emulator&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;alias run-emu="$ANDROID_HOME/tools/emulator @pixel2"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Reload &lt;em&gt;bash_profile&lt;/em&gt; or &lt;em&gt;.zshrc&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;source ~/.bash_profile&lt;/code&gt; or &lt;code&gt;source ~/.zshrc&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Generate emulator &amp;amp; run emulator
&lt;/h4&gt;

&lt;p&gt;Note:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In order to make &lt;code&gt;avdmanager&lt;/code&gt; command to work, you should
start android-studio and complete installation first.&lt;/li&gt;
&lt;li&gt;Also system-images should be installed Type below command to 
install the system image.
&amp;gt;   sdkmanager --install "system-images;android-27;google_apis;x86"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Create &lt;code&gt;avd&lt;/code&gt; device&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;avdmanager create avd -n device1 -k "system-images;android-27;google_apis_playstore;x86" --device 'Nexus 5X
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;List emulators. You will see device1 as a result.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;emu -avd -list-avds
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Run emulator&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;emu -avd device1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Install react-native
&lt;/h2&gt;

&lt;p&gt;Install &lt;code&gt;react-native-cli&lt;/code&gt; using npm.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g react-native-cli
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Create &lt;code&gt;react-native&lt;/code&gt; project via &lt;code&gt;react-native-cli&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;react-native init NewProject
cd NewProject
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;
  
  
  Install Dependencies:
&lt;/h4&gt;

&lt;p&gt;To install all node module dependencies, run:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  Start Server
&lt;/h3&gt;

&lt;p&gt;Navigate to project root folder &amp;amp; run: &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;To clear cache &amp;amp; run server:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;npm start -c&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Run React Native app on emulator/local device:
&lt;/h2&gt;

&lt;p&gt;According to &lt;a href="https://facebook.github.io/react-native/docs/running-on-device"&gt;official documentation&lt;/a&gt; , after starting the local server, run:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;react-native run-android
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;To run the app on a specific device:&lt;/strong&gt;&lt;br&gt;
Firstly, Find the device or emulator connected to PC&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;adb devices

List of devices attached
$device_name    device
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Then, run the app specifically to that device&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;react-native run-android --deviceId=$device_name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Generate Debug APK
&lt;/h2&gt;

&lt;p&gt;To generate a debug apk of the app execute the following commands.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
cd android
./gradlew assembleDebug
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;You'll find the generated APK as &lt;code&gt;app-debug.apk&lt;/code&gt; in &lt;code&gt;{project_root}/android/app/build/outputs/apk/debug&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  ==  Common Errors:  ==
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Trouble shooting with permission (Mostly seen on Android Studio): &lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install qemu-kvm
sudo adduser &amp;lt;your_username&amp;gt; kvm
sudo chown &amp;lt;your_username&amp;gt; /dev/kvm
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If we face the following error:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IBfHCQir--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.lensdump.com/i/iUIHqx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IBfHCQir--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.lensdump.com/i/iUIHqx.png" alt=""&gt;&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf &amp;amp;&amp;amp; sudo sysctl -p&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you face that one or more modules are missing, re-run&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;npm install&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you face something like the following when running the app on device:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Oh7902eH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.lensdump.com/i/inCY9Z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Oh7902eH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.lensdump.com/i/inCY9Z.png" alt=""&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Simply, navigate to &lt;strong&gt;&lt;em&gt;root_folder/android/app/src/main/res&lt;/em&gt;&lt;/strong&gt; and delete the &lt;strong&gt;&lt;em&gt;raw&lt;/em&gt;&lt;/strong&gt; folder and all the &lt;strong&gt;&lt;em&gt;drawable-&lt;/em&gt;&lt;/strong&gt;* folders &lt;br&gt;
Then try to re-run the app again.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you face static image files missing in your bundled application, simply run this command:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then run the following command to compile your app to APK file.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cd android &amp;amp;&amp;amp; ./gradlew clean assembleDebug&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;When generating debug APK, if you face this error: &lt;code&gt;error EISDIR: illegal operation on a directory, open 'android'&lt;/code&gt;, kindly follow &lt;a href="https://medium.com/@adityasingh_32512/solved-unable-to-load-script-from-assets-index-android-bundle-bdc5e3a3d5ff"&gt;this amazing article&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>reactnative</category>
      <category>ubuntu</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
