<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sokserey PHON on Medium]]></title>
        <description><![CDATA[Stories by Sokserey PHON on Medium]]></description>
        <link>https://medium.com/@soksereyphon8?source=rss-f6699f52b47f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8R10B8gBukQo9MRpGb4Ylg@2x.jpeg</url>
            <title>Stories by Sokserey PHON on Medium</title>
            <link>https://medium.com/@soksereyphon8?source=rss-f6699f52b47f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 11:35:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@soksereyphon8/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Schedule Auto Backup Database With Crontab]]></title>
            <link>https://soksereyphon8.medium.com/schedule-auto-backup-database-with-crontab-97cae2c95739?source=rss-f6699f52b47f------2</link>
            <guid isPermaLink="false">https://medium.com/p/97cae2c95739</guid>
            <dc:creator><![CDATA[Sokserey PHON]]></dc:creator>
            <pubDate>Fri, 25 Nov 2022 02:47:08 GMT</pubDate>
            <atom:updated>2022-11-25T02:47:08.470Z</atom:updated>
            <content:encoded><![CDATA[<p>Backing up database is one of the most important part in real world applications. Imagine your system is running over a year and unfortunately you lost the database. It might be a nightmare!!!</p><blockquote>This article focuses on Postgresql and VPS. I assumed you already setup postgresql and VPS.</blockquote><ol><li><strong>SSH to VPS</strong></li></ol><pre>ssh youruser@yourip</pre><p>2. <strong>Make a tmp directory to store database backup</strong></p><pre>sudo mkdir tmp</pre><p>3. <strong>Create backup script in tmp directory</strong></p><pre>cd tmp/<br>sudo nano pg_backup_script.sh<br><br><br># in your pg_backup_script.sh<br><br>#!/bin/bash<br># This script will backup the postgresql database<br># and store it in a specified directory<br><br># Constants<br>BACKUP_DIRECTORY=&quot;/home/cb_dev/tmp&quot;<br><br># Date stamp (formated YYYYMMDD)<br>CURRENT_DATE=$(date &quot;+%Y%m%d&quot;)<br>DB_NAME=$DATABASE\_$CURRENT_DATE<br># Database named (command line argument) use pg_dump for targed backup<br><br>pg_dump -U dbUser dbName -h 127.0.0.1 | gzip - &gt; $BACKUP_DIRECTORY/$DB_NAME.dump.gz</pre><p>4. Make sure your script work</p><pre>cd tmp/<br>bash pg_backup_script.sh<br><br>// you can check in your tmp folder and you will see your backup file.</pre><p>5. <strong>Setup Crontab for scheduling backup</strong></p><pre>sudo apt install cron<br><br>sudo systemctl enable cron</pre><p>click <a href="https://www.digitalocean.com/community/tutorials/how-to-use-cron-to-automate-tasks-ubuntu-1804">here</a> for more details.</p><p>6. <strong>Edit Crontab</strong></p><pre>crontab -e</pre><p>It will ask you to choose your favourite editor</p><pre><br># Edit this file to introduce tasks to be run by cron.<br>#<br># Each task to run has to be defined through a single line<br># indicating with different fields when the task will be run<br># and what command to run for the task<br>#<br># To define the time you can provide concrete values for<br># minute (m), hour (h), day of month (dom), month (mon),<br># and day of week (dow) or use &#39;*&#39; in these fields (for &#39;any&#39;).<br>#<br># Notice that tasks will be started based on the cron&#39;s system<br># daemon&#39;s notion of time and timezones.<br>#<br># Output of the crontab jobs (including errors) is sent through<br># email to the user the crontab file belongs to (unless redirected).<br>#<br># For example, you can run a backup of all your user accounts<br># at 5 a.m every week with:<br># 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/<br>#<br># For more information see the manual pages of crontab(5) and cron(8)<br>#<br># m h  dom mon dow   command<br>0 0 * * * cd /home/YOURUSERNAME/tmp &amp;&amp; bash pg_backup_script.sh args</pre><p>0 0 * * * means it will backup your database every day at midnight.</p><p>I hope this will help.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97cae2c95739" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fastlane in Flutter App]]></title>
            <link>https://mobileappcircular.com/fastlane-in-flutter-app-c351358c64ba?source=rss-f6699f52b47f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c351358c64ba</guid>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[fastlane-match]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[fastlane]]></category>
            <category><![CDATA[fastlane-ios]]></category>
            <dc:creator><![CDATA[Sokserey PHON]]></dc:creator>
            <pubDate>Fri, 26 Nov 2021 10:02:08 GMT</pubDate>
            <atom:updated>2021-12-10T17:19:26.392Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/0*LfWYkGQ20vGBKjuN.png" /></figure><h3>What is Fastlane?</h3><p>Fastlane is an open source platform aimed at simplifying Android and iOS deployment. Fastlane lets you automate every aspect of your development and release workflow.</p><h3>Prerequisite</h3><p>Before getting started, I assumed you already had an apple developer and google developer account and registered your app in apple developer portal.</p><h3>Installation</h3><p>Make sure your ruby version is 2.7.3 or newer.</p><pre>ruby --version<br>output: ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [x86_64-darwin20]</pre><p>I recommend install fastlane through <strong>gem</strong></p><pre>gem install fastlane</pre><ul><li>Init fastlane for Android and iOS</li></ul><p>Go to /ios and /android directory. Then run the following command</p><pre>fastlane init</pre><p>By running the above command, you will see <em>fastlane </em>folder is generated in ios and android folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*E_-iUB1GJRohDJjIbin3ow.png" /></figure><h3>Fastlane for iOS</h3><h4><strong>1. Authentication</strong></h4><p>In order to authenticate your app and publish to app store, fastlane recommended AppStore Connect Api Key. <a href="https://docs.fastlane.tools/app-store-connect-api/"><em>Learn more</em></a></p><p><strong>Creating an App Store Connect API Key</strong></p><ol><li>go to: <a href="https://appstoreconnect.apple.com/access/api">AppStoreConnect</a></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WKKAq4s-xr0hiPoK3mmc8A.png" /></figure><p>2. Download the newly created API Key file (.p8). This file cannot be downloaded again after the page has been refreshed.</p><p>3. Create appConnectApiKey.json in fastlane folder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wdKMS_TIevhZDKo47-wfHg.png" /></figure><p><strong>key_id</strong>: your generated key id</p><p><strong>issuer_id</strong>: your issuer id, look at above image</p><p><strong>key</strong>: open your .p8 file and paste in your appConnectApiKey.json</p><blockquote>Please ignore appConnectApiKey.json from your repo.</blockquote><h4><strong>2. Cert and Sigh</strong></h4><p>cert and sigh is a part of fastlane: <strong>The easiest way to automate beta deployments and releases for your iOS and Android apps.</strong></p><pre>fastlane cert =&gt; create your certificate<br>fastlane sigh =&gt; create provisioning profiles.</pre><p>Let’s create cert_and_sigh lane to generate certificate and provisioning profile.</p><p>go to your <em>/ios </em>directory, there is a folder called fastlane. Then open FastFile and create the following lane.</p><pre>lane :cert_and_sigh do</pre><pre>cert(</pre><pre>username: &quot;your_username@gmail.com&quot;</pre><pre>team_name: &quot;YourTeamName&quot;</pre><pre>development: true</pre><pre>)</pre><pre>sigh(</pre><pre>username: &quot;your_username@gmail.com&quot;</pre><pre>team_name: &quot;YourTeamName&quot;</pre><pre>app_identifier: &quot;yourapp.com&quot;</pre><pre>development: true</pre><pre>)</pre><pre>end</pre><p>Then to execute this lane just simply run</p><pre>/ios<br>fastlane cert_and_sigh</pre><p>by running the above command. It will generate certificate and provisioning profile from your machine.</p><h4>3. Match</h4><p><strong>Match </strong>is used to match certificate and provisioning profile. Moreover, it helps you to work with your team.</p><blockquote>Before using <em>fastlane match, </em>please create a blank private repo to store all certificates and provisioning profiles.</blockquote><pre>/ios</pre><pre># add git url for storing certs and profile, generate match file<br>fastlane match init</pre><pre># generate dev certs and profiles and push to git<br>fastlane match development</pre><pre># generate production certs and profiles and push to git<br>fastlane match appstore</pre><blockquote>You will see all your certificates and provisioning profiles are store in your repo.</blockquote><h4>4. Publish to TestFlight</h4><p>go to your FastFile and follow the following codes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*S4DascW9mNP4NxzB4BV4Kw.png" /></figure><blockquote><strong>increment_version_number</strong> and <strong>increment_build_number</strong> here is just an example. You can replace it with yours.</blockquote><p>Now it is time to upload your app to TestFlight, just run</p><pre>fastlane release_app</pre><p>Fastlane will do the job for you and you can enjoy your coffee or beer 🍻.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c351358c64ba" width="1" height="1" alt=""><hr><p><a href="https://mobileappcircular.com/fastlane-in-flutter-app-c351358c64ba">Fastlane in Flutter App</a> was originally published in <a href="https://mobileappcircular.com/">Mobile App Circular</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Version Management]]></title>
            <link>https://soksereyphon8.medium.com/flutter-version-management-3c318c4ff97d?source=rss-f6699f52b47f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c318c4ff97d</guid>
            <category><![CDATA[fvm]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <dc:creator><![CDATA[Sokserey PHON]]></dc:creator>
            <pubDate>Tue, 27 Apr 2021 05:51:46 GMT</pubDate>
            <atom:updated>2021-04-27T08:12:25.764Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ihpzwH-gScI1PZlMOOIGdw.png" /></figure><p>Flutter version management or (FVM) is a tool to manage Flutter SDK Version on your machine. This means that we can define specific Flutter version for different projects.</p><p>This tool allows you to manage multiple channels and releases, and caches these versions locally, so you don’t have to wait for a full setup every time you want to switch versions.</p><h3>1. Install FVM on your machine</h3><ul><li>First make sure flutter is already installed. Moreover, it must be flutter stable channel. In your command line just simply type this:</li></ul><pre>// set flutter to stable channel<br>flutter channel stable</pre><pre>// check flutter channel<br>flutter channel</pre><pre>// output<br>Flutter channels:<br>  master<br>  dev<br>  beta<br>* stable</pre><ul><li>Once you have determined your flutter is already installed, Let install FVM by the following command:</li></ul><pre>flutter pub global activate fvm</pre><ul><li>There is a warning message at the end of the installation process. So the next step would be to add fvm path to our shell’s config file (.bashrc, bash_profile, etc.). In order for the fvm command to work, it is necessary that you have three following lines defined within the file:</li></ul><pre>export PATH=”$PATH:`pwd`/flutter/bin”<br>export PATH=”$PATH:`pwd`/bin/cache/dart-sdk/bin”<br>export PATH=”$PATH:`pwd`/.pub-cache/bin”</pre><ul><li>Type fvm in your command line to see all available options:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jTIGl-8GN1YyoE_zHgZ1cQ.png" /></figure><h3>2. Install Flutter SDK Version with FVM</h3><ul><li>Type fvm install stable to install stable channel.</li><li>If you want to see all flutter SDK version releases that you can install just type fvm releases</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A57EY_WOcHJaHy2XY20n0g.png" /></figure><ul><li>If you want to install specific version. Let say you want to install flutter SDK version 2.05 just type fvm install 2.0.5</li><li>To see your installed versions. just type: fvm list</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UQTJw6uL4Q0XTp_C1w8sHQ.png" /></figure><h3>3. Use FVM in your project</h3><ul><li>In your root file of your project type fvm use &lt;your version&gt;</li></ul><p>For example I use 2.0.5. just type fvm use 2.0.5 to see if it is already used that version in your project. Execute this fvm list command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KoW1AZVmJNYo_IZizcFNfw.png" /></figure><h3>4. Set up to your IDE</h3><p>Let configure your IDE. In my example, I will show you how to finish the setup process in<strong> </strong>VS code.</p><ul><li>After using the above commands to use your flutter SDK version. You will see .fvm folder in your root file.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IQd-UeUsbUkpaPCFK8_fdA.png" /></figure><ul><li>Press cmd + , then go to user setting.json and paste this:</li></ul><pre>&quot;dart.flutterSdkPaths&quot;: [</pre><pre>&quot;$YOUR_PATH/fvm/versions&quot;,</pre><pre>],</pre><ul><li>To get the above path simply execute fvm list command. Then will show this:</li></ul><pre>// copy this path<br>Versions path:  $YOUR_PATH/fvm/versions</pre><ul><li>To use it please type cmd + shift + p and type change sdk and then you can choose your prefer version.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yblH685cwklR42uVja_ENw.png" /></figure><ul><li>In this example I choose Flutter SDK 2.0.5</li></ul><h3>5. How Run or Install library in your project</h3><p>From now on, every commands want to use like flutter run , flutter pub get , etc. You MUST prefix them by fvm.</p><p>For example:</p><pre>// to run your project<br>fvm flutter run</pre><pre>// to install libs<br>fvm flutter pub get</pre><h3>Conclusion</h3><p>Flutter Version Management or (FVM) is simple cli to manage Flutter SDK versions.</p><p>FVM helps with the need for a consistent app builds by allowing to reference Flutter SDK version used on a per-project basis. It also allows you to have multiple Flutter versions installed to quickly validate and test upcoming Flutter releases with your apps, without waiting for Flutter installation every time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c318c4ff97d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Upload multiple images and compress image in Flutter]]></title>
            <link>https://soksereyphon8.medium.com/upload-multiple-images-and-compress-image-in-flutter-62d113a3247a?source=rss-f6699f52b47f------2</link>
            <guid isPermaLink="false">https://medium.com/p/62d113a3247a</guid>
            <category><![CDATA[imagepicker]]></category>
            <category><![CDATA[image-compression]]></category>
            <category><![CDATA[image-upload]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Sokserey PHON]]></dc:creator>
            <pubDate>Fri, 26 Feb 2021 09:52:08 GMT</pubDate>
            <atom:updated>2021-02-26T09:52:08.122Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sRy6FyWnT-pVxTDM.jpeg" /></figure><p>In this article, I will demonstrate how to upload multiple images and compress image in your Flutter App.</p><p>There are some required libs in order to solve this problem:</p><p><a href="https://pub.dev/packages/multi_image_picker"><em>multi_image_picker</em></a></p><p><a href="https://pub.dev/packages/flutter_image_compress"><em>flutter_image_compress</em></a></p><p><a href="https://pub.dev/packages/dio"><em>dio</em></a></p><p><a href="https://pub.dev/packages/path_provider"><em>path_provider</em></a></p><p><a href="https://pub.dev/packages/flutter_absolute_path">flutter_absolute_path</a></p><h3><strong>Get images from gallery</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9wpy_bRjfZtCzD79eVHeWA.png" /><figcaption>Load assets from gallery with multi_image_picker</figcaption></figure><h3><strong>Convert List&lt;Asset&gt; to List&lt;File&gt;</strong></h3><p>From <em>multi_image_picker</em> lib, it returns <strong><em>List&lt;Asset&gt;</em></strong><em>. </em>However<em>, flutter_image_compress </em>can compress <strong><em>File</em></strong><em>. </em>Let’s convert <strong>List&lt;Asset&gt;</strong> to <strong>List&lt;File&gt;</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7_OM-a95AXy1zJu94QuriQ.png" /><figcaption>Convert List&lt;Asset&gt; to List&lt;File&gt;</figcaption></figure><h3><strong>Image Compress Service</strong></h3><p>Let’s create <em>image_compress_service </em>to generate image path and compress image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TKfrv4dErGJtYLR2Motd8w.png" /></figure><h3><strong>Generate FormData</strong></h3><p>In order to upload file, we need to generate it to <strong><em>FormData</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c-3ujrO_7pvULku6e1_hDg.png" /><figcaption>Generate Form Data</figcaption></figure><h3><strong>Upload Images to Server</strong></h3><p>After generating <strong>FormData </strong>from above method, here is the final step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G4S2UVQuuQgtI8zL9CtZ4g.png" /></figure><p>Finally, we can upload compressed images to the server successfully. Please give me some claps 👏👏👏👏 if you like this article.</p><p>Check out full source code here: <a href="https://github.com/MRSEREY/upload_multi_image_flutter"><em>full_source_code</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62d113a3247a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to debug redux and inspect react elements in your react native app]]></title>
            <link>https://soksereyphon8.medium.com/how-to-debug-redux-and-inspect-react-elements-in-your-react-native-app-cddd551cd2fd?source=rss-f6699f52b47f------2</link>
            <guid isPermaLink="false">https://medium.com/p/cddd551cd2fd</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react-native-debugger]]></category>
            <category><![CDATA[redux-devtools]]></category>
            <category><![CDATA[react-devtools]]></category>
            <dc:creator><![CDATA[Sokserey PHON]]></dc:creator>
            <pubDate>Mon, 21 Oct 2019 07:25:03 GMT</pubDate>
            <atom:updated>2019-10-21T07:25:03.118Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mqu1ZDROnR0P00WLWzOR1g.png" /></figure><p>As default of react native debugger, we can only debug basic console in your app. Imagine you are using redux how to can you debug your states, actions, etc. Moreover, It is hard to inspect your react native elements and change your style directly like what you did in chrome. In this blog, I will illustrate easy tools and how to integrate within your react native app.</p><ol><li><a href="https://github.com/jhen0409/react-native-debugger/blob/master/docs/getting-started.md">react-native-debugger</a></li></ol><p>for mac:</p><pre>brew cask install react-native-debugger</pre><blockquote>after installing react-native-debugger successfully, let’s add an extension in our Chrome browser by going to <strong>chrome://extensions/ </strong>and add redux devtools.</blockquote><p>2. <a href="https://github.com/zalmoxisus/redux-devtools-extension">redux-devtools-extension</a></p><pre>npm install --save redux-devtools-extension<br>or<br>yarn add redux-devtools-extension</pre><p>after that let’s config our store:</p><pre>import { createStore, applyMiddleware, compose } from ‘redux’</pre><pre>import createSagaMiddleware from ‘redux-saga’</pre><pre>import rootSaga from ‘./sagas/rootSaga’;</pre><pre>import rootReducer from ‘./reducers/rootReducer’;</pre><pre><strong>import { composeWithDevTools } from ‘redux-devtools-extension’;</strong></pre><pre>const sagaMiddleware = createSagaMiddleware();</pre><pre>export default function configureStore() {</pre><pre>const store = createStore(rootReducer, <strong>composeWithDevTools(applyMiddleware(sagaMiddleware)))</strong></pre><pre>sagaMiddleware.run(rootSaga)</pre><pre>return store</pre><pre>}</pre><p>3. <a href="https://www.npmjs.com/package/react-devtools">react-devtools</a></p><p>if you want to install globally please follow the command line below:</p><pre><em># Yarn</em></pre><pre>yarn global add react-devtools</pre><pre><em># NPM</em></pre><pre>npm install -g react-devtools</pre><p>If you prefer to avoid global installations, you can add react-devtools as a project dependency. With Yarn, you can do this by running:</p><pre>yarn add — dev react-devtools</pre><p>after installing 3 packages above successfully, let play around with by just running this command line</p><pre>open &quot;rndebugger://set-debugger-loc?host=localhost&amp;port=8081&quot;</pre><p>it will open a react native debugger tool but <strong>please make sure your pervious debugger is closed</strong>. when react native debugger is launched, just type the following shortcuts to show developer menu and choose <strong><em>debug js remotely </em></strong>then it will be linked to react native debugger tool.</p><pre>for IOS simulator<br>cmd + d<br>for Android emulator<br>cmd + m</pre><p>Now you can play around with that tool by debugging state, action or inspecting your component’s styles.</p><blockquote>you can see more more options by just right click on your react debugger tool.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A3uJqDKDix0dMof9hNnytw.png" /></figure><p>I hope this will help you guys to test or debug your react native application easily. If this blog help you just give me some claps :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cddd551cd2fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to manage staging and production env for React Native App]]></title>
            <link>https://soksereyphon8.medium.com/how-to-manage-staging-and-production-env-for-react-native-app-50944138a8e3?source=rss-f6699f52b47f------2</link>
            <guid isPermaLink="false">https://medium.com/p/50944138a8e3</guid>
            <category><![CDATA[react-native-config]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react-native-env]]></category>
            <dc:creator><![CDATA[Sokserey PHON]]></dc:creator>
            <pubDate>Thu, 12 Sep 2019 10:39:40 GMT</pubDate>
            <atom:updated>2019-09-12T10:39:40.981Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*6DAA82E35zLrJCMKcV6I4w.png" /></figure><p>In this blog will demonstrate you guys how to manage your React Native App with different env, staging and production. This help me a lot when I want to change my environment to debug or release my app to the Store.</p><p>First thing first, we are going to use one of config file library,<strong><em> </em></strong><a href="https://github.com/luggit/react-native-config"><strong><em>react-native-config</em></strong></a><strong><em>. </em></strong>After following the docs, if you are using <strong><em>podfile </em></strong>you will face the following error:</p><pre>/node_modules/react-native-config/ios/ReactNativeConfig/ReactNativeConfig.m:2:9: fatal error: ‘GeneratedDotEnv.m’ file not found</pre><blockquote>To solve it just open your <strong>podfile</strong><em>,</em> then at the bottom of your<em> </em><strong>podfile</strong><em> </em>please add the following codes and then run <strong>pod install</strong>:</blockquote><pre>post_install do |installer|</pre><pre>installer.pods_project.targets.each do |target|</pre><pre>if target.name == “React”</pre><pre>target.remove_from_project</pre><pre>end</pre><pre>if target.name == ‘react-native-config’</pre><pre>phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)</pre><pre>phase.shell_script = “cd ../../”\</pre><pre>“ &amp;&amp; RNC_ROOT=./node_modules/react-native-config/”\</pre><pre>“ &amp;&amp; export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig”\</pre><pre>“ &amp;&amp; export BUILD_DIR=$RNC_ROOT/ios/ReactNativeConfig”\</pre><pre>“ &amp;&amp; ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby”</pre><pre>target.build_phases &lt;&lt; phase</pre><pre>target.build_phases.move(phase,0)</pre><pre>end</pre><pre>end</pre><pre>end</pre><p>Next, I am going to create 3 files in my root project</p><pre>// .env<br>API_HOST=https://api.staging.foobar.com<br><br>// .env.staging<br>API_HOST=https://api.staging.foobar.com<br><br>// .env.production<br>API_HOST=https://api.foobar.com</pre><blockquote>Note: please follow the above convention, no space needed</blockquote><p>Now, to put those vars to use for my React Native app, here’s how my config file usually looks like:</p><pre>// import wherever you want to use your config vars<br><br>import env from &#39;react-native-config&#39;</pre><pre>const API_HOST = config.API_HOST;</pre><p>That’s all. By default, react-native-config reads from the .env file, but reading from any file &amp; running the project is possible via the following command:</p><pre>$ ENVFILE=.env.staging react-native run-ios</pre><p>All good so far, but I want my build process to be as automated as possible. So manually specifying the .env file is not acceptable. Avoiding this is what we&#39;re going to do next.</p><h3>IOS SETUP</h3><p>On iOS, I’m going to take advantage of the concept of <strong>schemes.</strong></p><pre>go to your XCODE -&gt; PRODUCT -&gt; EDITSCHEMA -&gt; DUPLICATESCHEMA</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*YCn5e7aRkF64T8uLrrVugA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e_F4BMVUu-Pb4sS3IRFegg.png" /></figure><p>After duplicating schema I am going to create another new schemas, naming is very important as my default schema is <strong>pick_up</strong> so I am going to create another two schemas called <strong>pick_up.staging</strong> and <strong>pick_up.production</strong></p><p>Next to ensure that my schema loads up .env file I want, I am going to select my pick_up.staging schema and then expand <strong>run</strong> section -&gt; click <strong>on Pre-action </strong>-&gt; click on + button and then choose <strong>New Run Script Action </strong>and<strong> </strong>add the following script</p><pre>echo “.env.staging” &gt; /tmp/envfile</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-w_fMM8KJceG0jfolmX7Tw.png" /></figure><p>for pick_up.production we are going to do the same step as pick_up.staging by just selecting pick_up.production and add the following script</p><pre>echo “.env.production” &gt; /tmp/envfile</pre><blockquote>Note: When you want to change your environment, you just select your schema (staging or production) and then build. However, when you first build, sometimes, It won’t change your environment yet so you need to do it twice and to ensure that just <strong>console.log(your config var).</strong></blockquote><p>That is the end of IOS setup let move to another funny setup for Android</p><h3>ANDROID SETUP</h3><p>For Android, we have <a href="https://developer.android.com/studio/build/build-variants?utm_source=android-studio#build-types">build types</a>. So in your <strong><em>android/app/build.gradle</em></strong>, under <strong><em>apply plugin: “com.android.application&quot;</em></strong> please add</p><pre>project.ext.envConfigFiles = [<br>        debug: &quot;.env&quot;,<br>        release: &quot;.env.production&quot;<br>]<br>apply from: project(&#39;:react-native-config&#39;).projectDir.getPath() + &quot;/dotenv.gradle&quot;</pre><p>To run the app using one of the build types defined above, go to View -&gt; Tool Windows -&gt; Build Variants and select the variant (in the newly exposed window) before building:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*2yb_a4R_ZKXo4k5fxMMX4Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*HjDyKOqm8YzmzsnX3Qb0mQ.png" /></figure><p>Finally we completed all steps for both IOS and Android. For your sensitive key please do not commit to your repository, eg(.env.staging and .env.production).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50944138a8e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>