<?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 Areeb Momin on Medium]]></title>
        <description><![CDATA[Stories by Areeb Momin on Medium]]></description>
        <link>https://medium.com/@aribmomin111?source=rss-3827babc2c9b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*BNIDR1AnfdzVeJW8TNakqg.jpeg</url>
            <title>Stories by Areeb Momin on Medium</title>
            <link>https://medium.com/@aribmomin111?source=rss-3827babc2c9b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 03:12:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aribmomin111/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[Deploy Flutter to Firebase App Distribution in Single Click (Android Studio)]]></title>
            <link>https://medium.com/@aribmomin111/deploy-flutter-to-firebase-app-distribution-in-single-click-android-studio-dd4d3c77e666?source=rss-3827babc2c9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd4d3c77e666</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[android-studio]]></category>
            <category><![CDATA[firebase-app-distribution]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Areeb Momin]]></dc:creator>
            <pubDate>Sun, 17 Nov 2024 09:04:38 GMT</pubDate>
            <atom:updated>2024-11-17T09:04:38.492Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tC9nJTN7qU-IVx1_NJ2pUA.png" /></figure><p>Are you tired of repetitive build-sharing tasks? This guide shows you how to automate Flutter Android and iOS builds and push them to <a href="https://firebase.google.com/docs/app-distribution">Firebase App Distribution</a> with a single click in Android Studio. Simplify sharing with QA, maintain build history, and boost your workflow efficiency - effortlessly!</p><h3><strong>What is Firebase App Distribution?</strong></h3><p><a href="https://firebase.google.com/docs/app-distribution">Firebase App Distribution</a> is a powerful tool for sharing pre-release versions of your app with testers. It simplifies the distribution of Android and iOS builds by offering a central platform to upload, manage, and share builds. Testers receive updates instantly, and you can track feedback and crashes seamlessly. With build history and easy integration into CI/CD pipelines, Firebase App Distribution keeps your testing process efficient and organized.</p><h3>Result:</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F-7tnmf1WyPI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D-7tnmf1WyPI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F-7tnmf1WyPI%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3396c35a6c0e192a378a74f33f8c6bbc/href">https://medium.com/media/3396c35a6c0e192a378a74f33f8c6bbc/href</a></iframe><h3>Steps:</h3><p><strong>1. Create Shell Scripts:</strong></p><p><strong>a) For APK:</strong></p><p>Follow this doc: <a href="https://firebase.google.com/docs/app-distribution/android/distribute-cli?hl=en&amp;authuser=0&amp;apptype=apk">APK App Distribution Doc</a></p><pre>// upload_release_apk.sh<br><br>#!/bin/bash<br><br># create APK<br>cd YOUR_PROJECT_ROOT_PATH || exit 1<br>flutter build apk<br><br># Navigate to the directory containing your APK<br>cd build/app/outputs/flutter-apk/ || exit 1<br><br># Prompt the user for the release notes message<br>echo &quot;Enter the release notes message:&quot;<br>read RELEASE_NOTES<br><br># Run the Firebase App Distribution command with the input message<br>firebase appdistribution:distribute app-release.apk --app YOUR_FIREBASE_ANDROID_APP_ID --release-notes &quot;$RELEASE_NOTES&quot; --groups &quot;TESTER_GROUP_ALIAS&quot;</pre><p><strong>b) For IPA:</strong></p><p>Follow this doc: <a href="https://firebase.google.com/docs/app-distribution/ios/distribute-cli?hl=en&amp;authuser=0">IPA App Distribution Doc</a></p><pre>// upload_debug_ipa.sh<br><br>#!/bin/bash<br><br># create IPA<br>cd YOUR_PROJECT_ROOT_PATH || exit 1<br>flutter build ipa<br><br># Extract version from pubspec.yaml<br>VERSION=$(grep &#39;^version:&#39; pubspec.yaml | sed &#39;s/version: //;s/+.*//&#39;)<br><br># Navigate to the directory containing your IPA<br>cd build/ios/ipa/ || exit 1<br><br># Prompt the user for the release notes message<br>echo &quot;Enter the release notes message:&quot;<br>read RELEASE_NOTES<br><br># Run the Firebase App Distribution command with the input message<br>firebase appdistribution:distribute $VERSION.ipa --app YOUR_FIREBASE_IOS_APP_ID --release-notes &quot;$RELEASE_NOTES&quot; --groups &quot;TESTER_GROUP_ALIAS&quot;</pre><p><strong>2. Add External Tool in Android Studio:</strong></p><p>a) Navigate to ‘<em>Android Studio</em>’ -&gt; ‘<em>Settings</em>’ -&gt; ‘<em>Tools</em>’ -&gt; ‘<em>External Tools</em>’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*La8GqpRS4tK1Grhwns-1Tg.png" /><figcaption>External Tools Window</figcaption></figure><p>b) Click on the ‘<em>+</em>’ icon to create a new External Tool and add the following details:</p><p>Name: <em>Upload APK<br></em>Description: <em>Upload APK to Firebase App Distribution</em></p><p>c) In the ‘<em>Program</em>’ text field click the ‘<em>Browse</em>’ button and choose the associated shell script.</p><p>d) Click on ‘<em>OK</em>’ -&gt; ‘<em>Apply</em>’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dhcSbmj5-pNLCboAzvlsOw.png" /><figcaption>Create External Tool Window</figcaption></figure><p><strong>3. Add External Tool to Toolbar:</strong></p><p>a) Navigate to ‘<em>Android Studio</em>’ -&gt; ‘<em>Settings</em>’ -&gt; ‘<em>Appearance &amp; Behaviour</em>’ -&gt; ‘<em>Menus and Toolbars</em>’. Expand ‘<em>Main Toolbar</em>’ -&gt; ‘<em>Center</em>’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K_h_sOM5vKv1qSFioRf_mw.png" /><figcaption>Menus and Toolbars Window</figcaption></figure><p>b) Then click ‘<em>Center</em>’ -&gt; ‘<em>+</em>’ -&gt; ‘<em>Add Action…</em>’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rJnGFgxvEV5Yh6aIkWwehA.png" /><figcaption>Add Action Popup</figcaption></figure><p>c) In the Add Action window, Expand ‘<em>External Tools</em>’ -&gt; ‘<em>External Tools</em>’. Then click ‘<em>Upload APK</em>’. Choose the Icon of your choice, then click ‘<em>OK</em>’ -&gt; ‘<em>Apply</em>’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7_TRE1rPEBY5dlcFAjBbzA.png" /><figcaption>Add Action Window</figcaption></figure><p>That’s it, The External Tool shortcut will appear on the Toolbar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FBIAunA6d1kJc-VaGvIyiA.png" /><figcaption>Toolbar with External Tool shortcut</figcaption></figure><h3>Advanced:</h3><p><strong>A. For AAB (Android App Bundle):</strong></p><p>Follow this doc: <a href="https://firebase.google.com/docs/app-distribution/android/distribute-console?hl=en&amp;authuser=0&amp;apptype=aab">AAB App Distribution Doc</a></p><pre>// upload_release_aab.sh<br><br>#!/bin/bash<br><br># create AAB<br>cd YOUR_PROJECT_ROOT_PATH || exit 1<br>flutter build appbundle<br><br># Navigate to the directory containing your AAB<br>cd build/app/outputs/bundle/release/ || exit 1<br><br># Prompt the user for the release notes message<br>echo &quot;Enter the release notes message:&quot;<br>read RELEASE_NOTES<br><br># Run the Firebase App Distribution command with the input message<br>firebase appdistribution:distribute app-release.aab --app YOUR_FIREBASE_ANDROID_APP_ID --release-notes &quot;$RELEASE_NOTES&quot; --groups &quot;TESTER_GROUP_ALIAS&quot;</pre><p><strong>B. IPA creation for Auto-signing disabled case:</strong></p><p>Upload Script:</p><pre>// upload_debug_ipa.sh<br><br>#!/bin/bash<br><br># create IPA<br>cd YOUR_PROJECT_ROOT_PATH || exit 1<br>flutter build ipa --export-options-plist ios/ExportOptions.plist<br><br># Extract version from pubspec.yaml<br>VERSION=$(grep &#39;^version:&#39; pubspec.yaml | sed &#39;s/version: //;s/+.*//&#39;)<br><br># Navigate to the directory containing your IPA<br>cd build/ios/ipa/ || exit 1<br><br># Prompt the user for the release notes message<br>echo &quot;Enter the release notes message:&quot;<br>read RELEASE_NOTES<br><br># Run the Firebase App Distribution command with the input message<br>firebase appdistribution:distribute $VERSION.ipa --app YOUR_FIREBASE_IOS_APP_ID --release-notes &quot;$RELEASE_NOTES&quot; --groups &quot;TESTER_GROUP_ALIAS&quot;</pre><p>ExportOptions.plist file:</p><p>Save <em>ExportOptions.plist</em> file in the <em>ios</em> directory.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;<br>&lt;plist version=&quot;1.0&quot;&gt;<br>&lt;dict&gt;<br>    &lt;key&gt;method&lt;/key&gt;<br>    &lt;string&gt;development&lt;/string&gt;<br>    &lt;key&gt;provisioningProfiles&lt;/key&gt;<br>    &lt;dict&gt;<br>        &lt;key&gt;YOUR_BUNDLE_ID&lt;/key&gt;<br>        &lt;string&gt;YOUR_DEVELOPMENT_PROVISIONING_PROFILE_NAME&lt;/string&gt;<br>    &lt;/dict&gt;<br>    &lt;key&gt;signingStyle&lt;/key&gt;<br>    &lt;string&gt;manual&lt;/string&gt;<br>    &lt;key&gt;signingCertificate&lt;/key&gt;<br>    &lt;string&gt;Apple Development&lt;/string&gt;<br>    &lt;key&gt;teamID&lt;/key&gt;<br>    &lt;string&gt;YOUR_TEAM_ID&lt;/string&gt;<br>&lt;/dict&gt;<br>&lt;/plist&gt;</pre><p><strong>C. For Flutter Flavors Case:</strong></p><p><strong>Build Creation Flow Script:</strong></p><p>I) Create the below script under the ‘<em>app_distribution_scripts</em>’ directory.</p><p>II) Create all your flavor-specific build creation scripts under the ‘<em>app_distribution_scripts/upload_scripts</em>’ directory. Each file should follow the naming convention as ‘${flavor}_${os}.sh’, for example ‘<em>free_android.sh</em>’. Follow above APK/AAB/IPA upload scripts to create each file, respectively.</p><pre>// build_configuration_menu_flow_script.sh<br><br>#!/bin/bash<br><br># Change to the project root directory first<br>cd YOUR_PROJECT_ROOT_PATH || exit 1<br><br># Function to handle cursor movement and menu<br>menu() {<br>    # Array of menu options<br>    local options=(&quot;$@&quot;)<br>    local selected=0<br>    local key_input=&quot;&quot;<br>    <br>    # Hide cursor<br>    tput civis<br>    <br>    # Function to print menu<br>    print_menu() {<br>        local idx=0<br>        for item in &quot;${options[@]}&quot;; do<br>            if [ $idx -eq $selected ]; then<br>                echo -e &quot; &gt; ${item}&quot;<br>            else<br>                echo -e &quot;   ${item}&quot;<br>            fi<br>            ((idx++))<br>        done<br>    }<br>    <br>    # Print the title only once<br>    echo -e &quot;\n$title&quot;<br>    <br>    # Show initial menu<br>    print_menu<br>    <br>    # Handle key input<br>    while true; do<br>        # Read a single key input<br>        read -rsn1 key_input<br>        <br>        # Handle special keys (arrow keys)<br>        if [[ $key_input == $&#39;\x1b&#39; ]]; then<br>            read -rsn2 key_input<br>            case $key_input in<br>                &#39;[A&#39;) # Up arrow<br>                    if [ $selected -gt 0 ]; then<br>                        ((selected--))<br>                    fi<br>                    ;;<br>                &#39;[B&#39;) # Down arrow<br>                    if [ $selected -lt $((${#options[@]}-1)) ]; then<br>                        ((selected++))<br>                    fi<br>                    ;;<br>            esac<br>        elif [[ $key_input == &#39;&#39; ]]; then # Enter key<br>            # Show cursor again<br>            tput cnorm<br>            return $selected<br>        fi<br>        <br>        # Move cursor up to overwrite the previous menu without clearing the screen<br>        tput cuu $(( ${#options[@]} ))<br>        print_menu<br>    done<br>}<br><br># Function to handle Flavour selection<br>select_flavour() {<br>    local title=&quot;Select Flavour:&quot;<br>    menu &quot;Free&quot; &quot;Premium&quot;<br>    flavour_choice=$?<br>    <br>    case $flavour_choice in<br>        0) flavour=&quot;free&quot;;;<br>        1) flavour=&quot;premium&quot;;;<br>    esac<br>}<br><br># Function to handle operating system selection<br>select_os() {<br>    local title=&quot;Select OS:&quot;<br>    menu &quot;Android&quot; &quot;iOS&quot;<br>    os_choice=$?<br>    <br>    case $os_choice in<br>        0) os=&quot;android&quot;;;<br>        1) os=&quot;ios&quot;;;<br>    esac<br>}<br><br># Start the main menu<br>select_flavour<br>select_os<br><br># Print all selected values<br>echo -e &quot;\n creating $flavour $os build...\n&quot;<br><br># Construct the script name<br>script_name=&quot;./app_distribution_scripts/upload_scripts/${flavour}_${os}.sh&quot;<br><br># Check if the script exists, then execute it<br>if [[ -f &quot;$script_name&quot; ]]; then<br>    echo -e &quot;\nRunning script: $script_name&quot;<br>    bash &quot;$script_name&quot;<br>else<br>    echo -e &quot;\nScript $script_name not found.&quot;<br>fi</pre><p><strong>External Tool creation:</strong></p><p>I) Create an external Tool with the below details:<br> Name: <em>Upload Flutter Flavor build</em><br> Description: <em>Upload Flutter Flavor build to Firebase App Distribution</em><br> Program: <em>/usr/bin/open</em><br> Arguments: <em>-a Terminal “app_distribution_scripts/build_configuration_menu_flow_script.sh”</em></p><p>II) This external tool will run the above script in an external terminal, as Android Studio’s terminal is not interactive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JdJiw36v_fnOclj2rUDEyQ.png" /></figure><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XN_vgjOwRbkZDwkEQTCtiA.png" /><figcaption>Flutter Flavour Build Creation Terminal</figcaption></figure><p>Drop your suggestions and improvements in the comment below. Peace.</p><p>Connect with me on <a href="https://www.linkedin.com/in/areeb-momin/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd4d3c77e666" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Maps in Compose Multiplatform]]></title>
            <link>https://medium.com/@aribmomin111/google-maps-in-compose-multiplatform-4db4badffb6f?source=rss-3827babc2c9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4db4badffb6f</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[google-maps]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[compose-multiplatform]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <dc:creator><![CDATA[Areeb Momin]]></dc:creator>
            <pubDate>Sun, 22 Sep 2024 10:35:21 GMT</pubDate>
            <atom:updated>2024-09-22T10:35:21.650Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jaifkmx_MEW-pwRNUDtP8A.jpeg" /><figcaption>Map Thumbnail (AI Generated)</figcaption></figure><h3>Introduction:</h3><p>Compose Multiplatform is a Kotlin-based UI framework that allows developers to build cross-platform user interfaces for Android, iOS, Desktop, and Web using a shared codebase. It extends Jetpack Compose, enabling code reuse and seamless integration with platform-specific UI frameworks like SwiftUI on iOS. As <a href="https://mapsplatform.google.com/">Google Maps</a> is not available for <a href="https://www.jetbrains.com/lp/compose-multiplatform/">Compose Multiplatform</a> we have integrated native SDK’s for Android and iOS.</p><h3>Result:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*wwGZetVhP2MCZV98qDILFw.gif" /><figcaption>Google Maps in Comopose Multiplatform</figcaption></figure><h3>Sample Project:</h3><p><a href="https://github.com/areebmomin/Google-Maps-CMP?tab=readme-ov-file">GitHub - areebmomin/Google-Maps-CMP: Google Maps integration in Compose Multiplatform</a></p><h3>Get API Key:</h3><p><a href="https://developers.google.com/maps/get-started#api-key">Getting started with Google Maps Platform | Google for Developers</a></p><h3>Let’s Code:</h3><h4>In commonMain:</h4><p>Add <strong>expect</strong> composable in commonMain:</p><pre>@Composable<br>expect fun MapComponent()</pre><h4>In androidMain:</h4><p>Add dependency in module-level build.gradle.kts file:</p><pre>implementation(&quot;com.google.maps.android:maps-compose:6.1.0&quot;)</pre><p>Add API key in AndroidManifest.xml under &lt;application&gt; tag:</p><pre>&lt;meta-data<br>    android:name=&quot;com.google.android.geo.API_KEY&quot;<br>    android:value=&quot;MAPS_API_KEY&quot; /&gt;</pre><blockquote>For best practices for adding <strong>Maps API</strong> key in <strong>Android</strong> follow the below Doc:</blockquote><blockquote>Note: Sample project follows this best practice.</blockquote><p><a href="https://developers.google.com/maps/documentation/android-sdk/start#add-key">Maps SDK for Android Quickstart | Google for Developers</a></p><p>Implement <strong>actual</strong> composable in androidMain:</p><pre>@Composable<br>actual fun MapComponent() {<br>    Box(<br>        modifier = Modifier.fillMaxSize(),<br>    ) {<br>        val coordinates = LatLng(19.068857, 72.833)<br>        val markerState = rememberMarkerState(position = coordinates)<br>        val cameraPositionState = rememberCameraPositionState {<br>            position = CameraPosition.fromLatLngZoom(coordinates, 10f)<br>        }<br>        GoogleMap(<br>            modifier = Modifier.fillMaxSize(),<br>            cameraPositionState = cameraPositionState<br>        ) {<br>            Marker(<br>                state = markerState,<br>                title = &quot;Bandra West&quot;,<br>                snippet = &quot;Mumbai&quot;<br>            )<br>        }<br>    }<br>}</pre><p><strong>In iosMain:</strong></p><p>Update MainViewController.kt to add <strong>MapViewController</strong> callback:</p><pre>fun MainViewController(<br>    mapUIViewController: () -&gt; UIViewController<br>) = ComposeUIViewController {<br>    mapViewController = mapUIViewController<br>    App()<br>}<br><br>lateinit var mapViewController: () -&gt; UIViewController</pre><p>Implement <strong>actual</strong> composable in iosMain:</p><pre>@OptIn(ExperimentalForeignApi::class)<br>@Composable<br>actual fun MapComponent() {<br>    UIKitViewController(<br>        factory = mapViewController,<br>        modifier = Modifier.fillMaxSize(),<br>    )<br>}</pre><p><strong>In iosApp:</strong></p><p>Add dependency for <strong>Google Maps</strong> via <strong>Swift Package Manager</strong>:</p><p><a href="https://developers.google.com/maps/documentation/ios-sdk/config#swift-package-manager">Set up an Xcode project | Maps SDK for iOS | Google for Developers</a></p><p>Provide API key on App’s init():</p><pre>@main<br>struct iOSApp: App {<br>    init() {<br>        GMSServices.provideAPIKey(&quot;YOUR_API_KEY&quot;)<br>    }<br>    <br>    var body: some Scene {<br>        WindowGroup {<br>            ContentView()<br>        }<br>    }<br>}</pre><p>Create <strong>GoogleMapView</strong> in SwiftUI:</p><pre>struct GoogleMapView: UIViewRepresentable {<br>    func makeUIView(context: Context) -&gt; GMSMapView {<br>        let options = GMSMapViewOptions()<br>        options.camera = GMSCameraPosition.camera(withLatitude: 12.952636, longitude: 77.653059, zoom: 10.0)<br><br>        let mapView = GMSMapView(options: options)<br><br>        // Creates a marker in the center of the map.<br>        let marker = GMSMarker()<br>        marker.position = CLLocationCoordinate2D(latitude: 12.952636, longitude: 77.653059)<br>        marker.title = &quot;Indiranagar&quot;<br>        marker.snippet = &quot;Bengaluru&quot;<br>        marker.map = mapView<br>        <br>        return mapView<br>    }<br><br>    func updateUIView(_ uiView: GMSMapView, context: Context) {}<br>}</pre><p>Provide <strong>GoogleMapView</strong> in MainViewController’s callback:</p><pre>struct ComposeView: UIViewControllerRepresentable {<br>    func makeUIViewController(context: Context) -&gt; UIViewController {<br>        MainViewControllerKt.MainViewController(<br>            mapUIViewController: { () -&gt; UIViewController in<br>                return UIHostingController(rootView: GoogleMapView())<br>            }<br>        )<br>    }<br><br>    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}<br>}</pre><p>That’s it!</p><p>Drop your suggestions and improvements in the comment below. Peace.</p><p>Connect with me on <a href="https://www.linkedin.com/in/areeb-momin/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4db4badffb6f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking Proto DataStore Magic in KMM]]></title>
            <link>https://medium.com/@aribmomin111/unlocking-proto-datastore-magic-in-kmm-d397f40a0805?source=rss-3827babc2c9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d397f40a0805</guid>
            <category><![CDATA[data-stores]]></category>
            <category><![CDATA[protobuf]]></category>
            <category><![CDATA[kmm]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Areeb Momin]]></dc:creator>
            <pubDate>Sat, 22 Jun 2024 08:43:06 GMT</pubDate>
            <atom:updated>2024-10-17T19:00:56.479Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M6YQBMJHStQLLWrwiM2Grw.jpeg" /><figcaption>KMM</figcaption></figure><p>In the rapidly evolving world of mobile development, Kotlin Multiplatform Mobile (KMM) enables developers to write shared code for Android and iOS applications. Among the key challenges is finding efficient and reliable key-value data storage solutions (like SharedPreference in Android or NSUserDefaults in iOS). This article explores integrating <a href="https://developer.android.com/topic/libraries/architecture/datastore#proto-datastore">Proto DataStore</a> a robust and type-safe solution into a KMM project.</p><h3>DataStore</h3><p>Jetpack <a href="https://developer.android.com/topic/libraries/architecture/datastore">DataStore</a> is a data storage solution that allows you to store key-value pairs or typed objects with <a href="https://protobuf.dev/">protocol buffers</a>. DataStore uses Kotlin coroutines and Flow to store data asynchronously, consistently, and transactional.</p><p>DataStore provides two different implementations:</p><ul><li><strong>Preferences DataStore</strong> stores and accesses data using keys. This implementation does not require a predefined schema, and it does not provide type safety.</li><li><strong>Proto DataStore</strong> stores data as instances of a custom data type. This implementation requires you to define a schema using protocol buffers, but it provides type safety.</li></ul><blockquote>“It is strongly recommended that you use protocol buffers which provide immutability guarantees, a simple API, and efficient serialization.” ~ Doc</blockquote><p>As Google has now made <a href="https://android-developers.googleblog.com/2023/04/whats-new-in-jetpack-multiplatform.html">DataStore Multiplatform</a>!</p><p>In this article, we will implement Proto <a href="https://developer.android.com/kotlin/multiplatform/datastore">DataStore in KMM</a>, to take advantage of Protocol Buffer in KMM, we have used <a href="https://square.github.io/wire/">Wire</a>.</p><h3>Full Code</h3><p><a href="https://github.com/areebmomin/Proto-DataStore-KMM">GitHub - areebmomin/Proto-DataStore-KMM</a></p><h3>Step-by-step implementation</h3><ul><li>Add DataStore dependency in app/build.gradle.kts</li></ul><pre>commonMain.dependencies {<br>  // your other dependencies<br>  implementation(&quot;androidx.datastore:datastore-core-okio:1.1.1&quot;)<br>}</pre><ul><li>Add the Wire Gradle plugin in app/build.gradle.kts</li></ul><pre>plugins {<br>  // your other plugins<br>  id(&quot;com.squareup.wire&quot;) version &quot;5.0.0-alpha03&quot;<br>}</pre><ul><li>Add Wire Gradle configuration in app/build.gradle.kts</li></ul><pre>wire {<br>    kotlin {}<br>    sourcePath {<br>        srcDir(&quot;src/commonMain/proto&quot;)<br>    }<br>}</pre><ul><li>Create preference_data.proto file under src/commonMain/proto directory</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*130B3PIuN3IGrPWRv626qQ.png" /><figcaption>Proto Directory Structure</figcaption></figure><pre>// preference_data.proto file<br><br>syntax = &quot;proto3&quot;;<br><br>package com.areeb.proto_datastore_kmm;<br><br>message PreferenceData {<br>  int32 counter = 1;<br>}</pre><ul><li>Create a Protocol Buffer serializer for PreferenceData</li></ul><pre>// inside `commonMain`<br>// PreferenceSerializer.kt<br><br>object PreferenceSerializer : OkioSerializer&lt;PreferenceData&gt; {<br>    override val defaultValue: PreferenceData<br>        get() = PreferenceData()<br><br>    override suspend fun readFrom(source: BufferedSource): PreferenceData {<br>        try {<br>            return PreferenceData.ADAPTER.decode(source)<br>        } catch (exception: IOException) {<br>            throw Exception(exception.message ?: &quot;Serialization Exception&quot;)<br>        }<br>    }<br><br>    override suspend fun writeTo(t: PreferenceData, sink: BufferedSink) {<br>        sink.write(t.encode())<br>    }<br>}</pre><ul><li>Create a Proto DataStore instance for each platform (here Android and iOS)</li></ul><pre>// inside `commonMain`<br>// DataStore.kt<br><br>internal const val DATA_STORE_FILE_NAME = &quot;proto_datastore.preferences_pb&quot;<br><br>expect fun getDataStore(): DataStore&lt;PreferenceData&gt;<br><br>fun createDataStore(<br>    fileSystem: FileSystem,<br>    producePath: () -&gt; Path<br>): DataStore&lt;PreferenceData&gt; =<br>    DataStoreFactory.create(<br>        storage = OkioStorage(<br>            fileSystem = fileSystem,<br>            producePath = producePath,<br>            serializer = PreferenceSerializer,<br>        ),<br>    )</pre><pre>// inside `androidMain`<br>// ProtoDataStore.kt<br><br>actual fun getDataStore(): DataStore&lt;PreferenceData&gt; {<br>    val content = requireNotNull(AndroidPlatformContextProvider.context)<br>    val producePath = { content.filesDir.resolve(DATA_STORE_FILE_NAME).absolutePath.toPath() }<br><br>    return createDataStore(fileSystem = FileSystem.SYSTEM, producePath = producePath)<br>}</pre><pre>// inside `iosMain`<br>// ProtoDataStore.kt<br><br>actual fun getDataStore(): DataStore&lt;PreferenceData&gt; {<br>    @OptIn(ExperimentalForeignApi::class)<br>    val producePath = {<br>        val documentDirectory: NSURL? = NSFileManager.defaultManager.URLForDirectory(<br>            directory = NSDocumentDirectory,<br>            inDomain = NSUserDomainMask,<br>            appropriateForURL = null,<br>            create = false,<br>            error = null,<br>        )<br>        requireNotNull(documentDirectory).path + &quot;/$DATA_STORE_FILE_NAME&quot;<br>    }<br><br>    return createDataStore(fileSystem = FileSystem.SYSTEM, producePath = { producePath().toPath() })<br>}</pre><ul><li>Use DataStore to get and put key-value pair</li></ul><pre>// inside `commonMain`<br>// Preference.kt<br><br>interface Preference {<br>    suspend fun updateCounter()<br>    fun getCounter(): Flow&lt;Int&gt;<br>}<br><br>class PreferenceImpl(private val dataStore: DataStore&lt;PreferenceData&gt; = getDataStore()) :<br>    Preference {<br><br>    override suspend fun updateCounter() {<br>        dataStore.updateData { data -&gt;<br>            data.copy(counter = data.counter + 1)<br>        }<br>    }<br><br>    override fun getCounter(): Flow&lt;Int&gt; {<br>        return dataStore.data.map { data -&gt;<br>            data.counter<br>        }<br>    }<br>}</pre><ul><li>DataStore usage in <a href="https://www.jetbrains.com/lp/compose-multiplatform/">Compose Multiplatform</a></li></ul><pre>@Composable<br>@Preview<br>fun App() {<br>    MaterialTheme {<br>        val composableScope = rememberCoroutineScope()<br>        val preference: Preference = remember { PreferenceImpl() }<br>        val counter by preference.getCounter().collectAsState(initial = 0)<br><br>        Column(<br>            Modifier.fillMaxSize(),<br>            horizontalAlignment = Alignment.CenterHorizontally,<br>            verticalArrangement = Arrangement.Center,<br>        ) {<br>            Button(<br>                onClick = {<br>                    composableScope.launch {<br>                        preference.updateCounter()<br>                    }<br>                },<br>            ) {<br>                Text(&quot;Click me! Counter: $counter&quot;)<br>            }<br>        }<br>    }<br>}</pre><p>Result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*LLMohc4VOkcL1wdhGDjp_Q.gif" /><figcaption>Android</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*myxIzIctkEZvgk81vKV0-w.gif" /><figcaption>iOS</figcaption></figure><p><strong>Testing:</strong></p><p>Write the test for <strong><em>Android</em></strong>:</p><pre>// add dependencies in `libs.versions.toml`<br><br>[versions]<br>androidx-espresso-core = &quot;3.5.1&quot;<br>junitKtx = &quot;1.2.1&quot;<br><br>[libraries]<br>androidx-espresso-core = { group = &quot;androidx.test.espresso&quot;, name = &quot;espresso-core&quot;, version.ref = &quot;androidx-espresso-core&quot; }<br>androidx-junit-ktx = { group = &quot;androidx.test.ext&quot;, name = &quot;junit-ktx&quot;, version.ref = &quot;junitKtx&quot; }</pre><pre>// update `build.gradle.kts`<br><br>dependencies {<br>    androidTestImplementation(libs.androidx.espresso.core)<br>    androidTestImplementation(libs.androidx.junit.ktx)<br>}<br><br>android {<br>    defaultConfig {<br>        // enable Instrumentation Test<br>        testInstrumentationRunner = &quot;androidx.test.runner.AndroidJUnitRunner&quot;<br>    }<br>}</pre><pre>// inside `androidInstrumentedTest`<br>// PreferenceImplAndroidTest.kt<br><br>@RunWith(AndroidJUnit4::class)<br>class PreferenceImplAndroidTest {<br><br>    private lateinit var preference: Preference<br><br>    @Before<br>    fun setup() {<br>        val context = ApplicationProvider.getApplicationContext&lt;Context&gt;()<br>        AndroidPlatformContextProvider.setContext(context)<br>        preference = PreferenceImpl()<br>    }<br><br>    @Test<br>    fun testUpdateAndGetLastSelectedLocality() = runBlocking {<br>        preference.updateCounter()<br><br>        val counterValue = preference.getCounter().first()<br><br>        TestCase.assertEquals(1, counterValue)<br>    }<br>}</pre><p>Write the test for <strong><em>iOS</em></strong>:</p><pre>// inside `iosTest`<br>// PreferenceImplIosTest.kt<br><br>class PreferenceImplIosTest {<br><br>    private lateinit var preference: Preference<br>    private var dataStore: DataStore&lt;PreferenceData&gt; = getDataStore()<br><br>    @BeforeTest<br>    fun setup() {<br>        preference = PreferenceImpl(dataStore)<br>    }<br><br>    @AfterTest<br>    fun tearDown() {<br>        runBlocking {<br>            dataStore.updateData {<br>                it.copy(counter = 0)<br>            }<br>        }<br>    }<br><br>    @Test<br>    fun testUpdateAndGetLastSelectedLocality() = runBlocking {<br>        preference.updateCounter()<br><br>        val counterValue = preference.getCounter().first()<br><br>        assertEquals(1, counterValue)<br>    }<br>}</pre><p>Drop your suggestions and improvements in the comment below. Peace.</p><p>Connect with me on <a href="https://www.linkedin.com/in/areeb-momin/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d397f40a0805" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Pay’s Card Recognition Unleashed: Mastering Android Integration]]></title>
            <link>https://medium.com/@aribmomin111/google-pays-card-recognition-unleashed-mastering-android-integration-bdcebb1aa4e2?source=rss-3827babc2c9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdcebb1aa4e2</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ocr]]></category>
            <category><![CDATA[google-pay]]></category>
            <category><![CDATA[payments]]></category>
            <category><![CDATA[card-reader]]></category>
            <dc:creator><![CDATA[Areeb Momin]]></dc:creator>
            <pubDate>Sat, 26 Aug 2023 16:03:17 GMT</pubDate>
            <atom:updated>2023-08-26T16:03:17.791Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Google Pay’s Payment Card Recognition" src="https://cdn-images-1.medium.com/max/285/1*Oy7CWQOvc24V2Ge2ImjZAg.png" /><figcaption>Google Pay’s Payment Card Recognition</figcaption></figure><p>In the realm of mobile payment solutions, one innovation stands out <a href="https://developers.google.com/pay/payment-card-recognition/debit-credit-card-recognition">Google Pay’s payment card recognition</a>. For developers seeking to harness this technology, your guide has arrived. This article is your technical compass, leading you through the intricacies of implementing <a href="https://developers.google.com/pay/api/android/overview">Google Pay’s</a> payment card recognition library on Android. With practical insights and concise code snippets, we’ll navigate prerequisites, dive deep into <a href="https://developers.google.com/pay/api/android/guides/setup">integration</a>, and provide a clear step-by-step process. Your path to seamless integration begins here. Grab the complete code on <a href="https://github.com/areebmomin/Payment-Card-Recognition">GitHub </a>and let’s unlock the potential of payment card recognition.</p><p><a href="https://github.com/areebmomin/Payment-Card-Recognition">GitHub - areebmomin/Payment-Card-Recognition: An Android POC for using Google Pay&#39;s &#39;Payment Card Recognition&#39; feature.</a></p><h4><strong>Result:</strong></h4><figure><img alt="Home Page" src="https://cdn-images-1.medium.com/max/337/1*jRU0sOVL34u2MJL_ht4f-g.jpeg" /><figcaption>Home Page</figcaption></figure><figure><img alt="Payment Card Recognition Page" src="https://cdn-images-1.medium.com/max/294/1*8XDY5pWHfIy0so80cNTepg.jpeg" /><figcaption>Payment Card Recognition Page</figcaption></figure><h4><strong>Add Google Pay dependency:</strong></h4><p>Add dependency in app/build.gradle.</p><pre>dependencies {<br>  implementation &#39;com.google.android.gms:play-services-wallet:19.2.0&#39;<br>}</pre><h4><strong>Modify your Manifest:</strong></h4><p>Add meta-data to the &lt;application&gt; element of your project&#39;s AndroidManifest.xml file.</p><pre>&lt;meta-data<br>  android:name=&quot;com.google.android.gms.wallet.api.enabled&quot;<br>  android:value=&quot;true&quot; /&gt;</pre><h4><strong>Initialize Payment Client:</strong></h4><p>Create a PaymentsClient instance in the onCreate method in your Activity.</p><pre> private fun createPaymentsClient(activity: Activity): PaymentsClient {<br>        val walletOptions = Wallet.WalletOptions.Builder()<br>            .setEnvironment(WalletConstants.ENVIRONMENT_TEST)<br>            .build()<br><br>        return Wallet.getPaymentsClient(activity, walletOptions)<br>    }</pre><h4><strong>Get Card Recognition intent:</strong></h4><p>Create a newPendingIntent before every launch of the Card Recognition page.</p><pre>private fun createOCRIntent(onSuccess: () -&gt; Unit, onFailure: () -&gt; Unit) {<br>        val request = PaymentCardRecognitionIntentRequest.getDefaultInstance()<br><br>        paymentsClient<br>            .getPaymentCardRecognitionIntent(request)<br>            .addOnSuccessListener {<br>                cardRecognitionPendingIntent = it.paymentCardRecognitionPendingIntent<br>                onSuccess()<br>            }<br>            .addOnFailureListener { e -&gt;<br>                onFailure()<br>                Toast.makeText(this, &quot;Payment card ocr not available. $e&quot;, Toast.LENGTH_LONG).show()<br>            }<br>    }</pre><h4><strong>Launch Card Recognition page:</strong></h4><p>Open the Card Recognition Page and wait for results.</p><pre>private fun startPaymentCardOcr(onComplete: () -&gt; Unit) {<br>        try {<br>            val intentSenderForResult =<br>                IntentSenderRequest.Builder(cardRecognitionPendingIntent.intentSender).build()<br>            getResultLauncher.launch(intentSenderForResult)<br>        } catch (e: SendIntentException) {<br>            Toast.makeText(this, &quot;Failed to start payment card recognition. $e&quot;, Toast.LENGTH_LONG)<br>                .show()<br>        }<br>        onComplete()<br>    }<br><br>    private val getResultLauncher =<br>        registerForActivityResult(<br>            ActivityResultContracts.StartIntentSenderForResult()<br>        ) { result -&gt;<br>            val resultCode = result.resultCode<br>            val data = result.data<br><br>            if (resultCode == Activity.RESULT_OK &amp;&amp; data != null) {<br>                PaymentCardRecognitionResult.getFromIntent(data)?.let {<br>                    handlePaymentCardRecognitionResult(it)<br>                }<br>            }<br>        }</pre><h4><strong>Handle Card Recognition Page result:</strong></h4><p>After receiving the result, process PaymentCardRecognitionResult.</p><pre>private fun handlePaymentCardRecognitionResult(<br>        cardRecognitionResult: PaymentCardRecognitionResult,<br>    ) {<br>        val creditCardExpirationDate = cardRecognitionResult.creditCardExpirationDate<br>        val expirationDate = creditCardExpirationDate?.let { &quot;%02d/%d&quot;.format(it.month, it.year) }<br>        val cardResultText = &quot;PAN: ${cardRecognitionResult.pan}\nExpiration date: $expirationDate&quot;<br>        Toast.makeText(this, cardResultText, Toast.LENGTH_LONG).show()<br>    }</pre><h4><strong>Full code:</strong></h4><pre>class MainActivity : ComponentActivity() {<br><br>    private lateinit var paymentsClient: PaymentsClient<br>    private lateinit var cardRecognitionPendingIntent: PendingIntent<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br><br>        paymentsClient = createPaymentsClient(this)<br><br>        setContent {<br>            PaymentCardRecognitionPOCTheme {<br>                Surface(<br>                    modifier = Modifier.fillMaxSize(),<br>                    color = MaterialTheme.colorScheme.background<br>                ) {<br>                    Column(<br>                        horizontalAlignment = Alignment.CenterHorizontally,<br>                        verticalArrangement = Arrangement.Center,<br>                        modifier = Modifier<br>                            .fillMaxWidth()<br>                            .fillMaxHeight()<br>                            .padding(20.dp)<br>                    ) {<br>                        MyButton()<br>                    }<br>                }<br>            }<br>        }<br>    }<br><br>    @Composable<br>    fun MyButton() {<br>        var intentStatus by remember { mutableStateOf(INIT_LOADING) }<br><br>        LaunchedEffect(intentStatus) {<br>            when (intentStatus) {<br>                INIT_LOADING -&gt; createOCRIntent(<br>                    onSuccess = {<br>                        intentStatus = SUCCESS<br>                    },<br>                    onFailure = {<br>                        intentStatus = FAILURE<br>                    },<br>                )<br><br>                else -&gt; {}<br>            }<br>        }<br><br>        OCRButton(intentStatus) {<br>            when (intentStatus) {<br>                INIT_LOADING, LOADING -&gt; {}<br>                SUCCESS -&gt; {<br>                    startPaymentCardOcr {<br>                        intentStatus = EXPIRED<br>                    }<br>                }<br><br>                EXPIRED, FAILURE -&gt; {<br>                    intentStatus = LOADING<br>                    createOCRIntent(<br>                        onSuccess = {<br>                            intentStatus = SUCCESS<br>                            startPaymentCardOcr {<br>                                intentStatus = EXPIRED<br>                            }<br>                        },<br>                        onFailure = {<br>                            intentStatus = FAILURE<br>                        },<br>                    )<br>                }<br>            }<br>        }<br>    }<br><br>    @Composable<br>    fun OCRButton(intentStatus: IntentStatus, onButtonClick: () -&gt; Unit) {<br>        Button(onClick = onButtonClick) {<br>            when (intentStatus) {<br>                SUCCESS, EXPIRED -&gt; Text(&quot;Open OCR&quot;)<br>                FAILURE -&gt; Text(&quot;Unable to load OCR&quot;)<br>                INIT_LOADING, LOADING -&gt; CircularProgressIndicator(<br>                    color = Color.White,<br>                )<br>            }<br>        }<br>    }<br><br>    private fun createPaymentsClient(activity: Activity): PaymentsClient {<br>        val walletOptions = Wallet.WalletOptions.Builder()<br>            .setEnvironment(WalletConstants.ENVIRONMENT_TEST)<br>            .build()<br><br>        return Wallet.getPaymentsClient(activity, walletOptions)<br>    }<br><br>    private fun createOCRIntent(onSuccess: () -&gt; Unit, onFailure: () -&gt; Unit) {<br>        val request = PaymentCardRecognitionIntentRequest.getDefaultInstance()<br><br>        paymentsClient<br>            .getPaymentCardRecognitionIntent(request)<br>            .addOnSuccessListener {<br>                cardRecognitionPendingIntent = it.paymentCardRecognitionPendingIntent<br>                onSuccess()<br>            }<br>            .addOnFailureListener { e -&gt;<br>                onFailure()<br>                Toast.makeText(this, &quot;Payment card ocr not available. $e&quot;, Toast.LENGTH_LONG).show()<br>            }<br>    }<br><br>    private fun startPaymentCardOcr(onComplete: () -&gt; Unit) {<br>        try {<br>            val intentSenderForResult =<br>                IntentSenderRequest.Builder(cardRecognitionPendingIntent.intentSender).build()<br>            getResultLauncher.launch(intentSenderForResult)<br>        } catch (e: SendIntentException) {<br>            Toast.makeText(this, &quot;Failed to start payment card recognition. $e&quot;, Toast.LENGTH_LONG)<br>                .show()<br>        }<br>        onComplete()<br>    }<br><br>    private val getResultLauncher =<br>        registerForActivityResult(<br>            ActivityResultContracts.StartIntentSenderForResult()<br>        ) { result -&gt;<br>            val resultCode = result.resultCode<br>            val data = result.data<br><br>            if (resultCode == Activity.RESULT_OK &amp;&amp; data != null) {<br>                PaymentCardRecognitionResult.getFromIntent(data)?.let {<br>                    handlePaymentCardRecognitionResult(it)<br>                }<br>            }<br>        }<br><br>    private fun handlePaymentCardRecognitionResult(<br>        cardRecognitionResult: PaymentCardRecognitionResult,<br>    ) {<br>        val creditCardExpirationDate = cardRecognitionResult.creditCardExpirationDate<br>        val expirationDate = creditCardExpirationDate?.let { &quot;%02d/%d&quot;.format(it.month, it.year) }<br>        val cardResultText = &quot;PAN: ${cardRecognitionResult.pan}\nExpiration date: $expirationDate&quot;<br>        Toast.makeText(this, cardResultText, Toast.LENGTH_LONG).show()<br>    }<br>}<br><br>enum class IntentStatus {<br>    INIT_LOADING,<br>    LOADING,<br>    SUCCESS,<br>    EXPIRED,<br>    FAILURE,<br>}</pre><h4><strong>Notes:</strong></h4><ol><li>The payment card recognition API requires production access to <a href="https://developers.google.com/pay/api/android/overview">Google Pay API for Android</a>.</li><li>When using WalletConstants.ENVIRONMENT_TEST, the API always returns a stub result if it recognizes the card.</li></ol><p>Drop your suggestions and improvements in the comment below. Peace.</p><p>Connect with me on <a href="https://www.linkedin.com/in/areeb-momin/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdcebb1aa4e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>