<?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 Jacky Wu on Medium]]></title>
        <description><![CDATA[Stories by Jacky Wu on Medium]]></description>
        <link>https://medium.com/@jackywxd?source=rss-4f7f098f287e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*5OXGHIkcKa3NEPQm.</url>
            <title>Stories by Jacky Wu on Medium</title>
            <link>https://medium.com/@jackywxd?source=rss-4f7f098f287e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 07:43:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jackywxd/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[Maintain Firebase Cloud Messaging Tokens]]></title>
            <link>https://jackywxd.medium.com/maintain-firebase-cloud-messaging-tokens-eaa4445e5f6c?source=rss-4f7f098f287e------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaa4445e5f6c</guid>
            <category><![CDATA[push-notification]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[token]]></category>
            <category><![CDATA[fcm]]></category>
            <category><![CDATA[google-cloud-messaging]]></category>
            <dc:creator><![CDATA[Jacky Wu]]></dc:creator>
            <pubDate>Mon, 07 Feb 2022 18:25:45 GMT</pubDate>
            <atom:updated>2022-02-07T18:25:45.687Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="FCM Architectural" src="https://cdn-images-1.medium.com/max/1024/1*f73JFzfYkAl43zJ15v9pqw.png" /></figure><p>Firebase Cloud Messaging (FCM) is quite often being used to send push notification to customers. Google has excellent documentation and you can find tons of examples out there to get you started.</p><p>But I did not find many discussions about how to update the device tokens. In the real world, it is very important to maintain the tokens up-to-dated as tokens could change over time.</p><p>As we know saving user’s device tokens is the prerequisite to be able to send push notification. A user can have more than one token (for example using 2 devices) so it’s important to ensure that we store all tokens in the database. A token arrays could be maintained in the backend database and being used when sending push notification to devices:</p><pre><em>// Node.js</em><br>var admin = require(&#39;firebase-admin&#39;);<br><br><em>// ownerId - who owns the picture someone liked</em><br><em>// userId - id of the user who liked the picture</em><br><em>// picture - metadata about the picture</em><br><br>async function onUserPictureLiked(ownerId, userId, picture) {<br>  <em>// Get the owners details</em><br>  const owner = admin.firestore().collection(&#39;users&#39;).doc(ownerId).get();<br><br>  <em>// Get the users details</em><br>  const user = admin.firestore().collection(&#39;users&#39;).doc(userId).get();<br><br>  await admin.messaging().sendToDevice(<br>    owner.tokens, <em>// [&#39;token_1&#39;, &#39;token_2&#39;, ...]</em><br>    {<br>      data: {<br>        owner: JSON.stringify(owner),<br>        user: JSON.stringify(user),<br>        picture: JSON.stringify(picture),<br>      },<br>    },<br>    {<br>      <em>// Required for background/quit data-only messages on iOS</em><br>      contentAvailable: true,<br>      <em>// Required for background/quit data-only messages on Android</em><br>      priority: &#39;high&#39;,<br>    },<br>  );<br>}</pre><p>The admin.messaging().sendToDevice will return an object that contains the result of messaging delivery result, including success count and failure count, as well as the result for each token in the results array:</p><pre>{<br>  successCount: 1,<br>  failureCount: 1,<br>  canonicalRegistrationTokenCount: 0,<br>  multicastId: 955052197873664600,<br>  results: [<br>    { messageId: &#39;1642701659970999&#39; },<br>    {<br>      error: {<br>        code: &#39;messaging/registration-token-not-registered&#39;,<br>        message:<br>          &#39;The provided registration token is not registered. A previously valid registration token can be unregistered for a variety of reasons. See the error documentation for more details. Remove this registration token and stop using it to send messages.&#39;<br>      }<br>    },<br>  ]<br>}</pre><p>By examining this returned result of admin.messaging().sendToDevice we can easily keep user’s tokens up-to-dated. Below is a simple code snippet.</p><pre>async function updateTokens(<br>  tokens: string[],<br>  res: admin.messaging.MessagingDevicesResponse,<br>  userId: string<br>) {<br>  if (res.failureCount &gt; 0) {<br>    res.results.forEach((result, index) =&gt; {<br>      if (result.error) {<br>        tokens.splice(index, 1)<br>      }<br>    })<br>    await db.collection(&#39;users&#39;).doc(userId).set(<br>      {<br>        tokens<br>      },<br>      { merge: true }<br>    )<br>  }<br>}</pre><p>I hope you find this short article helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaa4445e5f6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understand JWT: Access token vs Refresh token]]></title>
            <link>https://jackywxd.medium.com/understand-jwt-access-token-vs-refresh-token-2951e5e45193?source=rss-4f7f098f287e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2951e5e45193</guid>
            <category><![CDATA[access-token]]></category>
            <category><![CDATA[feathersjs]]></category>
            <category><![CDATA[jwt-token]]></category>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[refresh-token]]></category>
            <dc:creator><![CDATA[Jacky Wu]]></dc:creator>
            <pubDate>Sat, 06 Mar 2021 05:48:09 GMT</pubDate>
            <atom:updated>2022-02-08T05:45:42.952Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently in one of my project I need to secure my REST API using JWT. Most of my previous projects were using serverless architecture and I always use AWS Cognito as a go-to solution.</p><p>When working with AWS Cognito, we need to deal with three tokens: ID token, access token and refresh token. <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-with-identity-providers.html">Using Tokens with User Pools</a>. AWS SDK and Amplify handle all the dirty-works related to token management, and provides couple APIs that enables easy and straight forward interface working with Cognito backend.</p><p>When I come to use Feathers as a building block for my new project, I bring the same expectation for Feathers. I was really surprised when I learned that Feathers only supports access token and no refresh token implementation.</p><p>Refresh-token actually is long-requested feature for Feathers since year 2015. <a href="https://github.com/feathersjs/feathers/issues/1337#issuecomment-651488662">Add support for refresh tokens #1337</a> After digging into the discussions in the issue, I found that there were some mis-understandings of refresh-token. Some people believe that re-issuing access-token is refresh-token. That’s not the case. Access token and refresh token are two totally different things.</p><p>The main purpose of refresh-token is to refresh the short-live access-token. Access-token can access user’s data and having a long-live access-token could cause security issue. That’s why access-token usually will expire in hour or even minutes. Once access-token expired, to avoid having user to login again, refresh-token is used to get a new access token. Refresh-token cannot access user’s data, so having a long live refresh token will have less security concern. In the worst case refresh-token also can be revoked.</p><p>Once refresh-token expired, user has to go through login process again to get a new refresh-token. There is not other way to refresh refresh-token.</p><p>Some key difference between access token and refresh token listed below:</p><h3>Difference between access token and refresh token</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*847bYy5ey-RVRXwCy0cuKQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2951e5e45193" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Native for Cross-platform App — Android and iOS are not equal]]></title>
            <link>https://jackywxd.medium.com/react-native-for-cross-platform-app-android-and-ios-are-not-equal-a2dd84331cd3?source=rss-4f7f098f287e------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2dd84331cd3</guid>
            <category><![CDATA[keyboardavoidingview]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobx]]></category>
            <dc:creator><![CDATA[Jacky Wu]]></dc:creator>
            <pubDate>Sat, 06 Mar 2021 02:32:40 GMT</pubDate>
            <atom:updated>2021-03-06T02:32:40.880Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Native for Cross-platform App — Android and iOS are not equal</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*QcBu2_5Xz98G46jGFwmegw.png" /><figcaption>React Native for Cross-platform App — Android and iOS are not equal</figcaption></figure><p>When it comes to cross platform mobile App development, most people turn to React Native as it promotes itself: Learn once, write everywhere, or put it another way, write once, run everywhere! And it is true, with React native, you can use one code base for both Android and iOS App.</p><p>But my experience tells me that Android and iOS are not equal. Quite often something works perfectly in iOS which doesn’t work in Android. Android requires lots more efforts to make it work properly.</p><p>You may not agree with me, here are a few issues we encountered and some suggestions how to avoid them, hope that can help others.</p><h3>JavaScript Run Time</h3><p>JSC is the default JavaScript runtime that comes with React Native, but your better choice would be V8 or the newer Hermes if it is supported. Here are some issues we ran into with default JSC:</p><ol><li>Year 38 crash issue<br>Setting date beyond year 2038 can crash the whole App</li><li>Mobx observable array crash; some npm packages may not work as expected, for example, the popular cron-parser will throw errors with JSC</li></ol><pre><strong>*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***</strong></pre><pre><strong>Build fingerprint: &#39;google/sdk_gphone_x86/generic_x86_arm:10/RSR1.200312.003/6304234:userdebug/dev-keys&#39;</strong></pre><pre><strong>Revision: &#39;0&#39;</strong></pre><pre><strong>ABI: &#39;x86&#39;</strong></pre><pre><strong>Timestamp: 2021-02-07 11:13:56-0800</strong></pre><pre><strong>pid: 11252, tid: 11387, name: mqt_js &gt;&gt;&gt; mobi.autotext &lt;&lt;&lt;</strong></pre><pre><strong>uid: 10147</strong></pre><pre><strong>signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0</strong></pre><pre><strong>Cause: null pointer dereference</strong></pre><pre><strong>eax 00000000 ebx 00000004 ecx edd81c30 edx 38363032</strong></pre><pre><strong>edi 00000000 esi bea67368</strong></pre><pre><strong>ebp bea67458 esp bea67340 eip edd81c32</strong></pre><p>A little google will tell I am not alone, below are few links for your reference:</p><p><a href="https://github.com/mobxjs/mobx/issues/734">Large observable arrays do not play well with React Native Android · Issue #734 · mobxjs/mobx</a></p><p><a href="https://github.com/facebook/react-native/issues/24261">App Crash on Android OS 6 Samsung Galaxy S7 SM-G930FD (JSC Crash) 64 bit support A/libc: Fatal signal 11 (SIGSEGV) · Issue #24261 · facebook/react-native</a></p><p><a href="https://github.com/facebook/react-native/issues/25494">signal 11 (SIGSEGV), code 1 (SEGV_MAPERR) libjsc.so still occuring on Caterpillar S41 (Android 8.0) · Issue #25494 · facebook/react-native</a></p><h3>Bundle size issue</h3><p>The cost of using a V8 engine (<a href="https://github.com/Kudo/react-native-v8">Kudo/react-native-v8: Opt-in V8 runtime for React Native Android</a>) will be the bundle size. After switching to V8, the bundle size of our App jumped from 40MB to 60MB, that’s a 50% increase! I think using Herme definitely will help, but we are using React Native Firebase which doesn’t support Herme yet, that leaves us V8 the only option. With V8, everything runs much smoother, we can even set schedules to 2068. I hope React Native will be still around at that time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/0*UAAiDVtMww82NUKv" /></figure><p>As React Native 0.64 will be released soon which supports Firebase. We will give it a try once it is available.</p><h3>Keyboard layout</h3><p>Keyboard layout is another simple thing that we struggle a lot with Android, and have been experiencing some weird behaviours.</p><p>For example, I had exactly the same problem as this one: header gets pushed up on Android when keyboard first appears. <a href="https://github.com/FaridSafi/react-native-gifted-chat/issues/1931">https://github.com/FaridSafi/react-native-gifted-chat/issues/1931</a></p><p>Below is the screenshot of my App. You can see the TextInput is in the middle of screen leaving a big gap between the keyboard. As soon as I start typing, it will drop down and display normal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/0*xbxJEOKquoabeZoJ" /></figure><p>And even worse. I found that sometimes React Native code in the Emulator and real device would behave differently. This problem only happens on my Samsung and not in Emulator. I have to use real devices to do development.</p><p>Anyway, I was able to find a workaround after struggling for a couple days. Sometimes small things will kill you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2dd84331cd3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase Setup for Monorepo: Functions + Yarn + Webpack]]></title>
            <link>https://jackywxd.medium.com/firebase-setup-for-monorepo-functions-yarn-webpack-45a61e6c14eb?source=rss-4f7f098f287e------2</link>
            <guid isPermaLink="false">https://medium.com/p/45a61e6c14eb</guid>
            <category><![CDATA[yarn]]></category>
            <category><![CDATA[function]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[webpack]]></category>
            <dc:creator><![CDATA[Jacky Wu]]></dc:creator>
            <pubDate>Tue, 05 Jan 2021 06:09:28 GMT</pubDate>
            <atom:updated>2022-08-08T07:26:03.563Z</atom:updated>
            <content:encoded><![CDATA[<p>January 02, 2021</p><h3>Background</h3><p>In Heidi Technology (https://heidi.cloud), we use single monorepo for all of our products. Our monorepo is managed by yarn workspace and we have couple products built on top of Firebase, including frontend and backend.</p><h3>The problem</h3><p>Firebase cli doesn’t support monorepo, not yet when the time I am writing this blog. There is an open <a href="https://github.com/firebase/firebase-tools/issues/653">issue</a> keep tracking it in its repo since 2018.</p><p>Firebase expects all dependencies in Functions’s packages.json are available when it deploys your functions code in the Google Cloud. In a yarn monorepo, local shared packages are simply symbol links in node_modules which are not available during cloud deployment. So Firebase will reports below error when you try to deploy functions:</p><pre>error An unexpected error occurred: &quot;https://registry.yarnpkg.com/&lt;packagename&gt;: Not found&quot;.<br>info If you think this is a bug, please open a bug report with the information provided in &quot;/workspace/yarn-error.log&quot;.</pre><p>To address this issue, there are two solutions:</p><ol><li>Publish shared packages to NPM or Github so they are accessible during cloud deployment</li><li>Package your shared packages along with your functions code, there are two ways to package local dependencies in a monorepo:</li></ol><ul><li>Use yarn pack</li><li>Use webpack to bundle all local deps</li></ul><p>Here I would like to share what I did to deploy Firebase functions in my monorepo using yarn and webpack based on the tips/workarounds being discussed in above issue. I also created a demo repo <a href="https://github.com/jackywxd/firebase-monorepo">firebase-monorepo</a> with all my configurations, you can simply clone it and follow alone. Below is the folder structure of the demo project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/0*euinWoVQlWkuV1CX.png" /></figure><ul><li>firebase — Your firebase folder</li><li>shared — Shared libs used by firebase functions</li></ul><p>Let’s take a closer look of some key settings we need to set to make it works.</p><h3>Shared folder</h3><p>Not much in the shared folder, this is where you implement all your shared libs or business logics.</p><h3>package.json</h3><p>Make sure shared package name starts with ”@”, so it can be used as local dependency by Firebase functions. The shared folder and webpack folder also should share the same dependencies.</p><pre>{<br>  &quot;name&quot;: &quot;@jackywxd/shared&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>  },<br>  &quot;keywords&quot;: [],<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;firebase-admin&quot;: &quot;^9.4.1&quot;,<br>    &quot;firebase-functions&quot;: &quot;^3.13.0&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;@typescript-eslint/eslint-plugin&quot;: &quot;^4.9.1&quot;,<br>    &quot;@typescript-eslint/parser&quot;: &quot;^4.9.1&quot;,<br>    &quot;eslint&quot;: &quot;^7.15.0&quot;,<br>    &quot;eslint-plugin-import&quot;: &quot;^2.22.0&quot;,<br>    &quot;firebase-functions-test&quot;: &quot;^0.2.0&quot;,<br>    &quot;typescript&quot;: &quot;^4.1.2&quot;<br>  },<br>  &quot;private&quot;: true<br>}</pre><h3>Settings for Firebase functions folder</h3><p>In functions folder, two files need to be updated: package.json, firebase.json and webpack.config.js.</p><h4>1. FIREBASE.JSON</h4><p>In firebase.json file, we set the source to the webpack bundle output folder, in my case, it is set to “webpack”. I also config the predeploy to call webpack prior deployment.</p><pre>{<br>  &quot;functions&quot;: {<br>    &quot;source&quot;: &quot;webpack&quot;,<br>    &quot;predeploy&quot;: [&quot;npm --prefix \&quot;functions\&quot; run webpack&quot;]<br>  }<br>}</pre><h4>2. PACKAGE.JSON</h4><p>In the package.json in functions folder, I add a new “webpack” entry to call webpack. Make sure devDependencies includes webpack, webpack-cli and webpack-node-externals which will be used in webpack.config.js. Your local package used by functions also should be added to dependencies.</p><pre>{<br>  &quot;name&quot;: &quot;functions&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;webpack&quot;: &quot;webpack&quot;, <br>    &quot;lint&quot;: &quot;eslint \&quot;src/**/*\&quot;&quot;,<br>    &quot;build&quot;: &quot;tsc&quot;,<br>    &quot;serve&quot;: &quot;npm run build &amp;&amp; firebase emulators:start --only functions&quot;,<br>    &quot;shell&quot;: &quot;npm run build &amp;&amp; firebase functions:shell&quot;,<br>    &quot;start&quot;: &quot;npm run shell&quot;,<br>    &quot;deploy&quot;: &quot;firebase deploy --only functions&quot;,<br>    &quot;logs&quot;: &quot;firebase functions:log&quot;<br>  },<br>  &quot;engines&quot;: {<br>    &quot;node&quot;: &quot;12&quot;<br>  },<br>  &quot;main&quot;: &quot;lib/index.js&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;@jackywxd/shared&quot;: &quot;*&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;@typescript-eslint/eslint-plugin&quot;: &quot;^3.9.1&quot;,<br>    &quot;@typescript-eslint/parser&quot;: &quot;^3.8.0&quot;,<br>    &quot;eslint&quot;: &quot;^7.6.0&quot;,<br>    &quot;eslint-plugin-import&quot;: &quot;^2.22.0&quot;,<br>    &quot;firebase-functions-test&quot;: &quot;^0.2.0&quot;,<br>    &quot;ts-loader&quot;: &quot;^8.0.13&quot;,<br>    &quot;typescript&quot;: &quot;^3.8.0&quot;,<br>    &quot;webpack&quot;: &quot;^5.11.1&quot;,<br>    &quot;webpack-cli&quot;: &quot;^4.3.1&quot;,<br>    &quot;webpack-node-externals&quot;: &quot;^2.5.2&quot;<br>  },<br>  &quot;private&quot;: true<br>}</pre><h4>3. WEBPACK.CONFIG.JS</h4><p>Two key settings in the webpack.config.js file: externals and output. Make sure your local package used by functions is added to nodeExternals’ allowlist.</p><p>In output section, set the filename to ‘index.js’ and path to the correct folder. This setting should match the settings in the package.json in webpack folder.</p><pre>const path = require(&#39;path&#39;)<br>const nodeExternals = require(&#39;webpack-node-externals&#39;)</pre><pre>module.exports = {<br>  target: &#39;node&#39;,<br>  mode: &#39;production&#39;,<br>  entry: &#39;./src/index.ts&#39;,<br>  module: {<br>    rules: [<br>      {<br>        test: /\.tsx?$/,<br>        use: &#39;ts-loader&#39;,<br>        exclude: /node_modules/,<br>      },<br>    ],<br>  },<br>  optimization: {<br>    minimize: false,<br>  },<br>  performance: {<br>    hints: false,<br>  },<br>  devtool: &#39;nosources-source-map&#39;,<br>  resolve: {<br>    extensions: [&#39;.tsx&#39;, &#39;.ts&#39;, &#39;.js&#39;, &#39;.json&#39;],<br>  },<br>  externals: [<br>    /^firebase.+$/,<br>    /^@google.+$/,<br>    nodeExternals({<br>      allowlist: [/^@jackywxd/],<br>    }),<br>  ],<br>  output: {<br>    filename: &#39;index.js&#39;,<br>    path: path.resolve(__dirname, &#39;../webpack/dist&#39;),<br>    libraryTarget: &#39;commonjs&#39;,<br>  },<br>}</pre><h3>Webpack output folder</h3><p>This is the webpack output folder configured in functions’s webpack.config.js, only one package.json and one dist folder are required in this folder. Folder “dist” is the folder configured in the path of output section in the webpack.config.js file. Webpack bundled file will go to this folder with file name index.js.</p><p>The main in package.json in webpack folder should be set to “dist/index.js”. It should have a deploy script to call firebase functions deploy.</p><p>And as mentioned previously, all dependencies used by your local packages should be put in dependencies as well, so they will be installed correctly during cloud deployment.</p><pre>{<br>  &quot;name&quot;: &quot;cloud-functions&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;deploy&quot;: &quot;firebase deploy --only functions&quot;<br>  },<br>  &quot;engines&quot;: {<br>    &quot;node&quot;: &quot;12&quot;<br>  },<br>  &quot;main&quot;: &quot;dist/index.js&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;firebase-admin&quot;: &quot;^9.4.1&quot;,<br>    &quot;firebase-functions&quot;: &quot;^3.13.0&quot;<br>  },<br>  &quot;devDependencies&quot;: {},<br>  &quot;private&quot;: true<br>}</pre><p>Finally, you may want to update .gitignore file to add the dist folder.</p><h3>The result</h3><p>With the above setup, inside the firebase folder, I can simply use one command firebase deploy --only functions to bundle all of my code to webpack folder and deploy functions to Firebase from there.</p><p>And below is the deployment result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/0*BZWG4ond-58Vj2hc.png" /></figure><p>This config works with yarn monorepo nicely and it is a common patter used by other projects such as serverless and serverless-webpack. Since I have been working with serverless for a while and quite familiar with similar configuration, that’s why I have chosen this solution.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45a61e6c14eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase Admob Causes Android App Crashing on Launch]]></title>
            <link>https://jackywxd.medium.com/firebase-admob-causes-android-app-crashing-on-launch-151ee911d8f1?source=rss-4f7f098f287e------2</link>
            <guid isPermaLink="false">https://medium.com/p/151ee911d8f1</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[admob]]></category>
            <dc:creator><![CDATA[Jacky Wu]]></dc:creator>
            <pubDate>Fri, 01 Jan 2021 03:30:14 GMT</pubDate>
            <atom:updated>2021-01-01T03:30:14.802Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Reference https://facebook.github.io/react-native/blog/2018/11/01/oss-roadmap" src="https://cdn-images-1.medium.com/max/1024/1*6qROUrzwvHvlNRdYPfnUzQ.png" /><figcaption>Reference: <a href="https://facebook.github.io/react-native/blog/2018/11/01/oss-roadmap">https://facebook.github.io/react-native/blog/2018/11/01/oss-roadmap</a></figcaption></figure><p>Today I tried to migrated my React Native App to a monorepo. The monorepo is created based on Bruno Lemos’s excellent work react native web monorepo template (<a href="https://github.com/brunolemos/react-native-web-monorepo">https://github.com/brunolemos/react-native-web-monorepo</a>).</p><p>Since my React Native App is already working fine on both iOS and Android, I simply copy couple folders (namely they are android, ios and src) folders from my current project to the new monorepo project under mobile folder. Then tried to change the settings to make it work with monorepo. (see below screen shot, folders pointed with arrow)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*5A4GfFcDIHXLicALod81zQ.png" /><figcaption>My monorepo project folder structure</figcaption></figure><p>The migration of ios App went well, but it took me a full day to make android working properly. Somehow the android app even can be compiled successfully and launched in emulator or real phone, but the launch screen just flashed a second then disappeared.</p><p>Since I am using <a href="https://github.com/crazycodeboy/react-native-splash-screen">react-native-splash-screen</a>, so I thought that was caused by it. So I spent couple hours on making sure <a href="https://github.com/crazycodeboy/react-native-splash-screen">react-native-splash-screen</a> was configured properly following its Github documentation, also tried different combination of settings, but still no luck, same result, the launch screen flashed a second then simply disappeared, no error and no log.</p><p>Before I giving up, I decided to figure out what’s going on during the app launch. In one console I used “adb logcat” to see the real time logs, then launch my app in the other console window “react-native run-android”</p><pre>adb logcat</pre><p>Right away I found out that I forgot to copy the firebase.json from my original project, and missing the firebase.json caused Firebase Admob crashing on launch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kw8E5t_XalvxMofqHZH_eg.png" /></figure><p>The firebase.json file is located in the project root and it contains App ID Settings for Admob, apparently Admob can’t work properly without it.</p><pre><br>{</pre><pre>&quot;react-native&quot;: {</pre><pre>&quot;admob_android_app_id&quot;: &quot;ca-app-pub-&lt;id&gt;&quot;,</pre><pre>&quot;admob_ios_app_id&quot;: &quot;ca-app-pub-&lt;id&gt;&quot;,</pre><pre>&quot;admob_delay_app_measurement_init&quot;: true,</pre><pre>}</pre><p>After copied the firebase.json file to the mobile folder, everything works correctly! So missing one file caused my entire day! 😭</p><p>Anyway, I am glad I finally figure it out and I still learned quite a lot, so it is worthy. Below is just an example I learned today how to configure react native unimodule for monorepo.</p><h3>Update React Native Unimodule for monorepo</h3><p>Bruno Lemos’s react native web monorepo template is very bare bone, only involved react native’s setting. My react native project contains lots more packages, such as Firebase, Expo, some of them also require change to work with monorepo. For example, below are some changes for react native unimodule:</p><pre>android/settings.gradle:</pre><pre>apply from: &#39;../../../node_modules/react-native-unimodules/gradle.groovy&#39;; includeUnimodulesProjects([modulesPaths: [&#39;../../../../node_modules&#39;]])</pre><pre>android/app/build.gradle:</pre><pre>addUnimodulesDependencies([modulesPaths[&#39;../../../../node_modules&#39;]])</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=151ee911d8f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>