<?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 Jonathan Mercandalli on Medium]]></title>
        <description><![CDATA[Stories by Jonathan Mercandalli on Medium]]></description>
        <link>https://medium.com/@jonathan.mercandalli_41381?source=rss-c3eebdf68fcd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ftS6wRQ_2aaltXaH</url>
            <title>Stories by Jonathan Mercandalli on Medium</title>
            <link>https://medium.com/@jonathan.mercandalli_41381?source=rss-c3eebdf68fcd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 10:54:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jonathan.mercandalli_41381/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[Le paradoxe de Monty Hall]]></title>
            <link>https://medium.com/@jonathan.mercandalli_41381/le-paradoxe-de-monty-hall-cf332f403a2c?source=rss-c3eebdf68fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf332f403a2c</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[paradox]]></category>
            <category><![CDATA[education]]></category>
            <dc:creator><![CDATA[Jonathan Mercandalli]]></dc:creator>
            <pubDate>Mon, 08 Jul 2024 21:55:35 GMT</pubDate>
            <atom:updated>2026-02-14T15:15:00.407Z</atom:updated>
            <content:encoded><![CDATA[<h4>Quand le code a aidé à me convaincre d’une vérité mathématique</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EEaLRPZXgPi8Vi46pawujQ.png" /><figcaption><em>Illustration from </em><a href="https://brilliant.org/wiki/monty-hall-problem/"><em>brilliant.org</em></a></figcaption></figure><p>Avez-vous vu le film Las Vegas 21 ? Si non, voici le problème :</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F9kagt5P1x0k%3Fstart%3D70%26feature%3Doembed%26start%3D70&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D9kagt5P1x0k&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F9kagt5P1x0k%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/70b9d2947dbfaefef6e52cc4a4da8f42/href">https://medium.com/media/70b9d2947dbfaefef6e52cc4a4da8f42/href</a></iframe><p>Vous participez à un jeu télévisé et on vous donne la possibilité de choisir entre 3 portes différentes. Derrière l’une des 3 portes, il y a une voiture, derrière les 2 autres, des chèvres.</p><ul><li>a. L’animateur vous demande de choisir une porte. Vous choisissez une porte, disons la 1.</li><li>b. Après ce choix, l’animateur, qui sait ce qu’il y a derrière chaque porte, décide d’ouvrir une autre porte derrière laquelle se trouve une chèvre, disons la 3.</li><li>c. L’animateur vous demande ensuite: “voulez-vous garder la porte numéro 1, ou souhaitez-vous changer et prendre la numéro 2 ?”</li></ul><p>Est-il dans votre intérêt de changer de choix ?</p><p>C’est là que l’intuition entre en jeu. Étant très mauvais en probabilité, je me dis que l’on me demande de choisir maintenant entre 2 portes et que j’ai donc une chance sur deux de gagner. Partant de ce principe, je dirais instinctivement que le fait de changer de porte ne change pas la probabilité.</p><p>Et là, stupeur, le film continue et j’apprends qu’il vaut mieux changer de porte. Que, soi-disant, ce changement ne donne pas 50%/50% mais bien 2/3 des chances de gagner.</p><p>En regardant le film à nouveau, celui-ci explique très rapidement la solution, mais il est très difficile de s’en convaincre. Comment être persuadé de la solution. Comment ressentir intuitivement un tel résultat ?</p><p>Ce n’est pas faute d’avoir lu l’excellente <a href="https://fr.wikipedia.org/wiki/Probl%C3%A8me_de_Monty_Hall">page Wikipedia</a> sur le sujet, et les différentes démonstrations. J’ai pourtant des souvenirs de proba’ et notamment le fameux “la proba de A sachant B”, mais même avec ça, difficile de se convaincre du résultat. Vous l’aurez compris, je ne veux pas qu’une formule me dise le résultat, je veux m’en persuader.</p><p>Heureusement, je me souviens qu’il suffit parfois, pour des problèmes “simple”, de faire du dénombrement et de compter toutes les possibilités. C’est ce que j’ai fait. Cela permet bien de démontrer la solution et le 2/3.</p><p>Ci-dessous, tous les cas possibles, avec la voiture derrière soit la porte 3, 2 ou 1, votre choix qui est soit derrière la porte 1, 2 ou 3 et le choix de l’animateur en fonction de la position de la voiture et de votre choix. Enfin, à la ligne c., le gain ou la défaite en suivant la stratégie du changement de porte.</p><pre>   | x: chèvre 🐐<br>   | v: voiture 🚗<br>   | x x v: chèvre derrière la porte 1 et 2, voiture derrière la porte 3<br>   | majuscule: votre choix à l&#39;étape a.<br>   | ⊗: la porte révélée par l&#39;animateur où il y avait une chèvre<br>   | G: gain 🚗 avec la stratégie de changer de porte<br>   | D: défaite 🐐 avec la stratégie de changer de porte<br>   | P(G) &amp; P(D): Proba de G &amp; proba de D<br>   |<br>   |<br>   |         x x v         |         x v x         |         v x x         |<br>   |   |-------|-------|   |   |-------|-------|   |   |-------|-------|   |<br>a. | X x v | x X v | x x V | X v x | x V x | x v X | V x x | v X x | v x X |<br>b. | X ⊗ v | ⊗ X v | ⊗ x V | X v ⊗ | ⊗ V x | ⊗ v X | V ⊗ x | v X ⊗ | v ⊗ X |<br>   |       |       | x ⊗ V |       | x V ⊗ |       | V x ⊗ |       |       |<br>c. |   G   |   G   |   D   |   G   |   D   |   G   |   D   |   G   |   G   |<br>   |<br>   | P(G) + P(D) = 2/3 + 1/3 = 1</pre><p>Avec cette démonstration, on se rend compte du résultat. Mais, plus que cela, elle permet de formuler le résultat ainsi. <strong>Changer de porte est gagnant dans tous les cas si une porte avec une chèvre a été choisie comme première porte. On gagne donc avec une proba de 2/3 car il y a 2 chances sur 3 d’avoir choisi une première porte avec une chèvre.</strong></p><p>À noter que l’on peut aussi se convaincre que la probabilité de changer de porte + celle ce ne pas changer fait 1. En effet, soit on change, soit on ne change pas, il n’y a que ces 2 choix possibles.</p><p>C’est bien, la démonstration permet de mieux sentir le résultat. Mais mon instinct n’est pas encore 100% convaincu. Il faut que je le vois en pratique, il faut que je “vois” les statistiques en action.</p><p>Il existe plein <a href="https://www.google.com/search?q=monty+hall+simulation&amp;sca_esv=04aa412ff406bf20&amp;sxsrf=ADLYWILBO0hWv7s_ehEHtoUoaqm7L6P1Lg%3A1720472308795&amp;ei=9FKMZr6VMLLrkdUPsOqhmAI&amp;oq=Monty+Hall+sim&amp;gs_lp=Egxnd3Mtd2l6LXNlcnAiDk1vbnR5IEhhbGwgc2ltKgIIADIFEAAYgAQyChAAGIAEGBQYhwIyBRAAGIAEMgYQABgWGB4yBhAAGBYYHjIGEAAYFhgeMgYQABgWGB4yBhAAGBYYHjIGEAAYFhgeMgYQABgWGB5I7xJQuwRY7Q1wAXgBkAEAmAFDoAGxAqoBATW4AQPIAQD4AQGYAgagAsYCwgIKEAAYsAMY1gQYR8ICChAjGIAEGCcYigXCAgQQIxgnwgIKEC4YgAQYQxiKBcICBhAAGAcYHsICChAAGIAEGEMYigXCAhkQLhiABBhDGIoFGJcFGNwEGN4EGN8E2AEBwgIIEAAYgAQYywHCAggQLhiABBjLAZgDAIgGAZAGCLoGBggBEAEYFJIHATagB6cs&amp;sclient=gws-wiz-serp">de simulations sur internet</a>. Le problème, je ne sais pas comment elles sont codées. Et bien, écrivons notre propre code.</p><p>Vous pouvez le lancer <a href="https://pl.kotl.in/i9OTRfhk_">ici et modifier le nombre d’expériences</a>.</p><pre>// How to run this code<br>// Online: copy code on https://play.kotlinlang.org/<br>// On MacOS:<br>//    - Install brew: https://brew.sh/<br>//    - Open terminal and type: &quot;brew install kotlin&quot;.<br>//    - Put this code inside &quot;math_monty_hall.main.kts&quot; file<br>//    - Run in terminal &quot;kotlinc -script ./math_monty_hall.main.kts&quot;<br><br>import kotlin.random.Random<br><br>enum class BehindDoor {<br>    CAR,<br>    GOAT<br>}<br><br>val experiencesCount = 1_000<br>var strategyChangeDoorWinCount = 0<br><br>fun main() {<br>    val experiences = (0..&lt;experiencesCount).map {<br>        listOf(BehindDoor.GOAT, BehindDoor.GOAT, BehindDoor.CAR).shuffled()<br>    }<br><br>    for (experience in experiences) {<br>        // My choice index is either 0, 1 or 2<br>        val myChoiceAtStepAIndex = Random.nextInt(3)<br><br>        // Prepare presenter choice index. Must be a Goat and != myChoiceAtStepAIndex<br>        val zeroOneTwo = mutableListOf(0, 1, 2)<br>        zeroOneTwo.remove(myChoiceAtStepAIndex)<br>        zeroOneTwo.shuffled()<br>        val tvShowPresenterRevealIndex = if (experience[zeroOneTwo[0]] == BehindDoor.GOAT) {<br>            zeroOneTwo[0]<br>        } else {<br>            zeroOneTwo[1]<br>        }<br><br>        val myChoiceAtStepCWithChangingDoorStrategyIndex = mutableSetOf(0, 1, 2).first {<br>            it != myChoiceAtStepAIndex &amp;&amp; it != tvShowPresenterRevealIndex<br>        }<br><br>        if (experience[myChoiceAtStepCWithChangingDoorStrategyIndex] == BehindDoor.CAR) {<br>            strategyChangeDoorWinCount++<br>        }<br>    }<br><br>    println(&quot;experiencesCount: $experiencesCount&quot;)<br>    println(&quot;strategyChangeDoorWinCount: $strategyChangeDoorWinCount&quot;)<br>    println(&quot;winRate: ${strategyChangeDoorWinCount / experiencesCount.toFloat()}&quot;)<br>}<br><br>main() // To comment when run from https://play.kotlinlang.org/</pre><p>Voici ce que ce code va afficher : une probabilité autour des 2/3 avec 1 000 expériences réalisées.</p><pre>experiencesCount: 1000<br>strategyChangeDoorWinCount: 685<br>winRate: 0.685</pre><p>Et bien voilà, j’espère qu’avec ces 2 approches, la démonstration et l’approche statistique avec un grand nombre d’expériences grâce à la programmation, vous serez, vous aussi, plus proche de “ressentir” le résultat de ce paradoxe, qui n’en sera plus vraiment un pour vous.</p><p><em>PS: Douter, remettre en cause, tester par soi-même, avoir des opinions et chercher à les prouver même si elles’avèrent fausses, c’est comme cela que l’on progresse.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf332f403a2c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin 2.0.0 migration guide as an Android developer]]></title>
            <link>https://medium.com/@jonathan.mercandalli_41381/kotlin-2-0-0-how-to-bump-as-an-android-dev-36cd0874619d?source=rss-c3eebdf68fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/36cd0874619d</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[compose]]></category>
            <dc:creator><![CDATA[Jonathan Mercandalli]]></dc:creator>
            <pubDate>Wed, 29 May 2024 23:36:26 GMT</pubDate>
            <atom:updated>2024-05-30T14:48:45.079Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to bump kotlin from 1.9.24 to 2.0.0 and gain 9% of compile time.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*b6tAZxRwD1b5PMvzZkhpwg.png" /><figcaption>Generated from <a href="https://code2art.jetbrains.com/">https://code2art.jetbrains.com/</a></figcaption></figure><p>As an Android Dev, here are the steps I followed to bump from 1.9.24 to 2.0.0</p><h3>1. Bump from 1.9.24 to 2.0.0</h3><p>Inside<em> &lt;root&gt;/build.gradle.kts, </em>bump classpath:</p><pre>classpath(kotlin(&quot;gradle-plugin&quot;, version = &quot;2.0.0&quot;))<br>classpath(kotlin(&quot;serialization&quot;, version = &quot;2.0.0&quot;)) // Optional</pre><p>Inside <em>&lt;root&gt;/settings.gradle.kts</em>, if you are using <a href="https://kotlinlang.org/docs/kapt.html">kapt</a>, move to <a href="https://github.com/google/ksp">ksp</a> (<a href="https://youtrack.jetbrains.com/issue/KT-68400/K2-w-Kapt-currently-doesnt-support-language-version-2.0.-Falling-back-to-1.9.">reason</a>). Then bump ksp:</p><pre>pluginManagement {<br>    plugins {<br>        // [GitHub] https://github.com/google/ksp<br>        id(&quot;com.google.devtools.ksp&quot;) version &quot;2.0.0-1.0.21&quot;<br>    }<br>}</pre><p>Inside <em>&lt;root&gt;/&lt;module&gt;/build.gradle.kts</em>, if you are using some multiplatform libraries, bump dependencies:</p><pre>implementation(&quot;org.jetbrains.kotlin:kotlin-stdlib-common:2.0.0&quot;)<br>implementation(&quot;org.jetbrains.kotlin:kotlin-stdlib:2.0.0&quot;)<br>implementation(&quot;org.jetbrains.kotlin:kotlin-test-common:2.0.0&quot;)<br>implementation(&quot;org.jetbrains.kotlin:kotlin-test-annotations-common:2.0.0&quot;)<br>// ...</pre><h3>2. Update .gitignore</h3><p>Add this line to your <em>&lt;root&gt;/.gitignore</em>:</p><pre># Since Kotlin 2.0.0, folder named &quot;.kotlin&quot; is created at compile time<br>.kotlin</pre><h3>3. If your are depending on Compose</h3><p>Compose changed <a href="https://developer.android.com/jetpack/androidx/releases/compose-kotlin#pre-release_kotlin_compatibility">compatibility</a>. With Kotlin 2.0.0+, a new <a href="https://developer.android.com/develop/ui/compose/compiler">gradle plugin</a> is now required for the compiler. Here is one way to setup the plugin:</p><p>In <em>&lt;root&gt;/build.gradle.kts</em>, add the following:</p><pre>buildscript {<br><br>  dependencies {<br><br>    // Compose UI.<br>    // [Documentation] https://developer.android.com/develop/ui/compose/compiler<br>    // [Plugin] &quot;org.jetbrains.kotlin.plugin.compose&quot;<br>    classpath(&quot;org.jetbrains.kotlin:compose-compiler-gradle-plugin:2.0.0&quot;)<br><br>    // ...<br>  }<br><br>  // ...<br>}</pre><p>In compose gradle modules, inside <em>&lt;root&gt;/&lt;module&gt;/build.gradle.kts</em>, add:</p><pre>plugins {<br><br>  // Compose UI.<br>  // [Documentation] https://developer.android.com/develop/ui/compose/compiler<br>  // [RootClasspath] org.jetbrains.kotlin:compose-compiler-gradle-plugin:...<br>  id(&quot;org.jetbrains.kotlin.plugin.compose&quot;)<br><br>  // ...<br>}</pre><p>Clean up any previous compose compiler declaration. In compose gradle modules, inside <em>&lt;root&gt;/&lt;module&gt;/build.gradle.kts</em>, remove kotlinCompilerExtensionVersion declaration:</p><pre>android {<br>  composeOptions {<br>    // https://androidx.tech/artifacts/compose.compiler/compiler/<br>    // https://developer.android.com/jetpack/androidx/releases/compose-kotlin#pre-release_kotlin_compatibility<br>    // https://developer.android.com/jetpack/androidx/releases/compose-compiler<br>    kotlinCompilerExtensionVersion = &quot;1.5.14&quot; // &lt;-- To remove<br>  }<br>}</pre><h3>4. If you were using kotlinOptions</h3><p>If you used kotlinOptions, the method is deprecated. Here the new declaration</p><pre>// Deprecated declaration<br>tasks.withType&lt;org.jetbrains.kotlin.gradle.tasks.KotlinCompile&gt; {<br>  kotlinOptions {<br>    // jvmTarget = JavaVersion.VERSION_17.toString()<br>    // freeCompilerArgs = listOf(&quot;...&quot;)<br>  }<br>}<br><br>// New declaration<br>kotlin {<br>  compilerOptions {<br>    // jvmTarget.set(JvmTarget.JVM_17)<br>    // freeCompilerArgs.add(&quot;...&quot;)<br>  }<br>}</pre><h3>5. Test and enjoy</h3><p>Run <em>./gradlew assemble</em> to be sure everything is OK.<br>Enjoy the new K2 compiler. You should have <a href="https://blog.jetbrains.com/kotlin/2024/04/k2-compiler-performance-benchmarks-and-how-to-measure-them-on-your-projects/">better compilation performances ~9%</a> =)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36cd0874619d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin sealed class and override]]></title>
            <link>https://medium.com/@jonathan.mercandalli_41381/kotlin-sealed-class-and-override-498b973d779f?source=rss-c3eebdf68fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/498b973d779f</guid>
            <category><![CDATA[sealed-classes]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Jonathan Mercandalli]]></dc:creator>
            <pubDate>Mon, 29 Apr 2024 15:06:26 GMT</pubDate>
            <atom:updated>2024-04-29T16:48:22.964Z</atom:updated>
            <content:encoded><![CDATA[<h4>Do not repeat the same mistake I’m the first to do</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*kawx5ECeySSNtEDE4MY-_Q.png" /><figcaption>Avoid this sealed class</figcaption></figure><p>TL;DR: Avoid extra field on bytecode. Move from:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d2ce932b812a6b76470a58d9597bfc8/href">https://medium.com/media/9d2ce932b812a6b76470a58d9597bfc8/href</a></iframe><p>to:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d357d8d5395958ab17e2b818c0f07193/href">https://medium.com/media/d357d8d5395958ab17e2b818c0f07193/href</a></iframe><h3>1. Example</h3><p>In Kotlin, enum represents a set of items with a constant size. Take for example a network response. It’s simple to represent the response like that.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76982f9af693fb8d533f1c10769586a5/href">https://medium.com/media/76982f9af693fb8d533f1c10769586a5/href</a></iframe><p>What if you want to add data to this response only when it’s “success”. Here comes the sealed class.</p><h3>2. To a “bad” solution</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f3d7d5198f02590cb64a4741696b24e/href">https://medium.com/media/5f3d7d5198f02590cb64a4741696b24e/href</a></iframe><p>From here, no issue.</p><p>Then, what if you want to add a common field to all sub classes. Let’s say we want to add the httpCode of the response.</p><p>One way, and the most common way to do is like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cead77d177a5a592a1f12c87ef09e801/href">https://medium.com/media/cead77d177a5a592a1f12c87ef09e801/href</a></iframe><p>Indeed, without the “open” and “override” keywords, impossible to compile if we want to keep “httpCode” on both parent and children.</p><p>Here comes the issue. When we “decompile” the code above, here is java representation of the bytecode generated. Lot of code, only three lines matters: line 2, line 19 and line 87:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cade1299aaf66c2487177fd99f124012/href">https://medium.com/media/cade1299aaf66c2487177fd99f124012/href</a></iframe><p>The issue? 3 fields will be in RAM. The field line 2 should not be on the bytecode.</p><p>How to improve the situation?</p><h3>3. “Better” solution</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d357d8d5395958ab17e2b818c0f07193/href">https://medium.com/media/d357d8d5395958ab17e2b818c0f07193/href</a></iframe><p>And as expected, no more extra field on generated parent class bytecode (viewed as Java). Fields are line 6 and 74.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5153a255c1d571af5b7bec9d38496d46/href">https://medium.com/media/5153a255c1d571af5b7bec9d38496d46/href</a></iframe><h3>Go further</h3><p>Great tool to check your code is Android Studio. Go to <em>Tools</em> &gt; <em>Kotlin</em> &gt; <em>Show Kotlin Bytecode</em>. Then click <em>Decompile</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l8avG_0t1qAin_IfgGww1Q.png" /><figcaption>Android Studio menu on Mac OS</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SelZL2INW4Y740cy9GugAg.png" /><figcaption>Decompiled code using the tool</figcaption></figure><h3>Sources</h3><ul><li>Big thanks to <a href="https://github.com/bowserf">Fred</a> 🙏💪 making me realise this. 👉 Go check his <a href="https://medium.com/@bowser-f">medium</a>.</li><li><a href="https://medium.com/@manuchekhrdev/sealed-class-in-kotlin-c2b5bff54530#:~:text=In%20summary%2C%20sealed%20classes%20provide,make%20%E2%80%9Cwhen%E2%80%9D%20expressions%20exhaustive.">Sealed Class in Kotlin</a> by <a href="https://medium.com/@manuchekhrdev">Manuchekhr Tursunov</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=498b973d779f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to root a pixel device?]]></title>
            <link>https://medium.com/@jonathan.mercandalli_41381/how-to-root-a-pixel-device-e893969ca5dd?source=rss-c3eebdf68fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/e893969ca5dd</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[google-pixel]]></category>
            <category><![CDATA[android-root-guide]]></category>
            <dc:creator><![CDATA[Jonathan Mercandalli]]></dc:creator>
            <pubDate>Fri, 22 Sep 2023 07:28:36 GMT</pubDate>
            <atom:updated>2023-09-22T09:38:42.131Z</atom:updated>
            <content:encoded><![CDATA[<h4>Become your Google Pixel super user</h4><p>This method only work for Google Pixel phones. Tested on Android 12 and Android 13.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*G6HHE6WCX05uD2N_ld-FaQ.png" /><figcaption><a href="https://unsplash.com/photos/n-KQ4-VY6Yg">Unspash image from Guido Coppa</a></figcaption></figure><h3>Why to root a device?</h3><ul><li>To reproduce ANR by underclocking the CPU</li><li>To reduce the battery consuption by underclocking the CPU</li><li>To increase your device performances with a CPU overclock</li><li>To reduce your device RAM for debug reasons</li><li>To control the WIFI more precisely</li><li>Customize your system UI</li></ul><h3>Why not-to root a device?</h3><ul><li>For security reason: if you grant SuperUser right to an app, the app has full control to your device.</li></ul><h3>Root with Magisk</h3><h4>Step 1: Preparing the computer</h4><ul><li>Open the official tool from Google <a href="https://flash.android.com/">https://flash.android.com/</a></li><li>Go to the bottom of the page and click “troubleshooting tips”</li><li>Install Google USB driver, download the zip and install the driver</li></ul><h4>Step 2: Preparing the phone</h4><ul><li>Go to the settings &gt; about and click the build number to be a developer</li><li>Click developer Option, unlock OEM unlock and enable USB debugging</li><li>Connect your phone to your computer and accept the popup</li></ul><h4>Step 3: Unlocking the bootloader</h4><ul><li>Go to <a href="https://flash.android.com/">https://flash.android.com/</a></li><li>Select select the last public release for your device</li><li>Uncheck the “Lock bootloader”, “Skip Secondary”, “Force debuggable”</li><li>Check “Wip Device”, “Force Flash all Partitions”, “Disable Verity”, “Disable Verification”</li><li>Click Install then use the the volume button to select “Unlock the bootloader” after the phone restart</li><li>Confirm with the power button</li><li>The process should continue on computer side</li><li>Resetup the device, Developer options, USB Debugging.</li></ul><h4>Step 4: Flash Magisk</h4><ul><li>Download the Android Platform-Tools to prepare fastboot via <a href="https://developer.android.com/tools/releases/platform-tools">platform-tools</a></li><li>Download latest <a href="https://github.com/topjohnwu/Magisk/releases">Magisk apk</a> and install it</li><li>Download you phone <a href="https://developers.google.com/android/images">rom image</a></li><li>Unzip the image, then unzip the zip inside to copy the boot.img into your device</li><li>Then, with Magisk, install the boot.img file.</li><li>A file should now exists on your phone Download folder magisk_&lt;...&gt;.img</li><li>Move the magisk_&lt;...&gt;.img into your computer</li><li>Then adb reboot bootloader</li><li>Then fastboot flash boot magisk_&lt;...&gt;.img</li></ul><h3>Source</h3><p>Big thank you to <a href="https://www.youtube.com/@akvaithi">akvaithi</a> from YouTube: <a href="https://www.youtube.com/watch?v=TJBMmuMp9ZM">https://www.youtube.com/watch?v=TJBMmuMp9ZM</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e893969ca5dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Aspect ratio with reference in Jetpack Compose]]></title>
            <link>https://proandroiddev.com/aspect-ratio-with-reference-in-jetpack-compose-9bf9b79016ee?source=rss-c3eebdf68fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/9bf9b79016ee</guid>
            <category><![CDATA[user-interface]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Jonathan Mercandalli]]></dc:creator>
            <pubDate>Wed, 29 Mar 2023 10:26:31 GMT</pubDate>
            <atom:updated>2023-04-13T09:57:50.404Z</atom:updated>
            <content:encoded><![CDATA[<h4>Jetpack compose — Aspect ratio</h4><h4>Aspect ratio with reference based on parent dimension: width, height, min, max. Overload the aspect ratio Modifier.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LEok4xt3Tm5nZjwUyb7UfA.jpeg" /><figcaption><a href="https://unsplash.com/photos/Qsh64pRu6CE">Unspash image</a> by <a href="https://unsplash.com/@komarov"><strong>Komarov Egor 🇺🇦</strong></a></figcaption></figure><p>If you are an Android, desktop, web or iOS developer working with Jetpack Compose for UI design, knowing how to resize your views is essential to support freeform windows or every form factor.</p><p>In this article, we will explore how to achieve desired visual effects using Jetpack Compose <a href="https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier">Modifier</a> overload of the aspect ratio. The goal will be to use the parent’s dimensions as reference to resize Composable function.</p><p>The solution is on GitHub and JitPack.</p><p><a href="https://github.com/Mercandj/compose-aspect-ratio-reference">GitHub - Mercandj/compose-aspect-ratio-reference: Aspect Ratio with Reference based on parent on JetPack Compose</a></p><h3>Context</h3><p>With Jetpack Compose, the <a href="https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier">Modifier</a> extension <a href="https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#(androidx.compose.ui.Modifier).aspectRatio(kotlin.Float,kotlin.Boolean)">aspectRatio</a> allows you to change the size of your composable functions based on a ratio.</p><p>If you want a square view with a dynamic size based on the parent size, put an <a href="https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#(androidx.compose.ui.Modifier).aspectRatio(kotlin.Float,kotlin.Boolean)">aspectRatio</a> with a value of 1f.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec7509bc994fe6e0303465731a78592a/href">https://medium.com/media/ec7509bc994fe6e0303465731a78592a/href</a></iframe><p>If you want to display a thumbnail of a YouTube video, put ratio = 16f / 9f.</p><p>What is great about the <a href="https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#(androidx.compose.ui.Modifier).aspectRatio(kotlin.Float,kotlin.Boolean)">aspectRatio</a> is that it let you choose the matchHeightConstraintsFirst.</p><p>By default, it’s false. If you put it to true, the child height will match the parent and the child width will be adjusted accordingly to the aspectRatio.</p><h3>Problem</h3><ul><li>What if you want to have the min(parentWidth, parentHeight) as reference in order to have the child fit the parent like ImageView’s centerInside.</li><li>What if you want to have the max(parentWidth, parentHeight) as reference in order to have the child centred and cropped inside the parent like ImageView&#39;s centerCrop.</li></ul><h3>Solution: API</h3><p>The goal will be to be able to write:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/838301035e8224a86fe09824e477877e/href">https://medium.com/media/838301035e8224a86fe09824e477877e/href</a></iframe><p>with the following AspectRatioReference:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ed9d9db8bae34499037dd587b0061a8/href">https://medium.com/media/8ed9d9db8bae34499037dd587b0061a8/href</a></iframe><p>With this API, every scenario are possible on the client side. Parent’s alignement can still be use, and we can choose the reference.</p><p>Note that there is no more one ratio in float, but 2 floats to easily represent ratio. Instead of doing ratio = 16f / 9f it’s ratioWidth = 16f, ratioHeight = 9f in order to explicit numerator from denominator.</p><h3>Solution: Implementation</h3><p>Here, the fun begins.</p><p>Based on the existing <a href="https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#(androidx.compose.ui.Modifier).aspectRatio(kotlin.Float,kotlin.Boolean)">aspectRatio</a> inside Jetpack Compose <a href="https://developer.android.com/jetpack/androidx/releases/compose-foundation">androidx.compose.foundation:foundation-layout:1.4.0</a>, we will write our own extension function to overload <a href="https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier">Modifier</a>.</p><p>The main difference will be inside the function Constraints.findSize(). This is where the logic of “resizing” is done.</p><p>Here is the method we want:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b1aeabab8b2785990ec65e25ebf935a/href">https://medium.com/media/5b1aeabab8b2785990ec65e25ebf935a/href</a></iframe><p>And here, the full implementation of the solution:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/46f7b7ab686f2a637e94961eaa9e81ee/href">https://medium.com/media/46f7b7ab686f2a637e94961eaa9e81ee/href</a></iframe><h3>Solution — Preview</h3><p>To be sure the code is working, the Android Studio preview is great.<br>Here, the code to have the following preview.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pmS0_cNRQhOe5mmOMA2HkA.png" /><figcaption><strong>Jetpack Compose preview of the solution</strong> by <a href="https://mercandalli.com/"><strong>Jonathan</strong></a></figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37e263788ecf578e728076df97b40aa1/href">https://medium.com/media/37e263788ecf578e728076df97b40aa1/href</a></iframe><h3>Conclusion</h3><p>Jetpack Compose is a great tool because we can easily add new behaviours. Checking how does it work behind the scene is a great way to be aware of “How” we can “do better” or at least, “make something filling our needs”.</p><p>Do not hesitate to comment or open issues on <a href="https://github.com/Mercandj/compose-aspect-ratio-reference">the github project</a>.</p><p>How to contact me, checkout <a href="https://mercandalli.com/">mercandalli.com</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9bf9b79016ee" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/aspect-ratio-with-reference-in-jetpack-compose-9bf9b79016ee">Aspect ratio with reference in Jetpack Compose</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Protect your Android app code]]></title>
            <link>https://medium.com/@jonathan.mercandalli_41381/protect-your-android-app-code-9219d4793ae0?source=rss-c3eebdf68fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/9219d4793ae0</guid>
            <category><![CDATA[google-play]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[android-apk]]></category>
            <category><![CDATA[android-security]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Jonathan Mercandalli]]></dc:creator>
            <pubDate>Mon, 20 Mar 2023 19:04:55 GMT</pubDate>
            <atom:updated>2023-09-21T11:18:02.418Z</atom:updated>
            <content:encoded><![CDATA[<h4>Android security</h4><h4>Make app safer against decompilation with obfuscation, c++, etc</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gQnwQOneqvM5eAC6Ykojcg.png" /><figcaption>DALL.E 2 generated image: smartphone in a japan painter style</figcaption></figure><p>As an Android developer, you will face an issue.<br>Your code is available to everyone.</p><p>If someone wants to know how your app works, no matter what you do, he will succeed. In security, there is no perfect protection.</p><p>The goal of this article is to provide you with some tools and tips to protect your app. Please note that decompiling an app to copy <a href="https://eur-lex.europa.eu/legal-content/EN/ALL/?uri=celex%3A31991L0250">is not legal</a>. You should only decompile your own app.</p><p>In this article, we will cover the following topics:<br>1. How to obtain the APK file<br>2. How to decompile the code<br>3. How attackers can obtain information<br>4. How to protect against decompilation</p><h3>1. How to obtain the APK file</h3><p><strong>From your own app from android project</strong></p><ul><li>If you are the developer of the application, the command ./gradlew assembleDebug and ./gradlew assembleRelease will generate the APK files in the folder app/build/outputs/apk .</li><li>If you release your app via app bundle, you can generate app bundle via ./gradlew bundleDebug or ./gradlew bundleRelease .<br>The app bundle can be transformed into an APK via <a href="https://github.com/google/bundletool">bundletool</a>.</li></ul><p><strong>From your own app from the PlayStore</strong></p><ul><li>On the Google Play Console, the section App Bundle Explorer allows developers to download AAB or APK.</li></ul><p><strong>From any installed app</strong></p><ul><li>Android stores APK from installed app. Note that installed AAB will make multiple APKs on the device. In order to pull APKs from the device to your computer, you can do it via ADB. adb pull /data/app/...</li><li>Tips: You can download this <a href="https://play.google.com/store/apps/details?id=com.mercandalli.android.apps.launcher">launcher</a>, long press on the app drawer button and click on the “adb pull every apk button”. This will give you the ADB pull command to get every APK.</li></ul><h3>2. How to decompile the code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*8swORiJ7fcZHH0joHzNw1w.jpeg" /><figcaption>My own app decompiled, obfuscated class picked at random.</figcaption></figure><p><strong>From Android Studio</strong></p><ul><li>Drag and drop the APK or AAB file into Android Studio. Click on .dex files to a sneak peek of the bytecode.</li></ul><p><strong>From </strong><a href="https://github.com/skylot/jadx"><strong>jadx</strong></a></p><ul><li>Download the <a href="https://github.com/skylot/jadx/releases/tag/v1.4.6">latest version</a> and run the GUI. This will show you the full bytecode in a “java view”.</li></ul><p><strong>From </strong><a href="https://github.com/iBotPeaches/Apktool"><strong>apktool</strong></a></p><ul><li>You can use apktool to decompile the code either in command-line or via your own java app.</li></ul><p><strong>From online decompiler</strong></p><ul><li>There are multiple decompilers available online to decompile APKs. However, as I do not know the code behind these tools and they are not open source, I recommand using this option as a last resort.</li></ul><h3>3. How attackers can obtain information</h3><p>Multiple open doors are available for attackers. Read the decompiled app code. Read the UI displayed. Read the RAM. Read network traffic.</p><p><strong>Non minified codebase</strong><br>Some apps do not minify the code. Minification makes it harder to read decompiled by replacing methods and variables names with “a”, “b”, “c”, etc.</p><p><strong>Resources</strong><br>Android resources like strings and layout are open doors for attackers. With strings, it’s sometimes possible to know what the code is doing. Raw folder is also a great entry point.</p><p><strong>Strings<br></strong>Any string constant in the code will be fully readable.</p><p><strong>Classes that are never minified like Activity, View, @Keep…</strong><br>To have the view inflate working, the views will never be minified. So, the name and package name you give to your views and activities will be fully readable.</p><p><strong>Assets folder</strong><br>Keep in mind the assets folder is accessible without any protection. Anything you put in this folder is public.</p><p><strong>Kotlin Intrinsics<br></strong>Kotlin automatically checks nullability of variables, fields and parameters. To do that, Kotlin uses the Intrinsics class. Intrinsics check every parameter and add the name of the variable in the error message inside a readable string. This is another entry point of attack.</p><p><strong>Kotlin data class</strong><br>A Kotlin data class automatically generates the toString(). The “issue” is that the data class name and field name will be visible in the string inside the toString() method.</p><p><strong>View dump</strong><br>On a non-debug APK, the layout inspector does not work. However, you can dump the UI using uiautomator by running the command adb shell uiautomator dump. This will retrieve the entire get UI DOM of the screen displayed on your device.</p><p><strong>Rooted device</strong><br>With a rooted device, you can both, analyse the RAM at runtime, and pull the internal storage.</p><p><strong>Network<br></strong>To analyse network calls, you can use a proxy or tools like Wireshark or Charles.</p><p><strong>AndroidManifest</strong><br>The AndroidManifest is one other open door that the system will use. Indeed, the manifest lists every activity, receiver, services… By knowing the first Activity of an app, attackers can follow the call flow that the Android OS will do. So, attackers will be able to follow step by step from the Application.onCreate to every Activity.onCreate.</p><h3>4. How to protect against decompilation</h3><p><strong>Minify, shrink and Obfuscate<br></strong>The first step to protect against decompilation is to use obfuscation. Enable it via minifyEnabled in your app/build.gradle.kts. This will reduce the size of the code and make reverse engineer harder. R8 will be use using proguard files for configuration. More information can be found on the <a href="https://developer.android.com/studio/build/shrink-code">Android official documentation</a>.</p><p><strong>Never put a key in clear in string</strong><br>There are robots on internet which crawl the PlayStore and decompile apps searching for secrets via static code analysis. The main target of these robots are non-protected strings with API keys inside. To protect information inside an application, there are multiple solutions depending on the level of security you want to have. Here are some solutions:</p><p><strong>Base64, Zip, Gzip</strong><br>This is the “easier” and less robust way to protect against basic code analysis. By base64 encoding your secret, it will be more difficult to know that there is a secret in the first place.</p><p><strong>Native code via jni</strong><br>This approach is a little bit more secure than Base64 approach. But keep in mind, this still possible to decompile the .so file and read your secret.</p><p><strong>RSA &amp; AES</strong><br>Using RSA to exchange the key and AES to encrypt provides better better protection (although not perfect as there is no perfect solution).</p><p><strong>Remove Kotlin Intrinsics to not provide your field and variable name</strong><br>There is a way to remove these Kotlin nullability checks. However, keep in mind that in a fail-fast approach, this is not a good practice. At least, you will give less information and reduce a your bytecode. Great article <a href="https://simonschiller.io/posts/removing-kotlin-bloat-on-android.html">here</a> and by <a href="https://jakewharton.com/shrinking-a-kotlin-binary/">Jake Wharton</a>.</p><p><strong>Kotlin data class - toString</strong><br>To hide class name and field names, you can override your data class’s toString() method.</p><p><strong>R8 option</strong><br>R8 has an option to make attacks harder. For more information, check out <a href="https://proandroiddev.com/improving-proguard-name-obfuscation-83b27b34c52a">this great article</a>. With this option, all your minified classes will be put on the same package.</p><pre>-repackageclasses &#39;defpackage&#39;</pre><p><strong>Compose<br></strong>With the use of Jetpack Compose, there is no need for layouts, views, fragments. You may even be tempted to have a mono activity. By doing this, you will reduce the surface of attack.</p><p><strong>PlayStore anti tamper protection</strong><br><a href="https://medium.com/avi-parshan-studios/protecting-your-android-app-against-reverse-engineering-and-tampering-a727768b2e9e">Here</a> is a great article about it. Otherwise the PlayStore hase released its own anti-tamper protection.</p><p><a href="https://github.com/Mercandj/AabResGuard"><strong>AabResGuard</strong></a><strong><br></strong>Tool from bytedance that I kept up-to date with latest version of BundleTool. This tool obfuscate resources: layouts, strings...</p><h3>Conclusion</h3><p>Thank you for reading. Please remember that there is no foolproof way to protect your app. Combine the techniques of this article to avoid other developers to steal your code. Don’t hesitate to comment and provide feedback.<br>You can learn more about me on <a href="https://mercandalli.com/">mercandalli.com</a> or on <a href="https://www.linkedin.com/in/jonathan-mercandalli/">linkedin</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*051YqDSjpwVI3vsvzTrMcA.png" /><figcaption>DALL.E.2 generated image : mobile phone impressionism</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9219d4793ae0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Move Glide from kapt to ksp on Android]]></title>
            <link>https://medium.com/@jonathan.mercandalli_41381/move-from-kapt-to-ksp-in-glide-on-android-dc786cab2584?source=rss-c3eebdf68fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc786cab2584</guid>
            <category><![CDATA[ksp]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[glide]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Jonathan Mercandalli]]></dc:creator>
            <pubDate>Fri, 03 Feb 2023 12:42:20 GMT</pubDate>
            <atom:updated>2023-02-17T12:34:46.397Z</atom:updated>
            <content:encoded><![CDATA[<h4>ANDROID BUILD TIME</h4><h4>Better build performance with glide ksp on Android</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5u_hGJhlbBDfkg2f7SBX3Q.jpeg" /></figure><p>ksp is 2 times faster than kapt (<a href="https://kotlinlang.org/docs/ksp-overview.html">sources</a>).</p><p>Many libraries like Room are already working with ksp. To benefit fully from ksp performance gain over kapt, move the Glide setup is the way to go.</p><h3>Gradle plugin</h3><p>In your app build.gradle.kts</p><pre>plugins {<br><br>  // From<br>  kotlin(&quot;kapt&quot;)<br><br>  // To<br>  id(&quot;com.google.devtools.ksp&quot;)<br>}</pre><h3>Gradle dependencies</h3><p>In your app build.gradle.kts</p><pre>dependencies {<br><br>    // From<br>    implementation(&quot;com.github.bumptech.glide:glide:4.14.2&quot;)<br>    kapt(&quot;com.github.bumptech.glide:compiler:4.14.2&quot;)<br><br>    // To<br>    implementation(&quot;com.github.bumptech.glide:glide:4.14.2&quot;)<br>    ksp(&quot;com.github.bumptech.glide:ksp:4.14.2&quot;)<br>}</pre><h3>Application source code</h3><p>Remove any reference to generated code like GlideApp and GlideRequests</p><pre>// From<br>GlideApp.with(context)<br>    .load(url)<br>    .into(imageView)<br><br>// To<br>Glide.with(context)<br>    .load(url)<br>    .into(imageView)</pre><h3>Sources</h3><ul><li><a href="https://bumptech.github.io/glide/doc/download-setup.html#kotlin---ksp">https://bumptech.github.io/glide/doc/download-setup.html#kotlin---ksp</a></li><li><a href="https://github.com/bumptech/glide/issues/4492">https://github.com/bumptech/glide/issues/4492</a></li><li><a href="https://bumptech.github.io/glide/doc/generatedapi.html">https://bumptech.github.io/glide/doc/generatedapi.html</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc786cab2584" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use SwiftUI preview with UIView]]></title>
            <link>https://medium.com/mwm-io/how-to-use-swiftui-preview-for-uiview-404aad95f32e?source=rss-c3eebdf68fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/404aad95f32e</guid>
            <category><![CDATA[swiftui-previews]]></category>
            <category><![CDATA[uiview]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[uikit]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Jonathan Mercandalli]]></dc:creator>
            <pubDate>Sat, 07 Jan 2023 17:36:33 GMT</pubDate>
            <atom:updated>2023-01-08T23:30:46.042Z</atom:updated>
            <content:encoded><![CDATA[<h4>SWIFT UI PREVIEW FOR UIVIEW</h4><h4>Avoid some runs on simulator or device to make UI</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w8fo8J4SZqlnIY2N2kqjtw.png" /></figure><p>Even if you do not want to convert your views to SwiftUI, you can use the Xcode preview of SwiftUI with UIView 👀</p><h3>1. UIView example</h3><p>Here a HelloWorld custom view displaying a UILabel with “HelloWorld” like the screenshot above.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc033a063c61c82d0fc55cd89a9192f2/href">https://medium.com/media/cc033a063c61c82d0fc55cd89a9192f2/href</a></iframe><h3>2. PreviewProvider</h3><p>In order to use SwiftUI to display the Xcode preview, add the SwiftUI import.</p><p>Then, implement<br>- <strong><em>UIViewRepresentable</em></strong><em> </em>for<em> UIView<br>- </em><strong><em>UIViewControllerRepresentable</em></strong><em> </em>for<em> UIViewController</em></p><p>Finally, add a struct <strong><em>PreviewProvider</em></strong> to your class and tada 🎉<br>Opening the swift file in Xcode opens the preview.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8eeeace3bfea3cc6515db6c1f1f0378d/href">https://medium.com/media/8eeeace3bfea3cc6515db6c1f1f0378d/href</a></iframe><h3>3. Tips to go further</h3><ul><li><strong>[Preview resize]<br></strong>Inside the Preview struct, implement <a href="https://nilcoalescing.com/blog/CustomSizeForUIViewsWrappedInUIViewRepresentable/">sizeThatFits</a>.</li><li><strong>[PreviewMode]<br></strong>UIView will run on Xcode.<br>Means the <em>AppDelegate.applicationDidBecomeActive</em> and other iOS lifecycle methods will not be called.<br>So, some static fields or instances may not be reachable in preview mode.<br>Proposition: provide a boolean to the UIView to use mocks for the preview.</li><li><strong>[Crash]</strong><br>I didn’t find a way to get stacktrace when UIView is crashing in the preview mode.</li><li><strong>[Update preview]</strong><br>Close / Re-open the file reload the preview.</li><li><strong>[Show / Hide]</strong><br>Toggle via: <strong><em>Xcode menu</em></strong> &gt; <strong><em>Editor</em></strong> &gt; <strong><em>Canvas</em></strong></li></ul><p><em>Do not hesitate to comment if you have any idea to improve this article. (As an Android dev, iOS dev is pretty new for me ^^)</em></p><p><strong>Source</strong>: Thank you to <a href="https://medium.com/swlh/how-to-use-live-previews-in-uikit-204f028df3a9">Finsi Ennes article</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=404aad95f32e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mwm-io/how-to-use-swiftui-preview-for-uiview-404aad95f32e">How to use SwiftUI preview with UIView</a> was originally published in <a href="https://medium.com/mwm-io">by MWM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Memory leaks fix via Android Studio profiler ]]></title>
            <link>https://medium.com/mwm-io/memory-leaks-fix-via-android-studio-profiler-51cfcfcbe6d1?source=rss-c3eebdf68fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/51cfcfcbe6d1</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-studio]]></category>
            <category><![CDATA[memory-leak]]></category>
            <category><![CDATA[android-profiler]]></category>
            <dc:creator><![CDATA[Jonathan Mercandalli]]></dc:creator>
            <pubDate>Fri, 09 Dec 2022 18:20:31 GMT</pubDate>
            <atom:updated>2023-09-19T09:33:47.854Z</atom:updated>
            <content:encoded><![CDATA[<h4>Android Studio Profiler</h4><h4>How to use profiler to find reasons of memory leak?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n9lUP2RhlErdpC6IcTnB9w.png" /></figure><h3>Introduction</h3><p><strong>What is a memory leak?<br></strong>When garbage collector cannot free memory.</p><p><strong>Symptom?</strong><br>When memory grow indefinitely, causing weak performances, ANR, or crashes.</p><p><strong>Main cause on Android?</strong><br>Activity destruction, for example when screen rotate.<br>When a reference of Activity is kept in a “static object”, the memory cannot be free.</p><h3>Example</h3><p>Here a leaking activity.</p><ul><li><em>listener</em> has a reference to the <em>MainActivity</em> via the lambda</li><li><em>onCreate</em> add the <em>listener</em> to a static <em>manager</em></li><li>So, <em>MainActivity</em> cannot be garbage collected</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/922ae85d6e38535390a5f8042b372d11/href">https://medium.com/media/922ae85d6e38535390a5f8042b372d11/href</a></iframe><p>At each screen rotation, new <em>Activity</em> is created. The manager is unique. The <em>manager set of listeners</em> will grow keeping activities alive and keeping <em>largeObject</em> alive.</p><p>Full project available here: <a href="https://github.com/Mercandj/memory-leak-android/blob/main/app/src/main/java/com/medium/MainActivity.kt">memory-leak-android</a>.</p><h3>Cause and non-cause of leak</h3><p><strong>What is a scope?</strong><br>A scope is a chain of reference.<br>A root reference is the reference of the scope that retain the scope to be free from the garbadge collector point of view.<br>A scope is considered as “static” when the root reference is kept on a “static” variable (like singleton).</p><p><strong>What cause leak?<br></strong>When “a reference or a transitive reference” of “an object with lifecycle we want to garbage collect” is kept from “a static scope or a scope that persist the object scope”.</p><p><strong>What do not cause leak?</strong><br>When 2 objects of the same scope are referencing one another.<br>For exemple, a reference from a “static scope” referencing to another object reference also on a “static scope” (two manager for instance).<br>For example, a view and the activity that created the view.</p><h3>Profiler Analysis</h3><p><strong>Measure</strong></p><ol><li>Open the profiler: “<em>AndroidStudio bottom bar”</em> &gt; “<em>Profiler”</em></li><li>Select your process: “<em>SESSIONS +</em>” &gt; “<em>Device</em>” &gt; “<em>App</em>”</li><li>Click the memory chart</li><li>Run the scenario doing the leak (<em>on the sample, screen rotation</em>)</li><li>Capture the heap bump</li><li>Inspect result</li></ol><p>The profiler automatically detect leaks with a ⚠️ icon 🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDA_PjglhUuCkG_r_3utOw.png" /><figcaption>Profiler</figcaption></figure><p><strong>Tips to find leak reason #1 — Arrange by package<br></strong>Great to find only your classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O1cPSXzIAnTEv29Bm2Xpww.png" /><figcaption>Arrange by package</figcaption></figure><p><strong>Tips to find leak reason #2— Sort, Depth, Go to Instance</strong></p><ul><li>A. Check huge object by sorting</li><li>B. Find the reason with the reference tab and “nearest” checkbox</li><li>C. Navigate from reference to reference to find the reference hold</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HHjd40SNrD75DuFduHRoNg.png" /><figcaption>Sort retained size -&gt; Check references -&gt; Find reason</figcaption></figure><h3>Sources</h3><p>Highly inspired by this article <a href="https://medium.com/@umairkhalid786/the-easiest-way-to-detect-and-fix-memory-leaks-using-android-studio-profiler-tool-and-weakreference-cd7c212908a1">The easiest way to detect and fix memory leaks using Android Studio Profiler Tool and WeakReference ❤</a>.<br>Thank you <a href="https://medium.com/@umairkhalid786?source=post_page-----cd7c212908a1--------------------------------">Umair Khalid</a> ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51cfcfcbe6d1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mwm-io/memory-leaks-fix-via-android-studio-profiler-51cfcfcbe6d1">Memory leaks fix via Android Studio profiler 👀</a> was originally published in <a href="https://medium.com/mwm-io">by MWM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Make a Desktop  Jetpack Compose App]]></title>
            <link>https://medium.com/better-programming/tutorial-jetpack-compose-how-to-create-a-desktop-app-6e6e9392ac90?source=rss-c3eebdf68fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e6e9392ac90</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Jonathan Mercandalli]]></dc:creator>
            <pubDate>Wed, 01 Jun 2022 18:11:53 GMT</pubDate>
            <atom:updated>2022-12-09T14:09:14.081Z</atom:updated>
            <content:encoded><![CDATA[<h4>Jetpack Compose</h4><h3>How to Make a Jetpack Compose Desktop App</h3><h4>A hands-on tutorial</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*an-uZN62pEGaqjsw" /><figcaption>Photo by <a href="https://unsplash.com/@claybanks?utm_source=medium&amp;utm_medium=referral">Clay Banks</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this tutorial, you will learn the minimum to create a desktop HelloWorld app with Jetpack Compose for Desktop in Kotlin.</p><ul><li><strong>Level:</strong> For beginners in compose for desktop</li><li><strong>Requirements:</strong> Java installed</li><li><strong>Final sample:</strong> <a href="https://github.com/Mercandj/jetpack-compose-desktop-hello-world">github</a>.</li><li><strong>Final UI</strong>:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*yPndxNqAhBvmZqtAchJaRQ.png" /></figure><h3>1. Setup the project</h3><p>First, in order to set up the project, you will need a Gradle project skeleton with a root build.gradle, settings.gradle and app/build.gradle. <br>Let’s do that using kts files to use only one language: Kotlin ❤️</p><p><strong>build.gradle.kts</strong> <br>Create the build.gradle.kts at the root of the project with the following to define the gradle project with compose maven.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8645b34ff9c9872473a05202fc48442/href">https://medium.com/media/f8645b34ff9c9872473a05202fc48442/href</a></iframe><p><strong>settings.gradle.kts </strong><br>Add at the root of the project the settings.gradle.kts to define the name of the project and the gradle module app.</p><pre><em>rootProject</em>.<em>buildFileName </em>= &quot;build.gradle.kts&quot;<br><em>rootProject</em>.<em>name </em>= &quot;medium-proto&quot;<br>include(&quot;:app&quot;)</pre><p><strong>app/build.gradle.kts </strong><br>Add to app/build.gradle.kts the plugin for compose:</p><pre>plugins <strong>{<br>    </strong><em>kotlin</em>(&quot;jvm&quot;)<br><em>    // </em><a href="https://github.com/JetBrains/compose-jb/releases"><em>https://github.com/JetBrains/compose-jb/releases</em></a><br>    id(&quot;org.jetbrains.compose&quot;) <em>version </em>&quot;1.2.0-alpha01-dev686&quot;<br><strong>}</strong></pre><p>Then add the dependency:</p><pre>dependencies <strong>{<br>    </strong><em>implementation</em>(<em>compose</em>.desktop.currentOs)<br><strong>}</strong></pre><p>Finally, define the application entry point:</p><pre><em>compose</em>.<em>desktop</em>.application.mainClass = &quot;com.medium.MainKt&quot;</pre><h4><strong>Final touches</strong></h4><p>Then, in order to compile the app, add to the root of the project a gradlew file and gradle folder. <a href="https://docs.gradle.org/current/userguide/gradle_wrapper.html#sec:adding_wrapper">Here</a>’s how to get the file. On MacOS, you can do it with this command on your root project: brew install gradle &amp;&amp; gradle wrapper.</p><h3>2. Create the main view</h3><p>Create a kotlin file app/src/main/kotlin/com/medium/Main.kt with</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e72c5048c8bc2bf6a1461b89951c2cf/href">https://medium.com/media/6e72c5048c8bc2bf6a1461b89951c2cf/href</a></iframe><p>This file contains the application definition with a Window containing</p><ul><li>onCloseRequest: The behaviour to close the app when the window close button is clicked</li><li>state: The size of the window in dp, the metric measure.</li><li>title: the title on the top bar of the window.</li></ul><p>Inside the lambda of the Window method, you can write JetPack Compose code “like” on an Android app. Here a Box in max-width and max-height has been added in order to center the text into the window. The Box is a container that allows the Text to have a Center alignement.</p><h3>3. Build and launch the app</h3><p>Get the permission to run the script via the command chmod 755 ./gradlew<br>Then, run ./gradlew run and tada:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*yPndxNqAhBvmZqtAchJaRQ.png" /></figure><p>Thank you to the JetBrains team and JetPack Compose and <a href="https://github.com/JetBrains/compose-jb">JetPack Compose Desktop</a> contributors.</p><h4><strong>To go further</strong></h4><ul><li>How to create a MacOS install file pkg to avoid using jar: use <a href="https://docs.oracle.com/en/java/javase/14/docs/specs/man/jpackage.html">jpackage</a></li><li>How to add an app icon: cf samples <a href="https://github.com/JetBrains/compose-jb">in this project</a></li><li>How to release as a native app to avoid jvm: cf <a href="https://github.com/JetBrains/compose-jb/blob/master/tutorials/Native_distributions_and_local_execution/README.md">this same repositor</a>y</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e6e9392ac90" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/tutorial-jetpack-compose-how-to-create-a-desktop-app-6e6e9392ac90">How to Make a Desktop  Jetpack Compose App</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>