<?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 Mayank &#39;DerperDoing&#39; Bagchi on Medium]]></title>
        <description><![CDATA[Stories by Mayank &#39;DerperDoing&#39; Bagchi on Medium]]></description>
        <link>https://medium.com/@derperdoing?source=rss-f238136b8489------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mNkFgta0Dwbba3Usso5RHw.png</url>
            <title>Stories by Mayank &amp;#39;DerperDoing&amp;#39; Bagchi on Medium</title>
            <link>https://medium.com/@derperdoing?source=rss-f238136b8489------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 14:26:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@derperdoing/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[How I built a free Japanese walking timer in the browser (and where the web hit its limits)]]></title>
            <link>https://derperdoing.medium.com/how-i-built-a-free-japanese-walking-timer-in-the-browser-and-where-the-web-hit-its-limits-8fc09cde7c92?source=rss-f238136b8489------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fc09cde7c92</guid>
            <category><![CDATA[expo]]></category>
            <category><![CDATA[japanese-walking]]></category>
            <category><![CDATA[web-audio-api]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Mayank 'DerperDoing' Bagchi]]></dc:creator>
            <pubDate>Sun, 18 Oct 2026 07:44:10 GMT</pubDate>
            <atom:updated>2026-10-18T07:46:42.252Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Drift-free intervals, chimes made with code, Wake Lock, and why I still ended up shipping an Android app.</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qqk1gRSnL_Qed4AnOex_LA.jpeg" /></figure><p>Hey there, fellow internet dweller on a quest for answers!</p><p>This time it’s not a Unity fix. After 60 to 90 minutes of strength training, I really don’t have another 90 minutes to walk 10,000 steps. That’s when I came across <strong>Japanese walking</strong>.</p><p>If you haven’t heard of it yet: Japanese walking is <strong>3 minutes of slow walking, then 3 minutes of brisk walking, repeated 5 times</strong>. That’s 30 minutes, at least 4 days a week. It comes from the <em>Interval Walking Training</em> research by Prof. Hiroshi Nose’s team at Shinshu University in Japan. If you want the proper how-to, with pace and a beginner plan, I wrote a <a href="https://freejapanesewalkingtimer.com/japanese-walking-method">step-by-step guide to the Japanese walking method</a>.</p><p>The method is simple. Knowing <em>when</em> to switch is not. I didn’t want to keep pulling my phone out, so my big brain made a playlist where every song was roughly 3 minutes long. 30 divided by 3 is… 10 songs. On repeat. Every walk. That got old fast.</p><p>So first I built an Android app (more on that saga below). Then I built a <a href="https://freejapanesewalkingtimer.com/">free Japanese walking timer</a> that runs in the browser, so anyone on iPhone or Android can use it right away: no sign-up, nothing to install, and different chimes so you never have to look at the screen.</p><p>Turns out a timer that’s <em>reliable while someone is walking with the phone in a pocket</em> is a bit trickier than setInterval(tick, 1000). Here’s what I ran into and how I fixed each one.</p><p><strong>TL;DR</strong></p><ol><li>Don’t count ticks. Store <strong>absolute end timestamps</strong> and work out the state from the clock.</li><li>Make the chimes with the <strong>Web Audio API </strong>(no audio files), and unlock audio on the Start tap.</li><li>Use the <strong>Screen Wake Lock API</strong> to stop the screen from dimming, and <strong>request it again</strong> whenever the page becomes visible.</li><li>A web page still gets paused when the phone is locked. That’s a platform limit, and it’s exactly why the Android app exists.</li></ol><h4><strong>PROBLEM 1: </strong><strong>setInterval lies to you</strong></h4><p>The obvious version looks like this:</p><pre>let remaining = 180;<br>setInterval(() =&gt; {<br>remaining--;<br>if (remaining === 0) switchPhase();<br>}, 1000);</pre><p>It works fine on your desk. Then you put the phone in your pocket. Browsers throttle timers in background tabs (sometimes to once a minute, or they freeze the tab completely), so every missed tick is a second your timer silently loses. Ten minutes in, your “3 minutes” is anything but.</p><p><strong>The fix:</strong> stop counting. Save <em>when</em> the current interval ends, and on every tick compare that against the actual time:</p><pre>tick() {<br>  if (this.status !== &#39;running&#39;) return [];<br>  const events = [];<br>  while (this.status === &#39;running&#39; &amp;&amp; Date.now() &gt;= this.segmentEndAt) {<br>    // Chain from the scheduled end, not from &quot;now&quot;, so long sleeps don&#39;t drift.<br>    events.push(…this.enterSegment(this.index + 1, this.segmentEndAt));<br>  }<br>  return events;<br>}</pre><p>Two details matter here:</p><ul><li>It’s a while, not an if. If the tab was frozen through two interval changes, it catches up through both of them in one tick.</li><li>The next interval starts from the <strong>scheduled</strong> end time, not from Date.now(). Otherwise a late tick pushes every interval after it back a little.</li></ul><p>Rendering runs on requestAnimationFrame while the page is visible. A slow setInterval keeps ticking when it’s hidden, and a visibilitychange listener syncs everything up the moment you look at the screen again.</p><h4><strong>PROBLEM 2: chimes without audio files</strong></h4><p>I wanted three sounds you can tell apart without looking: one for “slow down”, one for “speed up” and one for “done”. Instead of shipping MP3 files, the code generates them on the fly with the Web Audio API.</p><p>The trick is simpler than it sounds. Play a few sine waves at once (a main frequency, plus quieter ones at roughly 2x and 3x of it), then fade the volume in almost instantly and let it fade out over a second or so. That quick start and slow fade is what makes it sound like a “ding” instead of a flat beep:</p><pre>function ding(ac, freq, at, fadeOut, volume) {<br>  // Volume envelope: near-silent → full volume in 8 ms → fade out over `fadeOut` seconds.<br>  const out = ac.createGain();<br>  out.gain.setValueAtTime(0.0001, at);<br>  out.gain.exponentialRampToValueAtTime(volume, at + 0.008);<br>  out.gain.exponentialRampToValueAtTime(0.0001, at + fadeOut);<br>  out.connect(ac.destination);<br><br>  // [frequency multiplier, relative volume]: the main tone plus two quieter, higher ones.<br>  for (const [ratio, level] of [[1, 1], [2.01, 0.35], [3.02, 0.12]]) {<br>    const osc = ac.createOscillator();<br>    const g = ac.createGain();<br>    osc.frequency.value = freq * ratio;<br>    g.gain.value = level;<br>    osc.connect(g).connect(out);<br>    osc.start(at);<br>    osc.stop(at + fadeOut + 0.05);<br>  }<br>}</pre><p>Then each cue is just a few dings in a row. “Slow” plays two dings going <strong>lower</strong> in pitch, “brisk” plays three going <strong>higher</strong>, and “done” plays four with a longer fade at the end. Down means ease off, up means speed up. After a walk or two your brain just knows which is which.</p><p>(The 2.01 and 3.02 aren’t typos. Being slightly off an exact multiple makes it sound more like a real bell and less like a synth.)</p><p><strong>Gotcha:</strong> browsers won’t play audio until the user has interacted with the page. So I create and resume() the AudioContext inside the <strong>Start</strong> button&#39;s click handler. Do it anywhere else and your first chime plays to nobody.</p><p>On Android I also added vibration patterns with navigator.vibrate(): a single buzz for slow, a quick triple buzz for brisk. iOS Safari doesn&#39;t support it, so the option only shows up when the browser has it.</p><h4><strong>PROBLEM 3: the screen goes to sleep</strong></h4><p>If the screen auto-locks, the browser pauses the page, and the chimes stop. The <a href="https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API">Screen Wake Lock API</a> keeps it awake:</p><pre>let sentinel = null;<br>let wanted = false;<br><br>async function request() {<br>  if (!(&#39;wakeLock&#39; in navigator) || document.visibilityState !== &#39;visible&#39;) return;<br>  try {<br>    sentinel = await navigator.wakeLock.request(&#39;screen&#39;);<br>    sentinel.addEventListener(&#39;release&#39;, () =&gt; (sentinel = null));<br>  } catch {<br>  // Denied (e.g. battery saver). The timer still works; the screen may just dim.<br>  }<br>}<br><br>// The browser drops the lock whenever the page is hidden; take it back on return.<br>document.addEventListener(&#39;visibilitychange&#39;, () =&gt; {<br>  if (wanted &amp;&amp; !sentinel &amp;&amp; document.visibilityState === &#39;visible&#39;) request();<br>});</pre><p>The part most tutorials skip: <strong>the browser releases your wake lock every time the page is hidden</strong>, e.g. when you switch apps for a second to reply to a message. If you don’t request it again on visibilitychange, the screen quietly goes back to normal and you won’t notice until a chime goes missing.</p><h4><strong>PROBLEM 4: the screen is on… and in your pocket</strong></h4><p>A screen that stays on in your pocket will happily press “Reset” for you. So there’s a <strong>pocket lock</strong>: a full-screen black overlay with the phase and the clock, unlocked with a slide gesture. While it’s up, everything else on the page gets the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inert">inert</a> attribute, so stray touches (and screen readers) can’t reach the controls behind it.<br>Black pixels on an OLED screen also go easy on the battery.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dU_u9uJG6ICCrury6sIBsg.jpeg" /></figure><h4><strong>Where the web hit its limits</strong></h4><p>All of the above gets you a timer that’s accurate, can be used without looking, and survives switching apps. What it <em>can’t</em> do is keep running when you press the power button. Once the phone is locked, the browser suspends the page. Wake Lock only stops the screen from turning off <em>by itself</em>. It can’t stop you from turning it off.</p><p>Funnily enough, I’d already learned this lesson the hard way with the app.</p><p>I built <a href="https://play.google.com/store/apps/details?id=com.basementexperiments.japaneseintervalwalking"><strong>Vuvu, Japanese Interval Walking Timer for Android</strong></a> with <strong>Expo</strong>. It was my first native mobile app after 5+ years of game dev, and I tried to build it mostly with AI on a 10 dollar budget. The first AI-generated version had the exact same problem: it only worked while the app was on screen. Lock the phone, open YouTube… nothing.</p><p>The fix there was <strong>scheduling device notifications</strong> for every phase change in advance, so Android cues you even when the app isn’t running. A few things that cost me way more time than they should have:</p><ul><li><strong>Expo Go can’t test this.</strong> You need a development build installed on the phone (I used EAS Build).</li><li><strong>Exact timing needs permissions.</strong> I ended up with SCHEDULE_EXACT_ALARM, plus trying USE_EXACT_ALARM.</li><li><strong>AI kept “fixing” it without fixing it.</strong> What actually worked was reading the Expo notifications docs myself and then giving the AI better instructions.</li><li><strong>OnePlus still hates me.</strong> It works on Samsung, Motorola and Poco, but OnePlus notifications either don’t arrive or arrive at the wrong time. If you know the fix, please tell me in the comments!</li></ul><p>The browser doesn’t have a reliable way to schedule a local notification at an exact time, so that’s where the line falls. If you want cues with the screen off, use the app. It’s free too, with no sign-ups, no subscriptions and no ads.</p><p>I made a video about the whole saga, from “make my billion dollar app and MAKE NO MISTAKES” to a 7-day Play Store review:</p><p><a href="https://youtu.be/e1uvRDUN6rY">https://youtu.be/e1uvRDUN6rY</a></p><p>So the split ended up being:</p><ul><li><strong>Browser: </strong>zero install, works on iPhone and Android, perfect when you want to try the method today.</li><li><strong>Android app:</strong> for daily walkers who want the phone locked in their pocket.</li></ul><h4><strong>Try It!</strong></h4><ul><li>🕒 Free Web Timer: <a href="https://freejapanesewalkingtimer.com/">https://freejapanesewalkingtimer.com/</a></li><li>📖 New to the method? Read the <a href="https://freejapanesewalkingtimer.com/japanese-walking-method">Japanese walking guide</a>, plus <a href="https://freejapanesewalkingtimer.com/japanese-walking-pace">how fast “brisk” should actually be</a></li><li>🌐 Readers from Germany: here’s the <a href="https://freejapanesewalkingtimer.com/de/japanese-walking-method">Anleitung zum japanischen Gehen</a> auf Deutsch</li><li>📱 Android App: <a href="https://play.google.com/store/apps/details?id=com.basementexperiments.japaneseintervalwalking">Japanese Interval Walking on Google Play</a></li></ul><p>Hopefully this saves you some time if you’re building any kind of interval or workout timer for the web. And if you’re just here for the walking: go take a walk. 🚶</p><p>If in need, feel free to reach out to me <a href="http://www.mayankbagchi.dev/">@MayankBagchi.dev</a></p><p>See ya!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fc09cde7c92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to change C# script asset icon in Unity?]]></title>
            <link>https://derperdoing.medium.com/how-to-change-c-script-asset-icon-in-unity-0629f339f0a1?source=rss-f238136b8489------2</link>
            <guid isPermaLink="false">https://medium.com/p/0629f339f0a1</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[unity-editor]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[tools]]></category>
            <dc:creator><![CDATA[Mayank 'DerperDoing' Bagchi]]></dc:creator>
            <pubDate>Wed, 21 Jan 2026 11:49:33 GMT</pubDate>
            <atom:updated>2026-05-05T14:38:05.052Z</atom:updated>
            <content:encoded><![CDATA[<h4>NOT a tutorial but is in a way…</h4><figure><img alt="A thumbnail with Unity logo at the top, below it “Script Icon Customiser”, the name of the tool and on the right, a screenshot of the actual tool as visible in the Unity Editor." src="https://cdn-images-1.medium.com/max/1024/1*I74DQk_IBwqACzN9BC3l5w.png" /></figure><p>Hello there, fellow internet dweller on quest for answers!<br>Would you like to customise the C# script asset icons of your Unity project for <em>free</em> because:</p><ol><li>you want to reduce cognitive load for programmers &amp; enable designers and non-programmers to navigate scripts intuitively through colour-coded &amp; icon-coded systems?</li><li>make critical scripts pop visually?</li><li>may be simply prefer visually appealing things in your Unity Editor?</li><li>or, you have your own reasons (we don’t judge here)!</li></ol><h3>Meet — Script Icon Customiser</h3><p>I’ve created an open-source Unity package to help you achieve that.<br>(No, that em dash is not by ChatGPT 🙂)</p><blockquote><em>Unity Package Repo<br></em><a href="https://github.com/gamesbyBAE/script-icon-customiser.git"><em>https://github.com/gamesbyBAE/script-icon-customiser.git</em></a></blockquote><p>This Unity Editor tool adds a small editor window plus a couple of menu items to your Unity project. With it, you can:</p><ul><li>Change the icon of one or more C# script assets.</li><li>Use either a tinted version of Unity’s default script icon or a custom texture from your project (optionally, customise it’s color as well).</li><li>Restore everything back to the default icon in one click if you change your mind.</li></ul><p>It’s built to feel like a native part of the editor, not “some random hack” you’re afraid to commit.</p><h3>Install it the easy way (Unity Package Manager, Git URL)</h3><p>There are multiple ways to install the package, but if you just want to use it, this is the path of least resistance (also, the easiest to get package updates).</p><p>Depending on your Unity version (6000.3+ recommended) the options may differ, but I’ve tried my best here to cover the steps for different versions.</p><ol><li>Open your project in Unity.</li><li>Go to Window ➜ Package Manager or Window ➜ Package Management ➜ Package Manager</li><li>Click the + button in the top-left corner.</li><li>Select Add package from git URL… or Install package from git URL…</li><li>Paste this repository URL: <a href="https://github.com/gamesbyBAE/script-icon-customiser.git">https://github.com/gamesbyBAE/script-icon-customiser.git</a></li><li>Hit Add or Install and let Unity do its thing.</li></ol><p>That’s it. Once it finishes, the new menu items will be available under Assets ➜ Script Icon.</p><h3>How to use this tool?</h3><p>Here’s the “tutorial” part on using this tool to customise the script icons (very clickbaity?).</p><h4>Apply Custom Icon:</h4><p>1. Select one or more script assets in the Project window.</p><p>2. Open the Editor Window in any of these ways:</p><ul><li>Menu: Assets ➜ Script Icon ➜ Change Icon, or</li><li>Shortcut: Cmd/Ctrl + Alt + Shift + C, or</li><li>Right Click Menu: Right Click ➜ Script Icon ➜ Change Icon</li></ul><p>3. In the window:</p><ul><li>Use the image picker to select a custom texture, or leave it empty to just tint the default script icon.</li><li>Use the color picker to set a tint if you want.</li><li>Check the preview to see what the final icon will look like.</li></ul><p>6. Drag any extra scripts you want to affect into the Target Scripts list.</p><p>7. Click Apply button.</p><p>Unity will briefly reimport those assets and our Project window and Inspector will now show the new icon for those scripts.</p><h4>Restore Default Icon:</h4><p>If you or a teammate go overboard with colors or assigned a wrong icon, you can reset things quickly.</p><p><strong>Option 1: Quick Restore</strong></p><ol><li>Select the scripts you want to reset.</li><li>Use any one of the methods:</li></ol><ul><li>Menu: Assets → Script Icon → Restore Icon, or</li><li>The provided restore shortcut, or</li><li>The same right‑click menu under Script Icon → Restore Icon.</li></ul><p><strong>Option 2: From the Editor Window</strong></p><ol><li>Open the <em>Custom Script Icon</em> editor window again (Assets → Script Icon → Change Icon or shortcut).</li><li>Make sure the target list contains the scripts you want to reset.</li><li>Click Restore button.</li></ol><p>Unity will reimport and bring back the classic script icon.</p><h3>How it works under the hood?</h3><p>Well if you are here not just to use the tool, but to learn how to build something like this yourself (you were expecting that kinda tutorial…),<br>at this point, I’ve no intentions of creating a tutorial or in-depth explanation but you’re free to explore the repo, it may not be the best but it’s surely not <em>spaghetti</em>.<br>I’ve tried my best to keep the repo and scripts well structured and easy to read.</p><p>You’ll find:</p><ol><li>A dedicated editor window script that is the entry point of this tool along with menu hooks.</li><li>A presenter layer coordinating UI and logic.</li><li>Core services that:-</li></ol><ul><li>Grab the default icon.</li><li>Generate tinted copies or pass through your custom textures.</li><li>Save the new icons into a folder Unity can track.</li><li>Apply them to scripts through Unity’s importer API.</li></ul><p>If you’re exploring editor tools architecture, this is a nice, self‑contained example that touches UIElements, Unity Style Sheet (USS), editor menus, and asset importers without becoming a huge framework.</p><h3>Want to Contribute?</h3><p>If this package saves you time or makes your project feel a bit more “yours”, consider:</p><ol><li>Starring the repo on GitHub.</li><li>Opening an issue if you hit a bug or have a feature idea.</li><li>Sending a pull request if you:</li></ol><ul><li>Improve performance or UX.</li><li>Add useful options.</li><li>Clean up or extend the code.</li></ul><p>Here’s the repo again in case you missed it earlier:-</p><pre>https://github.com/gamesbyBAE/script-icon-customiser</pre><p>Use it in your next project, and turn that wall of identical C# icons into something your future self (and your teammates) will actually enjoy looking at.</p><p>🏃🏽‍♂️Until we meet again!<br><a href="http://www.mayankbagchi.dev/">www.MayankBagchi.dev</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0629f339f0a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get Started with Mistral AI OCR: Plug-and-Play Wrapper with Visual Outputs in 6 Steps]]></title>
            <link>https://derperdoing.medium.com/ocr-with-image-clippings-embedded-in-the-output-using-mistral-ai-61882b4163cd?source=rss-f238136b8489------2</link>
            <guid isPermaLink="false">https://medium.com/p/61882b4163cd</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[mistral]]></category>
            <category><![CDATA[ocr]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[mistral-ocr]]></category>
            <dc:creator><![CDATA[Mayank 'DerperDoing' Bagchi]]></dc:creator>
            <pubDate>Wed, 15 Oct 2025 13:16:38 GMT</pubDate>
            <atom:updated>2026-04-29T16:37:59.250Z</atom:updated>
            <content:encoded><![CDATA[<h4>Skip setup headaches, this 6-step guide shows how to use my minimal Mistral OCR wrapper that extracts text and embeds image snippets directly in the results.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*YJZONC2UGs7zL3OO3CpZEw.png" /></figure><p>If you’ve got a use case where you want tables, charts, diagrams, or other visual elements included in the OCR output, then right now <a href="https://mistral.ai/news/mistral-ocr"><strong>Mistral AI</strong></a> is one of the best options out there.</p><figure><img alt="It’s a comparison image. Left image shows the source image to be used for OCR. Right images shows the resultant OCR markdown preview." src="https://cdn-images-1.medium.com/max/1024/1*yITylhZiLfYnsx1JvhtTww.png" /><figcaption>Source Image &amp; OCR Output</figcaption></figure><p>That said, even though it’s pretty accurate most of the time, it does occasionally miss a few image clippings.<br>For example, in one case with two labelled plant diagrams, it extracted both the labels perfectly but only picked up one of the images.<br>It’d also be nice if we could include a custom prompt along with the OCR request, like you can with some other AI models. But overall, it still performs great for what it does.</p><p>Anyway, if your use case sounds like that, I built a minimal <a href="https://github.com/gamesbyBAE/mistral-ocr-with-embedded-images"><strong>Python wrapper</strong></a> to make it easy.</p><h3>Using the Wrapper</h3><p>All you need to do is import the Mistral client:</p><pre>from mistral_ai import mistral_client</pre><p>and then call either of these methods:</p><pre># OCR an image<br>await mistral_client.ocr_image(&quot;path/to/image.png&quot;)<br><br># OCR a PDF<br>await mistral_client.ocr_pdf(&quot;path/to/document.pdf&quot;)</pre><p>In response, you’ll get a <a href="https://en.wikipedia.org/wiki/Markdown">Markdown string</a> with the extracted text and embedded images encoded in Base64.</p><h3>Get Started in <strong>6 Quick Steps</strong></h3><p>1.Clone the repository from GitHub.</p><pre>git clone https://github.com/gamesbyBAE/mistral-ocr-with-embedded-images</pre><p>2. Install the 2 required packages:</p><ul><li>mistralai: The core Mistral library</li><li>python-dotenv: To read values from a file &amp; set them as environment values.</li></ul><p>Install the packages by running:</p><pre>pip install -r requirements.txt</pre><blockquote><em>⚠️ </em>Highly recommended to create a venv before installing the packages.</blockquote><p>3.Generate an API key in <a href="https://console.mistral.ai/api-keys">Mistral’s dashboard</a>.</p><figure><img alt="API Keys section in Mistral’s dashboard after logging in." src="https://cdn-images-1.medium.com/max/1024/1*035gii4pYrX3bkzk10PoXw.png" /><figcaption>API Keys section in Mistral Dashboard</figcaption></figure><p>4. Create a .env file at the root of the directory.</p><figure><img alt=".env file placed at the root directory of the project. The same level as README.md, requirements.txt, etc." src="https://cdn-images-1.medium.com/max/700/1*rNR8T_IRPHPyMhJAOKdEEw.png" /><figcaption>.env File at the Project Root</figcaption></figure><p>5.In this newly created .env file, add the following:</p><pre># Put your Mistral API key here<br>MISTRAL_API_KEY=YOUR_API_KEY_HERE<br><br># Optional: override model name<br>MISTRAL_OCR_MODEL=mistral-ocr-latest</pre><p>6.Check out main.py, which demonstrates how to use the Mistral wrapper.<br> It performs OCR on the included sample image and PDF file.</p><p>Upon its successful execution, you’ll see the outputs stored as Markdown files:</p><ul><li>/output/image_ocr.md</li><li>/output/pdf_ocr.md</li></ul><p>And we are done! 🎉<br>This wrapper exists to simplify the process of running OCR on images or PDFs with visual elements embedded in the output, hopefully saving you some dev time.</p><p>If in need, feel free to reach out to me <a href="http://www.mayankbagchi.dev/">@MayankBagchi.dev</a><br>See ya!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61882b4163cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use AWS SDK in Unity for WebGL builds?]]></title>
            <link>https://derperdoing.medium.com/how-to-use-aws-sdk-in-unity-for-webgl-builds-81c086f6f94a?source=rss-f238136b8489------2</link>
            <guid isPermaLink="false">https://medium.com/p/81c086f6f94a</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-sdk-for-webgl]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[aws-sdk]]></category>
            <category><![CDATA[webgl]]></category>
            <dc:creator><![CDATA[Mayank 'DerperDoing' Bagchi]]></dc:creator>
            <pubDate>Sun, 22 Oct 2023 15:34:32 GMT</pubDate>
            <atom:updated>2023-12-21T07:46:56.228Z</atom:updated>
            <content:encoded><![CDATA[<p>So you want to use AWS services in your Unity game/app and also figured out how to setup &amp; use the AWS SDK for .NET but then realise it doesn’t work for WebGL builds, right?</p><p>The TL;DR solution is to use AWS SDK for JavaScript in Unity that works with the WebGL builds.</p><p>Keep reading if you are curious on how to setup and call JavaScript functions from C# scripts with an example of using AWS Firehose service in Unity for WebGL to send your data.</p><h4>The whole process can be divided into 2 parts:</h4><ol><li>We create a .jslib file in our Unity project which has our JavaScript functions and use System.Runtime.InteropServices<em> </em>to call those functions from C# script.<br>Read more about it in Unity’s <a href="https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html">documentation</a>.</li><li>We either load the AWS SDK for JavaScript in runtime from a server or include it in the build itself.</li></ol><h4>Setting up your script files and the code to send data using AWS Firehose</h4><p>1.It is essential that the .jslib file with our JavaScript functions must be placed inside Assets &gt; Plugins folder of our project. I personally create another subfolder, WebGL, inside Plugins folder. Let’s call this file AWSFirehose.jslib</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-psZ37qDuJtQVq4aSO0H2A.png" /><figcaption>Assets &gt; Plugins &gt; WebGL &gt; AWSFirehose.jslib</figcaption></figure><p>2. Open the file in your code editor and type in the below lines.<br>Even if you ignore the first line where we declare the variable, rest of the template has to be exactly same.</p><pre>var firehoseClient = null; //Globally accessible AWS client<br><br>mergeInto(LibraryManager.library, {<br>  //All of our code goes inside this curly braces.<br>});</pre><blockquote><strong>Note:</strong> Comments are not allowed so don’t actually add them in your file else you’ll get errors.</blockquote><p>3. Before interacting with AWS services, it’s crucial to perform the AWS client configuration. Instead of hardcoding sensitive credentials like secret keys and access keys, it’s recommended to utilise AWS Cognito or other secure identity management methods for a more robust approach to AWS configuration.<br>But for this example, I’ll be hardcoding them. Again, <strong>not </strong>a recommended way of doing it.</p><pre>var firehoseClient = null; //Globally accessible AWS client<br><br>mergeInto(LibraryManager.library, {<br>  AWSFirehose_Init: function (accessKey, secretKey, region) {<br>        if(typeof AWS === &#39;undefined&#39;)<br>        {<br>            console.log(&quot;AWS SDK not available&quot;);<br>            return;<br>        }<br><br>        if(typeof AWS.Firehose === &#39;undefined&#39;)<br>        {<br>            console.log(&quot;Firehose service not available&quot;);<br>            return;<br>        }<br>        <br>        var ak = UTF8ToString(accessKey);<br>        var sk = UTF8ToString(secretKey);<br>        var rg = UTF8ToString(region);<br>        <br>        AWS.config.update({<br>            accessKeyId: ak,<br>            secretAccessKey: sk,<br>            region: rg<br>        });<br>        firehoseClient = new AWS.Firehose();        <br>    }<br>});</pre><p>4. Next, we write the function that actually sends our data.</p><pre>var firehoseClient = null; //Globally accessible AWS client<br><br>mergeInto(LibraryManager.library, {<br>  //Initialising Client<br>  AWSFirehose_Init: function (accessKey, secretKey, region) {<br>        if(typeof AWS === &#39;undefined&#39;)<br>        {<br>            console.log(&quot;AWS SDK not available&quot;);<br>            return;<br>        }<br><br>        if(typeof AWS.Firehose === &#39;undefined&#39;)<br>        {<br>            console.log(&quot;Firehose service not available&quot;);<br>            return;<br>        }<br>        <br>        var ak = UTF8ToString(accessKey);<br>        var sk = UTF8ToString(secretKey);<br>        var rg = UTF8ToString(region);<br>        <br>        AWS.config.update({<br>            accessKeyId: ak,<br>            secretAccessKey: sk,<br>            region: rg<br>        });<br>        firehoseClient = new AWS.Firehose();        <br>    }, //Don&#39;t forget this comma here before defining our next function<br>  <br>  //Sending Data<br>  AWSFirehose_PutRecord: function (dataPointer, streamName) {<br>        if (typeof firehoseClient === &#39;undefined&#39;) {<br>          console.error(&quot;AWS not initialized.&quot;);<br>          return;<br>        }<br><br>        //Data json to be sent<br>        var dataString = UTF8ToString(dataPointer);<br><br>        //Stream on which the data has to be sent<br>        var stream = UTF8ToString(streamName);<br><br>        function attemptPutRecord() {<br>            var params = {<br>                DeliveryStreamName: stream,<br>                Record: {<br>                    Data: dataString<br>                }<br>            };<br><br>            firehoseClient.putRecord(params, function (err, data) {<br>                if (err) {<br>                    console.log(&quot;Error sending data...&quot;, err);<br>                }<br>            });<br>        }<br><br>        attemptPutRecord();<br>    }<br>});</pre><p>5. We are done with our .jslib file. Now create a new C# script, AWSFirehose.cs, from where we’ll call our JavaScript functions.<br>In order to do so, we have to use System.Runtime.InteropServices as well as hard code the credentials.</p><pre>using UnityEngine;<br>using System.Runtime.InteropServices;<br><br>public class AWSFirehose : MonoBehaviour<br>{<br>    private readonly string accessKey = &quot;dummyAccessKey&quot;;<br>    private readonly string secretKey = &quot;dummySecretKey&quot;;<br>    private readonly Amazon.RegionEndpoint region = Amazon.RegionEndpoint.EUNorth1;<br>}</pre><blockquote><strong>Note:</strong> As mentioned at the beginning, assuming you have already setup AWS SDK for .NET in Unity, you’ll have access to <em>Amazon.RegionEndpoint</em> class else make the <em>region</em> variable of type string, because anyway further in this <em>AWSFirehose.cs</em> script’s Start method, we’ll be using one of it’s property called <em>SystemName</em> which is of type string.</blockquote><p>6. Next, we declare the methods/functions we defined in AWSFirehose.jslib<br>[DllImport(“__Internal”)] attribute indicates that we want to call a function from a native library or external code.<br>Make sure the method name is same as the one in .jslib and the order and type of parameters is correct as well.</p><pre>using UnityEngine;<br>using System.Runtime.InteropServices;<br><br>public class AWSFirehose : MonoBehaviour<br>{<br>    private readonly string accessKey = &quot;dummyAccessKey&quot;;<br>    private readonly string secretKey = &quot;dummySecretKey&quot;;<br>    private readonly Amazon.RegionEndpoint region = Amazon.RegionEndpoint.EUNorth1;<br><br>    [DllImport(&quot;__Internal&quot;)]<br>    private static extern void AWSFirehose_Init(string accessKey, string secretKey, string region);<br><br>    [DllImport(&quot;__Internal&quot;)]<br>    private static extern void AWSFirehose_PutRecord(string data, string streamName);<br>}</pre><p>7. Finally in Start method, we initialise the AWS client and another method to send the data. With that we finish the scripting part.</p><pre>using UnityEngine;<br>using System.Runtime.InteropServices;<br><br>public class AWSFirehose : MonoBehaviour<br>{<br>    private readonly string accessKey = &quot;dummyAccessKey&quot;;<br>    private readonly string secretKey = &quot;dummySecretKey&quot;;<br>    private readonly Amazon.RegionEndpoint region = Amazon.RegionEndpoint.EUNorth1;<br><br>    [DllImport(&quot;__Internal&quot;)]<br>    private static extern void AWSFirehose_Init(string accessKey, string secretKey, string region);<br><br>    [DllImport(&quot;__Internal&quot;)]<br>    private static extern void AWSFirehose_PutRecord(string data, string streamName);<br><br>    private void Start()<br>    {<br>        AWSFirehose_Init(accessKey, secretKey, region.SystemName);   <br>    }<br><br>    public void SendDataToFirehose(string data, string stream)<br>    {<br>        AWSFirehose_PutRecord(data, stream);<br>    }<br>}</pre><p><strong>Loading the AWS SDK for JavaScript in the build.</strong></p><p>1.Go on and build the WebGL build in Unity from the Build Settings as one usually builds for each platform.</p><p>2. Once the build has finished, you get an index.html and a Build folder. Open up index.html in your code editor.</p><p>3. This step is utmost important. We need to add &lt;script&gt; tag to include external JavaScript files in a web page. This is how we will be loading our AWS SDK for JavaScript. Add this tag preferably inside the &lt;head&gt; tag.</p><p>4. Now there are 2 ways you can load the SDK.</p><ol><li>Loading the hosted SDK package directly from Amazon Web Services or from your own server.</li><li>Download the package manually and including the SDK package in the previously mentioned Build folder before hosting the game.</li></ol><h4>If loading the package from server:</h4><p>In case you want to load the SDK from AWS’s server, add the line:</p><pre>&lt;script src=&quot;https://sdk.amazonaws.com/js/aws-sdk-SDK_VERSION_NUMBER.min.js&quot;&gt;&lt;/script&gt;</pre><p>I recently used <strong>v2.1475.0 </strong>so the code would be:</p><pre>&lt;script src=&quot;https://sdk.amazonaws.com/js/aws-sdk-2.1475.0.min.js&quot;&gt;&lt;/script&gt;</pre><p>Just replace the source link in case you want it to load from your server. Why would you do so though? Keep reading to know one of the reasons.</p><blockquote>Documentation sauce for loading the SDK from a server, switch to Browser tab from Node tab: <a href="https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-the-jssdk.html">AWS Doc</a></blockquote><h4>If including the package in Build folder:</h4><ul><li>Download the minified version from AWS’s GitHub repo: <a href="https://github.com/aws/aws-sdk-js/blob/master/dist/aws-sdk.min.js">Repository</a></li><li>Place it inside the Build folder.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tsCFVIJUk2hH79uHxMoKjw.png" /><figcaption>AWS SDK JavaScript package inside Build folder</figcaption></figure><p>Line of code to add in the index.html in this case would be the local path of the package.</p><pre>&lt;script src=&quot;Build/DOWNLOADED_PACKAGE_NAME.js&quot;&gt;&lt;/script&gt;</pre><p>Your index.html should probably look like this depending on how you choose to load the SDK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v0X-9zBwPzZaDrJxe826_A.png" /><figcaption>After adding &lt;script&gt; tag in index.html</figcaption></figure><h4>Create your own build of the AWS SDK for JavaScript.</h4><p>You can create a custom build of the AWS SDK by only including the services you’re using in the project.</p><p>The easiest way is to use AWS’s SDK builder web application:<br><a href="https://sdk.amazonaws.com/builder/js">https://sdk.amazonaws.com/builder/js</a></p><ol><li>Select the SDK version from Core version dropdown.</li><li>Select the services you want to include.</li><li>Select either Minified or Development. Development generates readable code.</li><li>Then click on Build button to download the package.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6_UsjBzFf-4eekZOKxsRcA.png" /><figcaption>Since, we didn’t use Cognito while coding just the Firehose service will be enough</figcaption></figure><blockquote>There are other ways to build your own SDK as well, you can find it in the <a href="https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/building-sdk-for-browsers.html">documentation</a>.</blockquote><p>Now you can either host this downloaded package on your own server or put it in the Build folder as mentioned previously.</p><p>You are ready to deploy your WebGL build and test out the services.</p><p>We have reached the end of the guide. That was the complete process of making the AWS SDK for JavaScript work in WebGL builds.<br>If in doubt, just ask! Cheers o/</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81c086f6f94a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fix Google Play’s In-App Review not working with Minify in Unity]]></title>
            <link>https://derperdoing.medium.com/fix-google-plays-in-app-review-not-working-along-with-minify-in-unity-1787ed03da43?source=rss-f238136b8489------2</link>
            <guid isPermaLink="false">https://medium.com/p/1787ed03da43</guid>
            <category><![CDATA[proguard]]></category>
            <category><![CDATA[in-app-reviews]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[play-store]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Mayank 'DerperDoing' Bagchi]]></dc:creator>
            <pubDate>Thu, 29 Jun 2023 14:44:46 GMT</pubDate>
            <atom:updated>2025-10-17T09:48:09.466Z</atom:updated>
            <content:encoded><![CDATA[<p>If your in-app review doesn’t show up and tick all the below checks:-<br>1. You followed the Google Play’s official <a href="https://developer.android.com/guide/playcore/in-app-review/unity">documentation</a> on integrating their in-app review in your Unity game/app.<br>2. Have <strong>Minify </strong>&gt; <strong>Release </strong>enabled under Publishing Settings of Unity.<br>3. The build has been uploaded to Internal Test Track or Play Internal App Sharing.</p><p>Then you might have to generate a custom Proguard file.</p><p>Google Play’s in-app review feature allows developers to prompt users to leave reviews directly within their app. However, there have been instances where this feature fails to work properly when the Minify option is enabled under the Publishing Settings of Unity. In this article, we will discuss the steps to ensure that the in-app review functionality works correctly even when Minify is enabled.</p><figure><img alt="Steps to reach the option where Minify is, Edit &gt; Project Settings &gt; Player &gt; Android icon &gt; Publishing Settings &gt; Minify" src="https://cdn-images-1.medium.com/max/1024/1*W7ZImgATUVVxte_glr3xTg.png" /><figcaption><strong>Edit</strong> &gt; <strong>Project Settings </strong>&gt;<strong> Player</strong> &gt; <strong>Android</strong> icon &gt; <strong>Publishing Settings </strong>&gt;<strong> Minify</strong></figcaption></figure><p>Before we proceed, it’s essential to understand that enabling Minify in Unity’s Publishing Settings helps optimise and reduce the size of your Android application by removing unused code. However, this optimisation process can sometimes interfere with certain features, such as the in-app review.</p><blockquote>Curious to know how I zeroed down the issue was caused due to Minify?<br>My article, <a href="https://medium.com/@derperdoing/fix-androidjavaexception-java-lang-classnotfoundexception-caused-by-minify-in-unity-f165f5ef198">Fix </a><a href="https://medium.com/@derperdoing/fix-androidjavaexception-java-lang-classnotfoundexception-caused-by-minify-in-unity-f165f5ef198">AndroidJavaException: java.lang.ClassNotFoundException caused by Minify in Unity</a>, explains it in great details.</blockquote><h3>To resolve the issue, follow the below steps:</h3><p><strong>1.Enable custom Proguard file in Unity</strong><br>Navigate to <strong>Project Settings</strong> &gt; <strong>Player </strong>&gt; <strong>Publish Settings</strong> and enable the <strong>Custom Proguard File</strong> option.<br>By using a custom Proguard file, we make sure the classes necessary for functioning of in-app review is always included in the build.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RPF2_pW2n9w2we72vZYKuw.png" /><figcaption><strong>Project Settings</strong> &gt; <strong>Player </strong>&gt; <strong>Publish Settings </strong>&gt; <strong>Custom Proguard File</strong></figcaption></figure><p>2. <strong>Modify the Proguard Configuration</strong><br>Unity creates a new file called “<em>proguard-user.txt</em>” under<br><strong>Assets </strong>&gt; <strong>Plugins </strong>&gt; <strong>Android</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*25Pvzg88PXTQDRVRqhw9Pg.png" /><figcaption><strong>Assets </strong>&gt; <strong>Plugins </strong>&gt; <strong>Android </strong>&gt;<strong> proguard-user.txt</strong></figcaption></figure><p>Open this newly created file and paste the following code into it:</p><pre># Copyright 2019 Google LLC<br>#<br># The Google Play Core Library is licensed to you under the Play Core Software<br># Development Kit Terms of Service<br># (https://developer.android.com/guide/playcore/license.html).<br># By using the Google Play Core Library, you agree to the Play Core Software<br># Development Kit Terms of Service.<br><br># Play Core Proguard Rules: Play In-app Review<br><br>-keep class com.google.android.play.core.review.ReviewManager {<br>  public com.google.android.gms.tasks.Task requestReviewFlow();<br>  public com.google.android.gms.tasks.Task launchReviewFlow(android.app.Activity, com.google.android.play.core.review.ReviewInfo);<br>}<br><br>-keepnames class com.google.android.play.core.review.ReviewInfo<br><br>-keep class com.google.android.play.core.review.ReviewManagerFactory {<br>  &lt;init&gt;();<br><br>  public static com.google.android.play.core.review.ReviewManager create(android.content.Context);<br>}<br><br>-keep class com.google.android.play.core.review.testing.FakeReviewManager {<br>  public &lt;init&gt;(android.content.Context);<br>  public com.google.android.gms.tasks.Task requestReviewFlow();<br>  public com.google.android.gms.tasks.Task launchReviewFlow(android.app.Activity, com.google.android.play.core.review.ReviewInfo);<br>}<br><br>-keep class com.google.android.play.core.review.model.ReviewErrorCode {<br>    public static int NO_ERROR;<br>    public static int PLAY_STORE_NOT_FOUND;<br>    public static int INVALID_REQUEST;<br>    public static int INTERNAL_ERROR;<br>}<br><br>-keep class com.google.android.play.core.review.ReviewException {<br>    public int getErrorCode();<br>}<br><br># Fixes Tasks class not found error<br>-keep class com.google.android.gms.tasks.** { *; }</pre><p>These lines have been been directly copied from the file,<br><strong>Asset </strong>&gt; <strong>GooglePlayPlugins </strong>&gt; <strong>com.google.play.review </strong>&gt; <strong>Proguard </strong>&gt; <strong>review.txt<br></strong>Except the last line which has been added based on the logs from logcat.</p><blockquote>Read my <a href="https://derperdoing.medium.com/fix-androidjavaexception-java-lang-classnotfoundexception-caused-by-minify-in-unity-f165f5ef198#15bb">article </a>to further know how to figure out which classes to add in the custom Proguard file.</blockquote><p>3. <strong>Force Resolve Dependencies<br></strong>To ensure the proper resolution of dependencies, use the Android Resolver tool. Go to<br><strong>Assets </strong>&gt; <strong>External Dependency Manager</strong> &gt; <strong>Android Resolver</strong> &gt; <strong>Force Resolve</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*iSWXPlUv5iaFXrXZImwr9A.png" /><figcaption><strong>Assets </strong>&gt; <strong>External Dependency Manager</strong> &gt; <strong>Android Resolver</strong> &gt; <strong>Force Resolve</strong></figcaption></figure><p>4. <strong>Upload to Internal Test Track or Play Internal App Sharing</strong><br>of your Play Developer Console. These options allow you to distribute your app to a limited audience for testing purposes.<br><strong><em>Note:</em></strong><em> Play Internal App Sharing is preferred as there are no additional checks/reviews performed by Google Play. After uploading your app bundle, wait 2–7 minutes for it to be available for installation via the unique link.</em></p><p>5. <strong>Verify Account in Play Store App before opening the game</strong><br>Ensure that the Google Play Store app is signed in with the account associated with the Testers list in the Play Console. Failure to do so may prevent the review pop-up from appearing.<br><strong><em>Note:</em></strong><em> The in-app review pop up doesn’t allow you to submit the review if the game/app has been installed from the Play Internal App Sharing.</em></p><p>I hope this article helps you resolve the issue with Google Play’s in-app review functionality and enables you to gather valuable user feedback seamlessly within your Unity game/app.<br>If not, at least I hope it points you in a direction where you can further research upon the possible fixes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1787ed03da43" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fix AndroidJavaException: java.lang.ClassNotFoundException caused by Minify in Unity]]></title>
            <link>https://derperdoing.medium.com/fix-androidjavaexception-java-lang-classnotfoundexception-caused-by-minify-in-unity-f165f5ef198?source=rss-f238136b8489------2</link>
            <guid isPermaLink="false">https://medium.com/p/f165f5ef198</guid>
            <category><![CDATA[proguard]]></category>
            <category><![CDATA[troubleshooting]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[minify]]></category>
            <dc:creator><![CDATA[Mayank 'DerperDoing' Bagchi]]></dc:creator>
            <pubDate>Thu, 29 Jun 2023 14:25:26 GMT</pubDate>
            <atom:updated>2023-06-29T14:43:13.795Z</atom:updated>
            <content:encoded><![CDATA[<p>A guide on how to fix the issue of AndroidJavaException: java.lang.ClassNotFoundException if you just made an Android build of your Unity project and Minify is enabled.</p><h4>Table of Contens</h4><ol><li><a href="#b6e0">Figuring out Minify is the cause</a></li><li><a href="#15bb">Setting up logcat to figure out the missing classes</a></li><li><a href="#8c0c">How to fix?</a></li></ol><p>Enabling <strong>Minify </strong>&gt; <strong>Release </strong>in Unity’s Publishing Settings helps optimize and reduce the size of your Android application by removing unused code. However, this optimization process can sometimes interfere with certain features.</p><h3>How to figure out Minify is the culprit?</h3><p>1.If you upload the build on one of Google Play’s <a href="https://support.google.com/googleplay/android-developer/answer/9845334?hl=en&amp;ref_topic=7071528">testing track</a>, it automatically generates a <a href="https://support.google.com/googleplay/android-developer/answer/9842757?hl=en">pre-launch report</a> for you. Going through it shows the issues present, if any, in your app/game.<br>This is a hint that something’s wrong in your build due to stripping down of code by Minify.</p><p>2. To further pin-point the issue you need to connect your Android device and use logcat to get the logs. If you see logs similar to the below example, then Minify must have removed these classes from the build.</p><pre>AndroidJavaException: java.lang.ClassNotFoundException: com.google.unity.ads.UnityInterstitialAdCallback</pre><p><strong><em>Note:</em></strong><em> It’s usually in the format,<br></em><em>java.lang.ClassNotFoundException: com.example.missingclass<br> You can further refer to this official </em><a href="https://developers.google.com/android/reference/packages"><em>documentation</em></a><em> for more info on the packages and the classes.</em></p><h3>Setting up device and using logcat</h3><p>As mentioned above, in order to know which classes are missing, you’ll have to connect your device and use logcat.</p><p>1. <strong>Enable Developer Options</strong></p><ul><li>Open the “Settings” app on your Android device.</li><li>Scroll down and tap on “About phone” or “About device.”</li><li>Look for the “Build number” or “Build version” entry.</li><li>Tap on the “Build number” entry seven times quickly. After a few taps, you should see a countdown indicating the remaining number of taps required.</li><li>Once you’ve tapped seven times, you’ll see a message saying, “You are now a developer!”</li></ul><p>2. <strong>Access Developer Options</strong></p><ul><li>Go back to the main Settings screen.</li><li>Scroll down and look for a new entry called “Developer options” or “Developer settings.”</li><li>Tap on “Developer options” to open the developer settings menu.</li></ul><p>3. <strong>Enable USB Debugging</strong></p><ul><li>Inside the Developer options menu, scroll down and locate “USB debugging.”</li><li>Tap on the toggle switch next to “USB debugging” to enable it.</li><li>A warning message will appear explaining the potential risks of enabling USB debugging. Read the message and tap “OK” or “Enable” to proceed.</li></ul><p>4. <strong>Connect your device to a computer</strong></p><ul><li>Using a USB cable, connect your Android device to a computer.</li><li>If prompted on your device to allow USB debugging, grant permission by tapping “Allow.”</li></ul><p>5. <strong>Use Logcat</strong></p><ul><li>Type the command to run logcat, just replace the path till the Unity editor version, in this case, replace till 2021.3.16f1</li><li>Windows user, type in the command prompt</li></ul><pre>&quot;C:\Program Files\Unity\Hub\Editor\2021.3.16f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools\adb.exe&quot; logcat -s Unity ActivityManager PackageManager dalvikvm DEBUG</pre><ul><li>Mac users, type in the terminal</li></ul><pre>/Applications/Unity/Hub/Editor/2021.3.16f1/PlaybackEngines/AndroidPlayer/SDK/platform-tools/adb logcat -s Unity ActivityManager PackageManager dalvikvm DEBUG</pre><ul><li>Press Enter to start displaying the logcat logs.</li></ul><p>6. <strong>Run your game/app</strong></p><ul><li>Go through your game/app flow till the point where you’re not getting the expected result.</li><li>You’ll see errors similar to this:</li></ul><pre>AndroidJavaException: java.lang.ClassNotFoundException: com.google.unity.ads.UnityInterstitialAdCallback</pre><h3>How to prevent stripping of the necessary code?</h3><p><strong>1.Enable custom Proguard file in Unity</strong><br>Navigate to <strong>Project Settings</strong> &gt; <strong>Player </strong>&gt; <strong>Publish Settings</strong> and enable the <strong>Custom Proguard File</strong> option.<br>By using a custom Proguard file, we make sure the classes are always included in the build.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RPF2_pW2n9w2we72vZYKuw.png" /><figcaption><strong>Project Settings</strong> &gt; <strong>Player </strong>&gt; <strong>Publish Settings </strong>&gt; <strong>Custom Proguard File</strong></figcaption></figure><p><strong>2. Modify the Proguard Configuration</strong><br>Unity creates a new file called “<em>proguard-user.txt</em>” under<br><strong>Assets </strong>&gt; <strong>Plugins </strong>&gt; <strong>Android</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*25Pvzg88PXTQDRVRqhw9Pg.png" /><figcaption><strong>Assets </strong>&gt; <strong>Plugins </strong>&gt; <strong>Android </strong>&gt;<strong> proguard-user.txt</strong></figcaption></figure><p>Open this newly created file and add lines in similar fashion for each classNotFoundException you see in the logs.</p><pre># Add lines in this below format for each classNotFoundExceptions<br># in your logs from logcat.<br><br>-keep class com.google.android.gms.tasks.** { *; }</pre><ul><li>-keep: Specifies that the class or classes defined by the rule should be preserved and not removed or obfuscated during the code optimization process.</li><li>class com.google.android.gms.tasks.**: Refers to all classes and sub-packages under the com.google.android.gms.tasks package. The double asterisks (**) indicate that it includes all sub-packages and classes within the specified package.</li><li>{ *; }: Indicates that all methods and fields within the specified classes should be preserved and not removed or obfuscated.</li></ul><p>In simpler terms, this ensures that all classes, methods, and fields under the com.google.android.gms.tasks package are not removed or obfuscated during the code optimization process.</p><p><strong>3. Force Resolve Dependencies<br></strong>To ensure the proper resolution of dependencies, use the Android Resolver tool. Go to<br><strong>Assets </strong>&gt; <strong>External Dependency Manager</strong> &gt; <strong>Android Resolver</strong> &gt; <strong>Force Resolve</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*iSWXPlUv5iaFXrXZImwr9A.png" /><figcaption><strong>Assets </strong>&gt; <strong>External Dependency Manager</strong> &gt; <strong>Android Resolver</strong> &gt; <strong>Force Resolve</strong></figcaption></figure><p>4. <strong>Build and test it on your Android device.<br></strong>Keep monitoring the logcat. If everything goes right, you won’t see the errors anymore.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f165f5ef198" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>