<?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 Akash Verma on Medium]]></title>
        <description><![CDATA[Stories by Akash Verma on Medium]]></description>
        <link>https://medium.com/@verma.akash1229?source=rss-4423c2026bf6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*avzm95-rzKx0id9Kxi-nuQ.jpeg</url>
            <title>Stories by Akash Verma on Medium</title>
            <link>https://medium.com/@verma.akash1229?source=rss-4423c2026bf6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 23:52:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@verma.akash1229/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[Navigating Android’s Media Access Changes: A Developer’s Guide to Avoiding Play Store Rejections]]></title>
            <link>https://medium.com/@verma.akash1229/navigating-androids-media-access-changes-a-developer-s-guide-to-avoiding-play-store-rejections-abc69ccd2dea?source=rss-4423c2026bf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/abc69ccd2dea</guid>
            <category><![CDATA[storage]]></category>
            <category><![CDATA[permission]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Akash Verma]]></dc:creator>
            <pubDate>Mon, 17 Mar 2025 14:16:09 GMT</pubDate>
            <atom:updated>2025-03-18T00:42:32.618Z</atom:updated>
            <content:encoded><![CDATA[<h3>Android Media Permissions: Navigating the New Policy Changes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kFYCngsnT_zuAJ9q" /><figcaption>Photo by <a href="https://unsplash.com/@austindistel?utm_source=medium&amp;utm_medium=referral">Austin Distel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Recent changes to Google Play’s media permissions policy have left many developers scrambling to update their apps after receiving rejection notices. This comprehensive guide explains the evolving landscape of Android media access, why Google is making these changes, and how to implement compliant solutions for your app.</p><h3>Understanding the New Policy Landscape</h3><p>Google Play has implemented stricter policies regarding media access permissions, specifically targeting READ_MEDIA_IMAGES and READ_MEDIA_VIDEO. The core principle behind these changes is clear:</p><blockquote><strong><em>Only apps with a core use case that require persistent access to photo and video files located in shared storage are allowed to use photo and video permissions.</em></strong></blockquote><p>This means if your app only needs occasional or one-time access to media files, you should not be requesting broad media access permissions. This change aligns with Android’s broader shift toward more granular and privacy-focused permissions.</p><h3>Why Your App Was Rejected</h3><p>If you received a rejection notice similar to this:</p><pre>Issue found: Permission use is not directly related to your app&#39;s core purpose.</pre><pre>We found that your app is not compliant with how the READ_MEDIA_IMAGES/READ_MEDIA_VIDEO permissions are allowed to be used.<br>Your app only requires one-time or infrequent access to media files on the device.</pre><p>The problem is likely that your app is requesting broader storage access than it actually needs for its functionality. Google is now enforcing a “least privilege” approach, where apps should only request permissions absolutely necessary for their core functionality.</p><h3>The Evolution of Android Storage Permissions</h3><p>Android’s storage permission model has undergone significant changes over several API levels:</p><h3>Android 9 (API 28) and Earlier</h3><ul><li>Used broad READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions</li><li>Apps had access to virtually all user files</li></ul><h3>Android 10 (API 29)</h3><ul><li>Introduced scoped storage</li><li>WRITE_EXTERNAL_STORAGE permission became less powerful</li><li>requestLegacyExternalStorage=&quot;true&quot; allowed temporary opt-out</li></ul><h3>Android 11 (API 30)</h3><ul><li>Scoped storage enforcement began</li><li>Introduced more granular media permissions</li><li>Legacy storage access further restricted</li></ul><h3>Android 13 (API 33)</h3><ul><li>Introduced READ_MEDIA_IMAGES and READ_MEDIA_VIDEO to replace the broader READ_EXTERNAL_STORAGE</li><li>More granular photo/video access</li></ul><h3>Android 14 (API 34)</h3><ul><li>Introduced READ_MEDIA_VISUAL_USER_SELECTED for temporary, user-initiated access</li><li>Enhanced PhotoPicker API support</li></ul><h3>The Solution: Using Modern Approaches</h3><h3>1. Photo Picker API (Recommended)</h3><p>For one-time or infrequent media selection, the Photo Picker API is now the preferred approach:</p><pre>if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.TIRAMISU &amp;&amp; <br>    ActivityResultContracts.PickVisualMedia.isPhotoPickerAvailable(requireContext())) {<br>    pickImageLauncher.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))<br>} else {<br>    // Fallback for older devices using system picker<br>    launchSystemPicker()<br>}</pre><p>The Photo Picker:</p><ul><li>Natively available on Android 13+ (API 33+)</li><li>Available via backport on:<br>- Android 4.4 (API 19) through Android 10 (API 29) devices with Google Play services<br>- Android Go devices running Android 11 or 12 with Google Play services</li><li>Doesn’t require any storage permissions</li><li>Provides a system UI for selecting media</li></ul><h4>Enabling Photo Picker Backport</h4><p>To ensure the Photo Picker works on older Android versions through Google Play Services, add this to your manifest:</p><pre>&lt;!-- Trigger Google Play services to install the backported photo picker module. --&gt;<br>&lt;service<br>    android:name=&quot;com.google.android.gms.metadata.ModuleDependencies&quot;<br>    android:enabled=&quot;false&quot;<br>    android:exported=&quot;false&quot;<br>    tools:ignore=&quot;MissingClass&quot;&gt;<br>    &lt;intent-filter&gt;<br>        &lt;action android:name=&quot;com.google.android.gms.metadata.MODULE_DEPENDENCIES&quot; /&gt;<br>    &lt;/intent-filter&gt;<br>    &lt;meta-data<br>        android:name=&quot;photopicker_activity:0:required&quot;<br>        android:value=&quot;&quot; /&gt;<br>&lt;/service&gt;</pre><p>This configuration tells Google Play Services to install the backported Photo Picker module when needed, providing a consistent experience across Android versions.</p><h3>2. Using System Picker for Older Devices</h3><p>For devices running Android 10–12 or when the Photo Picker is not available, use the system picker which doesn’t require broad storage permissions:</p><pre>// Register the launcher in your Activity or Fragment<br>private val pickStorageLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -&gt;<br>    if (result.resultCode == Activity.RESULT_OK) {<br>        result.data?.data?.let { uri -&gt;<br>            // Handle single image selection<br>            processSelectedImage(uri)<br>        } ?: run {<br>            // Handle multiple image selection<br>            result.data?.clipData?.let { clipData -&gt;<br>                val imageUris = mutableListOf&lt;Uri&gt;()<br>                for (i in 0 until clipData.itemCount) {<br>                    imageUris.add(clipData.getItemAt(i).uri)<br>                }<br>                processSelectedImages(imageUris)<br>            }<br>        }<br>    }<br>}<br><br>// Function to launch the system picker<br>private fun launchSystemPicker() {<br>    val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI).apply {<br>        val mimeTypes = arrayOf(&quot;image/jpg&quot;, &quot;image/png&quot;, &quot;image/jpeg&quot;)<br>        putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes)<br>        putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)<br>    }<br>    pickStorageLauncher.launch(Intent.createChooser(intent, &quot;Select Picture&quot;))<br>}</pre><p>This approach:</p><ul><li>Uses the system’s built-in picker interface</li><li>Doesn’t require READ_EXTERNAL_STORAGE permission</li><li>Works on Android 10+ without additional permissions</li><li>Provides a familiar interface for users</li></ul><h3>3. READ_MEDIA_VISUAL_USER_SELECTED Permission</h3><p>For Android 14+, when you need limited, user-initiated access:</p><pre>&lt;uses-permission android:name=&quot;android.permission.READ_MEDIA_VISUAL_USER_SELECTED&quot; /&gt;</pre><p>This permission:</p><ul><li>Allows temporary access to specific user-selected media files</li><li>Requires explicit user selection through a system picker</li><li>Does not grant broad access to all media</li></ul><h3>4. Properly Handle Legacy Devices</h3><p>Your manifest should include proper permission handling for older devices:</p><pre>&lt;uses-permission<br>    android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;<br>    android:maxSdkVersion=&quot;28&quot; /&gt;<br>&lt;uses-permission<br>    android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot;<br>    android:maxSdkVersion=&quot;28&quot; /&gt;<br>&lt;uses-permission android:name=&quot;android.permission.READ_MEDIA_VISUAL_USER_SELECTED&quot; /&gt;</pre><p>Notice how the storage permissions are limited to API 28 and below, while newer devices use the more limited permission.</p><h3>Updated Runtime Permission Logic</h3><p>Your permission checking code should adapt to different Android versions:</p><pre>// For media access<br>if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.TIRAMISU) {<br>    // Use PhotoPicker - no permissions needed<br>    if (ActivityResultContracts.PickVisualMedia.isPhotoPickerAvailable(requireContext())) {<br>        pickImageLauncher.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))<br>    } else {<br>        // Fallback to system picker<br>        launchSystemPicker()<br>    }<br>} else if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.Q) {<br>    // Android 10-12: Use system picker (no permissions needed)<br>    launchSystemPicker()<br>} else {<br>    // Android 9 and below: Need legacy permissions<br>    if (isPermissionGranted(this.requireContext(), PermissionManager.readExternalStoragePermission)) {<br>        // Permission already granted, proceed<br>        launchSystemPicker()<br>    } else {<br>        // Request the permission<br>        requestPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE)<br>    }<br>}</pre><h3>When Can You Still Use Broad Media Permissions?</h3><p>You should only request READ_MEDIA_IMAGES or READ_MEDIA_VIDEO if your app&#39;s core functionality genuinely requires persistent access to all media files. Examples include:</p><ul><li>Gallery or photo management apps</li><li>Media editing apps that need to access all user media</li><li>Backup applications that need to save all user photos</li></ul><p>If your app only needs to:</p><ul><li>Let users select a profile picture</li><li>Upload a single image or video</li><li>Select specific media items occasionally</li></ul><p>Then you should use the Photo Picker or READ_MEDIA_VISUAL_USER_SELECTED permission instead.</p><h3>Testing Your Implementation</h3><p>Before submitting to Google Play:</p><ol><li>Test on multiple API levels (28, 29, 33, 34+)</li><li>Verify your app works without requesting unnecessary permissions</li><li>Ensure the user experience remains smooth across different Android versions</li><li>Check that your manifest correctly limits permissions by API level</li><li>Test the Photo Picker backport on older devices with Google Play Services</li></ol><h3>Conclusion</h3><p>Google’s stricter enforcement of media permissions reflects the industry-wide shift toward enhanced user privacy. By adopting these modern approaches, you’ll not only comply with Google Play policies but also provide a more privacy-conscious experience for your users.</p><p>Remember: Always request the minimum permissions needed for your app’s functionality. When it comes to media access, prefer the system’s built-in pickers and limited-scope permissions whenever possible.</p><p>By following these guidelines, you can avoid Play Store rejections while building more privacy-friendly Android applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abc69ccd2dea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamic Feature Modules in a Production App]]></title>
            <link>https://blog.lenskart.com/dynamic-feature-modules-in-a-production-app-9986fab402ee?source=rss-4423c2026bf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/9986fab402ee</guid>
            <category><![CDATA[dynamic-feature-module]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[app-size]]></category>
            <category><![CDATA[modularization]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Akash Verma]]></dc:creator>
            <pubDate>Mon, 08 Feb 2021 07:05:51 GMT</pubDate>
            <atom:updated>2021-02-10T07:40:47.861Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2qbsCmY8S-u_WLGP" /><figcaption>Photo by <a href="https://unsplash.com/@krstne?utm_source=medium&amp;utm_medium=referral">Kristine Tumanyan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>For the past 4 years, we have focused on keeping the Android Consumer App’s size to stay in the 8-10MB range and had been successful at it.</p><p>Recently we started to look into options to give users a store-like experience in the App. This was essential considering the pandemic, where all of us were in lockdown and couldn’t really walk into a store and get a feel of how the eyewear would look on them. One feature that worked really well in achieving this was the Eyewear trial feature using Augmented Reality.</p><p>While it had a significant business impact (we even won an award for it), it broke our 4-year streak and raised the app size to go well over the 10MB benchmark.</p><p>We had to do something about it.</p><blockquote>Incase you haven’t already, do checkout the AR feature in Lenskart App (the feature is supported on ARCore enabled devices)</blockquote><p><a href="https://play.google.com/store/apps/details?id=com.lenskart.app">Lenskart: Eyeglasses, Sunglasses, Contact Lens App - Apps on Google Play</a></p><blockquote>Also, you can read our blog on how we implemented this feature using Google’s Sceneform SDK:</blockquote><p><a href="https://medium.com/lenskart-engineering/augmented-faces-using-googles-sceneform-sdk-e4a40c993ec4">Augmented Faces Using Google’s Sceneform SDK</a></p><p>It’s not just about the app size, we also consistently focus and work on the modularity of the code, enabling ease in the parallel development of features. And so, it was high time to take advantage of the Dynamic Feature Module.</p><p>In this article, I will be sharing the experience of converting the AR feature to DFM in the Lenskart App.</p><h3><strong>Prerequisites:</strong></h3><ul><li><strong>Enable App bundles:</strong> To use DFM, we need to enable App Bundles. The Dynamic features modules cannot be bundled with normal apk and require to shift to the new publishing format i.e. <strong>.aab</strong></li></ul><blockquote>For more info on App Bundles, checkout the link below: <a href="https://developer.android.com/guide/app-bundle">https://developer.android.com/guide/app-bundle</a></blockquote><ul><li>Remove <strong>shrinkResources</strong> from <strong>app.gradle</strong></li><li><strong>Modular Codebase:</strong> The most important thing to ensure before converting any feature to DFM is to first have a modular codebase.</li></ul><p>I would recommend you to check out the article on how we modularized our codebase. This will give you an idea about how the code can be structured better so that we can easily make our DFM:</p><p><a href="https://medium.com/lenskart-engineering/modularising-lenskart-consumer-app-architecture-aa82c9992fef">Modularizing an Android App: Architecture &amp; Design Decisions</a></p><h4><strong>TL;DR of the post!</strong></h4><p>The <strong>core</strong> is where all the different features reside. And we ensure that there is code separation between all these features. This gave us the advantage to easily convert a feature to DFM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*FgP003CkEU7G9SBR4ULrrQ.png" /><figcaption>Module Graph</figcaption></figure><p>Let’s go through a step by step guide to creating a DFM.</p><h3><strong>DFM Setup:</strong></h3><ol><li>Add the following dependency to <strong>app.gradle</strong>:<strong><br></strong>implementation &quot;com.google.android.play:core:${versions.playcore}&quot;</li><li>File → New → New Module → DFM Module</li><li><strong>Specify package name:</strong> In our case the base package name is <strong>com.lenskart.app</strong>, so we will name our AR module package <strong>com.lenskart.ar</strong>.<strong> </strong>It is important to name the module in the format com.example<strong>.modulename</strong> and <strong>not</strong> com.example<strong>.app.modulename</strong> otherwise, we get compilation errors especially if we are using data-binding.</li><li><strong>Select the module delivery type:</strong> Depending upon the use case of the feature module, we can select from the following module delivery type:</li></ol><ul><li><strong>On-Demand: </strong>With this type of delivery the <strong>base.apk</strong> will not contain a feature module and therefore decreasing the <strong>base.apk</strong> size when a user downloads the app. In this situation, we can dynamically load our module based on the compatibility of the module or when the flow is required. This is the best delivery option for our Eyewear trail feature as it is based on the ARCore service which is supported on most Android N+ devices.</li><li><strong>Install Time: </strong>In this type of delivery the module will be part of <strong>base.apk</strong>. This type of delivery is used for the module which will visible to the user only once. Login module can be an example of this type of delivery, once the user is logged-in we can just uninstall the module dynamically. But this doesn’t mean we can never reinstall the module again. If a user logs out we can just reinstall the module again just as if we would do for the on-demand module.</li><li><strong>Conditional Delivery: </strong>Again taking the example of the AR module, we can just make it an install-time module with a condition of the <strong>min-sdk</strong> parameter. So only Android N+ devices will receive the apk with the AR feature being included in the <strong>base.apk</strong>. There are other conditions like country, hardware requirements, etc. that we can also specify.</li></ul><blockquote>In Split Apk or DFM, the features are divided into different apk files. The common <strong>base.apk</strong> containing all basic functionality from base module gets installed first then on top of that <strong>feature-module.apk </strong>gets installed.</blockquote><blockquote>For more information on module delivery type, checkout the link below:<br><a href="https://developer.android.com/guide/app-bundle/play-feature-delivery">https://developer.android.com/guide/app-bundle/play-feature-delivery</a></blockquote><p><strong>Note</strong>: For sake of simplicity we will use install-time delivery for our module.</p><p>Once we are done with the above setup, our module gets created containing the following <strong>manifest.xml </strong>file:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;manifest xmlns:dist=&quot;http://schemas.android.com/apk/distribution&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    package=&quot;com.example.ar&quot;&gt;<br><br>    &lt;dist:module<br>        dist:instant=&quot;false&quot;<br>        dist:title=&quot;<strong>MODULE_NAME</strong>&quot;&gt;<br>        &lt;dist:delivery&gt;<br>            &lt;dist:install-time /&gt;<br>        &lt;/dist:delivery&gt;<br>        &lt;dist:fusing dist:include=&quot;true&quot; /&gt;<br>    &lt;/dist:module&gt;<br><br>&lt;/manifest&gt;</pre><p>One thing to note here in DFM is that the Dynamic Module is always dependent on the base module (or <strong>core</strong> module mentioned in the module graph) and not the other way around as it happens for any normal library module. Due to this, we need to invert our module dependency such that the base module doesn’t have any dependency on the new dynamic module created.</p><p>We can now move our feature code from the package <strong>com.example.app</strong> to <strong>com.example.modulename.</strong></p><p>Do ensure to move all the module-specific resources (string, drawable, etc.) to the module package and all external dependencies to the module gradle file.</p><p><strong>Important: </strong>If you are using data-binding do ensure to add the following rule in your proguard file, otherwise, you will be getting ClassNotFoundException on the launch of the Module related Activity:</p><pre>-keep class com.example.modulename.DataBinderMapperImpl { *; } </pre><h3><strong>Dagger Setup:</strong></h3><p>You will likely be using Dagger for dependency injection in your project and the class that we just moved in our dynamic module must have some dependencies that are injected by the dagger.</p><p>The application component doesn’t know about classes in DFM so it won’t be able to inject those dependencies now. But, since the DFM depends on the app module, it can access the dependencies through the application component inside the <strong>base</strong> module. So we need to set up and initialize a separate dependency module graph which will be dependent on the application module.</p><p>A basic dagger component setup will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JAe_kYzfQu1S-GOcP35RVw.png" /><figcaption>Dagger Multi-Module Graph</figcaption></figure><h4>Steps to Setup Feature Component:</h4><ul><li>First, we create a custom scope (<strong>FeatureScope</strong>) inside the <strong>base</strong> module. All our modules will be scoped to the feature itself.</li></ul><pre>@Scope<br>@Retention(AnnotationRetention.RUNTIME)<br>annotation class FeatureScope</pre><ul><li>Now we define our <strong>ActivityModule</strong> class inside our feature module.</li></ul><pre>@Module<br>class ActivityModule {<br>    @Provides<br>    fun providesFeatureActivity(featureActivity: FeatureActivity): FeatureActivity {<br>        return featureActivity<br>    }<br>}</pre><ul><li>Create <strong>ActivityComponent</strong> inside our Dynamic feature module. This uses <strong>AppComponent </strong>as a dependency from the <strong>base </strong>module and is marked with <strong>FeatureScope</strong></li></ul><pre><strong>@FeatureScope</strong><br>@Component(<br>    modules = [<strong>ActivityModule</strong>::class],<br>    dependencies = [<strong>AppComponent</strong>::class]<br>)<br>interface ActivityComponent {<br>    @Component.Builder<br>    interface Builder {<br>        fun build(): ActivityComponent<br><br>        @BindsInstance<br>        fun featureActivity(activity: FeatureActivity?): Builder<br>        fun appComponent(component: AppComponent?): Builder<br>    }<br><br>    fun inject(featureActivity: FeatureActivity)<br>}</pre><ul><li>Then inside your activity just initialize the <strong>DaggerActivityComponent</strong></li></ul><pre>DaggerActivityComponent.builder()<br>    .appComponent((application as ApplicationClass).appComponent)<br>    .featureActivity(this)<br>    .build()<br>    .inject(this)</pre><p>Incase your feature module contains fragments make sure to define <strong>FragmentModule </strong>and <strong>FragmentComponent</strong>class as well.</p><blockquote><strong>Note</strong>: This dagger component setup is required for each dynamic module that we create.</blockquote><h3>Navigation In DFM:</h3><p>Now that we are done with the dagger setup let&#39;s move on to changes required for navigation. Launching any module activity is a little different from what we generally do. Since the app module doesn’t have class reference to any of the module activities, we need to specify the fully qualified module class name while launching intent.</p><pre>Intent().setClassName(<br>   &quot;com.example.app&quot;,  <br>   &quot;com.example.app.modulename.ActivityName&quot;<br>).also {<br>   startActivity(it)<br>}</pre><p>In case you use deeplinks for navigation, this will not be required. You’ll just have to update <strong>android:name </strong>for the module activities with a fully qualified class name.</p><h3>Downloading On-Demand Module:</h3><p>To develop an on-demand module, we can use <strong>SplitInstallManager</strong> to download the DFM module using the following code:</p><pre>val request = SplitInstallRequest.newBuilder()<br>    .addModule(<strong><em>MODULE_NAME</em></strong>)<br>    .build()<br><br>splitManager.registerListener <strong>{<br>    </strong>when (it.status()) {<br>        <strong>SplitInstallSessionStatus.</strong><strong>CANCELED</strong> -&gt; {<br>            ...<br>        }<br>        <strong>SplitInstallSessionStatus.</strong><strong>CANCELING</strong> -&gt; {<br>            ...<br>        }<br>        <strong>SplitInstallSessionStatus.</strong><strong>DOWNLOADED</strong> -&gt; {<br>            ...<br>        }<br>        <strong>SplitInstallSessionStatus.</strong><strong>DOWNLOADING</strong> -&gt; {<br>            ...<br>        }<br>        <strong>SplitInstallSessionStatus.</strong><strong>FAILED</strong> -&gt; {<br>            ...<br>        }<br>        <strong>SplitInstallSessionStatus.INSTALLED</strong> -&gt; {<br>            ...<br>        }<br>        <strong>SplitInstallSessionStatus.</strong><strong>INSTALLING</strong> -&gt; {<br>            ...<br>        }<br>        <strong>SplitInstallSessionStatus.</strong><strong>PENDING</strong> -&gt; {<br>            ...<br>        } <br>        <strong>SplitInstallSessionStatus.</strong><strong>REQUIRES_USER_CONFIRMATION</strong> -&gt; {<br>            ...<br>        }<br>        <strong>SplitInstallSessionStatus.</strong><strong>UNKNOWN</strong> -&gt; {<br>            ...<br>        }<br><strong>}</strong></pre><pre>splitManager.startInstall(request)</pre><h3><strong>Testing DFM:</strong></h3><p>Now that we are done with our DFM setup, it’s time to test our application. But there is a catch here. As mentioned previously, DFM does not work with normal apk and requires app bundles format. So, we have 2 options:</p><h4><strong>1. Internal App sharing:</strong></h4><p>On the Google play console, we have internal app sharing. We need to provide the signing config on the console and then just upload a <strong>.aab </strong>file generated through Android Studio.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1hpkPyVAi_wUeKAV2KUwzQ.png" /><figcaption>Play console (Internal App Sharing)</figcaption></figure><p>Once we are done we just need to share the link. It will automatically redirect to the Play Store app and you will be able to download the device-specific apk generated and signed automatically by play console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*EcEjD3iRzfydiNp2Vh9m7A.jpeg" /><figcaption>Internal App Sharing through PlayStore</figcaption></figure><p><strong>Note</strong>: Before we can install this apk we need to enable internal app sharing settings in our play store app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*vjsztL3pNvcT_7y5idWrwg.gif" /><figcaption>Enable Internal App Sharing</figcaption></figure><p>If we have any on-demand module then that will also be served by the console itself.</p><h4><strong>2. Locally with BundleTools:</strong></h4><p>To test our app bundles or the DFM locally, we need to first install <strong>bundletool</strong> (command-line tool). It’s also internally used by the play console to build and sign apks. Once we have <strong>bundletool</strong> installed on the system, we first need to generate the <strong>.aab</strong> file, and then run the following commands:</p><pre>bundletool build-apks <br>--local-testing <br>--bundle=<strong><em>PATH_TO_AAB_FILE</em></strong> <br>--output=<strong><em>PATH_TO_APKS_FILE</em></strong>  <br>--ks=<strong><em>PATH_TO_JKS_FILE</em></strong>  <br>--ks-pass=<strong><em>PASS</em></strong><br>--ks-key-alias=<strong><em>ALIAS</em></strong> <br>--key-pass=<strong><em>PASS</em></strong></pre><p>This will generate a .<strong>apks </strong>file (not apk). This is similar to a zip file that contains all different kinds of device-specific apks. All will be signed with the signing config given in the command.</p><p>Then we need to run:</p><pre>bundletool install-apks --apks=<strong>PATH_TO_APKS_FILE</strong> --adb=<strong>PATH_TO_ADB</strong></pre><p>This command will extract the device-specific apk for the connected device and install it.</p><p>Now if you have any on-demand module then that apk will also be generated and will be copied to internal storage with the above command. The<strong>--local-testing</strong> flag tells the system that apk for the on-demand module has to be provided from local storage, instead of looking for it on the play console. And that’s it we can now access our module.</p><blockquote>For more info on bundletool and its commands, checkout the link below: <a href="https://developer.android.com/studio/command-line/bundletool">https://developer.android.com/studio/command-line/bundletool</a></blockquote><h3><strong>Points to Note:</strong></h3><ul><li>It is important to handle module availability exceptions. We need to ensure that the module is installed before launching any module activity and avoid any crashes. And for better user experience disable or hide the UI for the entry point of the module or maybe provide feedback to the user.</li><li>Most of the apps use deeplinks for navigation, so in your app manifest make sure to update your DFM activities with the fully qualified name. So update it to <strong>modulePackage.ExampleActivity</strong> instead of just <strong>.ExampleActivity</strong></li><li>We generally have different build types for testing and production purposes, so it might be possible that we use different signing config as well. But internal app sharing allows only to set 1 set of singing config. This is one drawback of the play console.</li><li>If you have a CICD pipeline then you will have to update that as well. We can implement the same set of commands (mentioned in “local testing using bundletool”) in the pipeline to generate a <strong>universal.apk</strong> using flag <strong>--mode=universal</strong> and share that for testing purposes.</li><li>As we already discussed that Dagger Android annotations can’t be used inside DFM and we need to rely on the Dagger2 setup, the same is true for Hilt as well. Right now, Hilt doesn’t directly support injection in DFM.</li></ul><blockquote>For more info on Hilt in multi-module apps, checkout the below link: <a href="https://developer.android.com/training/dependency-injection/hilt-multi-module">https://developer.android.com/training/dependency-injection/hilt-multi-module</a></blockquote><p>With on-demand DFM we were able to reduce our base apk size back to 10MB. The AR module (which is around 5MB) gets installed dynamically for supported devices. So users can start using the app once the base apk is installed, and as they go through the onboarding process we can just install our modules in the background and make it available as early as the onboarding process is complete.</p><h3>References:</h3><ul><li><a href="https://developer.android.com/guide/app-bundle/play-feature-delivery">https://developer.android.com/guide/app-bundle/play-feature-delivery</a></li><li><a href="https://developer.android.com/codelabs/on-demand-dynamic-delivery#0">https://developer.android.com/codelabs/on-demand-dynamic-delivery#0</a></li><li><a href="https://developer.android.com/guide/navigation/navigation-dynamic">https://developer.android.com/guide/navigation/navigation-dynamic</a></li><li><a href="https://medium.com/androiddevelopers/dependency-injection-in-a-multi-module-project-1a09511c14b7">https://medium.com/androiddevelopers/dependency-injection-in-a-multi-module-project-1a09511c14b7</a></li><li><a href="https://medium.com/androiddevelopers/a-patchwork-plaid-monolith-to-modularized-app-60235d9f212e">https://medium.com/androiddevelopers/a-patchwork-plaid-monolith-to-modularized-app-60235d9f212e</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9986fab402ee" width="1" height="1" alt=""><hr><p><a href="https://blog.lenskart.com/dynamic-feature-modules-in-a-production-app-9986fab402ee">Dynamic Feature Modules in a Production App</a> was originally published in <a href="https://blog.lenskart.com/">The Lenskart Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Augmented Faces Using Google’s Sceneform SDK]]></title>
            <link>https://blog.lenskart.com/augmented-faces-using-googles-sceneform-sdk-e4a40c993ec4?source=rss-4423c2026bf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4a40c993ec4</guid>
            <category><![CDATA[blender]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[augmented-reality]]></category>
            <category><![CDATA[sceneform]]></category>
            <dc:creator><![CDATA[Akash Verma]]></dc:creator>
            <pubDate>Mon, 27 Apr 2020 08:52:13 GMT</pubDate>
            <atom:updated>2020-04-27T11:09:47.316Z</atom:updated>
            <content:encoded><![CDATA[<h3>Augmented Faces Using Google’s Sceneform SDK — Part I</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1sv834MXsAlPqfAr" /><figcaption>Photo by <a href="https://unsplash.com/@davidgrdm?utm_source=medium&amp;utm_medium=referral">David Grandmougin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Augmented Reality and Virtual Reality have been hot topics for the past few years, with Google, Facebook, and the like actively working in this area as there are broad use-cases in the field of health, military, education, online retail, etc.. (and not just for creating Instagram or Snap Stories, or even running crazy to catch a Pokemon. <strong>Gotta Catch ’Em All </strong>😜)</p><p>Google came up with <em>ARCore</em>. The <em>ARCore SDK</em> allowed Android Developers to create Augmented Reality based Android native apps without requiring a deep understanding of Unity and other such platforms. Shortly after, Google came up with the <em>Sceneform SDK</em>, which further removed the necessity of learning OpenGL.</p><p>As per the Official Documentation:</p><blockquote>Sceneform SDK is a new library for Android that enables the rapid creation and integration of AR experiences in your app. It combines ARCore and a powerful physically-based 3D renderer.</blockquote><h3>How does it work?</h3><p>Fundamentally, ARCore does two things: 1] it tracks the position of the mobile device as it moves, and 2] it builds its own understanding of the real world.</p><p>In addition to identifying key points, ARCore can detect flat surfaces, like a table or the floor, and it can also estimate the average lighting of the area around it. These capabilities combine to enable ARCore to build its own understanding of the world around it.</p><p><em>Augmented Faces</em> is built on top of ARCore and does a couple of other things:</p><ul><li>It detects faces in the camera’s viewport,</li><li>Generates a Face Mesh — a virtual representation of the face, consisting of the vertices, facial regions, and the center of the user’s head for detected faces,</li><li>Identifies the Pose — points on a person’s face, anchored on the basis of the generated Face Mesh</li><li>Overlays and positions textures and 3D models based on the generated face mesh and identified regions.</li></ul><p>By default, the center pose —the physical center point of the user’s head, located behind the nose is used for placing renderables, but this can be easily modified if required.</p><h3>First things first</h3><p>To start with our first AR app, we need to install a Sceneform plugin on Android Studio. This plugin allows us to import 3D Models into our project (supported formats: obj, gltf (animations not supported), fbx). These are the commonly used formats for 3D models which are supported by Blender, Sketchup, etc..</p><p>But these 3D models cannot be used directly to render into the app. The Sceneform plugin helps us to convert these into supported formats i.e. *.sfa (<strong>S</strong>cene<strong>F</strong>orm <strong>A</strong>sset) or *.sfb (<strong>S</strong>cene<strong>F</strong>orm <strong>B</strong>inary, this one gets generated from the *.sfa when building the app).</p><blockquote>You can read more about Sceneform on the Android Developers guide: <a href="https://developers.google.com/ar/develop/java/sceneform/">https://developers.google.com/ar/develop/java/sceneform/</a></blockquote><h3><strong>Let’s Start!</strong></h3><p>Here are the steps we’ll follow:</p><ol><li>Add Sceneform dependencies</li><li>Add permissions to the manifest</li><li>Convert the 3D model (*.obj to *.sfa) using Sceneform plugin</li><li>Extend ArFragment class (<strong>important</strong>)</li><li>Check if the device is supported</li><li>Load the Renderable (3D model)</li></ol><p>It’s time to get our hands dirty and write some actual code!</p><h4><strong>1. Add Sceneform dependencies</strong></h4><p>Add Sceneform plugin classpath to Project level build.gradle file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91b2816751aeceff08370dde3deac75b/href">https://medium.com/media/91b2816751aeceff08370dde3deac75b/href</a></iframe><p>Add Sceneform dependency and apply the plugin to the app level build.gradle file. Also, add compile options inside android:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a126d683b4ca8a0274474b0276c167c/href">https://medium.com/media/4a126d683b4ca8a0274474b0276c167c/href</a></iframe><h4>2. Add Permissions to the manifest</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/948045d3c55924a3410c3fb7fe5931bf/href">https://medium.com/media/948045d3c55924a3410c3fb7fe5931bf/href</a></iframe><ul><li>Camera permission is necessary for AR apps for obvious reasons.</li><li>Internet permission will be useful when we are hosting our renderable (3D model) and fetching them at runtime.</li></ul><h4>3. Convert the 3D model</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*RnCPxEPgXXzo9QlhIqPyEw.png" /></figure><ul><li>First, create a “3dModels” directory inside our app folder: <br><strong>app-&gt;new-&gt;3dModels. </strong>Data inside this will not be deployed with our app.</li><li>Copy the 3D model into this directory.</li><li>Right-click on *.obj and click on “Import Sceneform Asset”. Provide the output path for *.sfa and *.sfb files. The *.sfb is the binary file used for rendering. This has to be deployed with our app by placing it in the <strong>res/raw</strong> directory.</li></ul><p>These converted Sceneform assets can now be viewed in the <strong>viewer</strong> added to Android Studio when you install Sceneform plugin. We can change related properties for this asset.</p><blockquote>Read more about the properties of Sceneform assets here:<br><a href="https://developers.google.com/ar/develop/java/sceneform/sfa">https://developers.google.com/ar/develop/java/sceneform/sfa</a></blockquote><p>When you “Import Sceneform Asset” below lines will be added to your app-level build.gradle file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2cb1085afbc871ee691da580096bfccf/href">https://medium.com/media/2cb1085afbc871ee691da580096bfccf/href</a></iframe><p>So if you change any property in *.sfa version of the file *.sfb will be updated at compile time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sXuqBcPYDJYzhD6s9jM3CQ.png" /></figure><p>The <strong>viewer</strong> is interactive and provides a 360⁰ view of the renderable.</p><h4>4. Extend ArFragment class</h4><p>The “ArFragment” class is the core of Google’s Sceneform SDK. This fragment is the layer that hides all the complex stuff (like OpenGL, rendering models, calculations, etc) and provides high-level APIs to load and render 3D models.</p><p>Before loading the 3D model and rendering it, we are required to ask for Camera Permission (Runtime permissions — obviously) and check whether the ARCore app is installed/updated. Well, here “ArFragment” comes again to the rescue. We do not have to write this boilerplate code and it’s all handled by the “ArFragment”.</p><p>Internally it detects the face and identifies the facial landmarks based on which it generates a face mesh and then overlays the 3D model onto this face mesh’s origin. By default when we generate *.sfa file, “recenter” property will be added which will force the center of 3D models to be placed at face mesh’s center pose.</p><p>Now create a new class and extend to ArFragment class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc52232eac57bf428263e0442d119382/href">https://medium.com/media/cc52232eac57bf428263e0442d119382/href</a></iframe><p>By default “ArFragment” starts detecting the Plane surface and also displays a tutorial (you all must have noticed this in other AR apps). We need to disable both these things (<em>line 27, line 29</em>) as they’re irrelevant to face augmentation.</p><p>Also, <em>line 12 </em>specifies that we will be using the front camera since face detection is not supported with a rear camera with Sceneform SDK.</p><p>Now in the activity_main.xml add this fragment.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed6e7e691a90c102d9f7db36fe11a8f6/href">https://medium.com/media/ed6e7e691a90c102d9f7db36fe11a8f6/href</a></iframe><h4>5. Check if the device is supported</h4><p>We have kept the app as “<strong>AR Required</strong>” for this demo, but if your app is an “<strong>AR Optional”</strong> app (when <em>android:value=optional</em> in AndroidManifest.xml) then the first thing we need to do in our MainActivity is to check is the device is ARCore supported or not.</p><blockquote>Learn more about <a href="https://developers.google.com/ar/develop/java/enable-arcore#ar_required_apps">AR Required</a> and <a href="https://developers.google.com/ar/develop/java/enable-arcore#ar_optional_apps">AR Optional</a> implementations.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2eb8b608547e341e44e7846a23a20fc6/href">https://medium.com/media/2eb8b608547e341e44e7846a23a20fc6/href</a></iframe><p>As soon as the Activity is created the “FaceArFragment” will handle the Camera permission and also check if the ARCore is installed/updated or not. If not it will prompt to install/update the app.</p><h4><strong>6. Load the Renderable</strong></h4><p>The only thing left now is to load the 3D model.</p><p>As mentioned earlier, the model can either be deployed with the app and can be loaded from the raw folder, or we can host it and fetch it at runtime.</p><p>Lets first load the model locally:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/517d067552067777e895d35afdd7d334/href">https://medium.com/media/517d067552067777e895d35afdd7d334/href</a></iframe><p>ModelRenderable.Builder provides us with CompletableFuture. So we don’t have to handle loading the model asynchronously.</p><p>And lastly add this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/798838f0bb8fb5b83dd4ec8f5af1791d/href">https://medium.com/media/798838f0bb8fb5b83dd4ec8f5af1791d/href</a></iframe><p>In case you have the asset present remotely, do this instead:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae76488b904131b93cc8c5c42d3bc479/href">https://medium.com/media/ae76488b904131b93cc8c5c42d3bc479/href</a></iframe><p>And we are done with our first AR app!</p><h3>Something to Note</h3><p>With Sceneform SDK you can find a <strong><em>“canonical_face_mesh.fbx”</em></strong> file which must be used as a template for creating your own 3D models. You can use this file as a reference by importing it along with the *.obj file in Blender, etc. and can correct positioning, scaling and other properties.</p><p>You can find this file inside here:<br><a href="https://github.com/google-ar/sceneform-android-sdk/blob/master/assets/canonical_face_mesh.fbx">https://github.com/google-ar/sceneform-android-sdk/blob/master/assets/canonical_face_mesh.fbx</a></p><p>To get started with your app you can download models from:<br><a href="https://poly.google.com/">https://poly.google.com</a></p><h3><strong>Limitations</strong></h3><p>There are some limitations to ARCore/Sceneform SDK.</p><ol><li><em>Augmented Faces </em>works only with the Front Camera.</li><li>Not all devices support ARCore. Most of the newer Android devices do support it now, but we still have some percentage of our audience who won’t be able to use ARCore based apps.<br>You can find the list of supported devices here:<br><a href="https://developers.google.com/ar/discover/supported-devices">https://developers.google.com/ar/discover/supported-devices</a></li><li>The 3D renderable needs to be configured/corrected a little bit as per the template provided with the Sceneform SDK.</li></ol><h4>Notes</h4><p>There are a lot of details we can go into, such as:</p><ul><li>Face mesh bones, and how to anchor renderables to these</li><li>File formats to use for various use-cases</li><li>Runtime transformation of renderables</li><li>Setting colors and material properties dynamically</li><li>Loading 3D models over the network</li><li>Model compression</li></ul><p><strong>In the next part of this article, we will be discussing the challenges in converting 3D models to Sceneform asset format.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4a40c993ec4" width="1" height="1" alt=""><hr><p><a href="https://blog.lenskart.com/augmented-faces-using-googles-sceneform-sdk-e4a40c993ec4">Augmented Faces Using Google’s Sceneform SDK</a> was originally published in <a href="https://blog.lenskart.com/">The Lenskart Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>