0

I am using Android Studio Dolphin and Kotlin. The app has some mp3 files which reside in a Dynamic Feature Module (see the image). The app and the dynamic modules are signed and packaged as Android App Bundle (aab). The app is downloaded and installed a physical Android device and the dynamic packages installed successfully on demand. The problem is whey I try to load an item from the dynamic package. The dynamic package cannot be found. Here is the code:

private fun getResRawIdentifierFromPackage(resName: String, packageName: String): Int { //com.companyname.mainpackage //resName = "aud_affirm_01_02_" //packageName = "com.companyname.dynamic_pack_a_aud_affirm" - our dynamic package name // try { // Test try with base package name to create context val refreshedContext = createPackageContext(packageName, 0).resources

        // returns 0 if no id found
        return refreshedContext.getIdentifier(
            resName,     //"aud_affirm_01_02_"
            "raw",
            packageName // "com.companyname.dynamic_pack_a_aud_affirm"
        )

    } catch (ex: Exception) {
        // Toast.makeText(context, ex.localizedMessage, Toast.LENGTH_LONG).show()
        Log.println(Log.DEBUG, "getResRawIdentifierFromPackage", "getResRawIdentifierFromPackageX: " + ex.localizedMessage  )
        return 0
    }
}

In the build.gradle (project): id 'com.android.dynamic-feature' version '7.3.1' apply false

In the bild.gradle (app): implementation 'com.google.android.play:core:1.10.3'

Everything is configured correctly and the dynamic packages can be installed so the problem is in my code when trying to create a package.

I tried adding the package name in the AndroidManifest.xml: package="com.companyname.dynamic_pack_a_aud_affirm">Project View in Android Studio

The clarify the question: How to access a RESOURCE in RAW directory in a dynamically installed module?

UPDATE 22-03/2023. After changing the names of the dynamic feature modules in the build gradle for the the dynamic on demand modules and i can play audio files from the res\raw\aduio_name without any issues. The problem is with playing video files placed in dynamic feature module. The video files play fine on on a local, physical device and the correct URIs are generated. When uploading to the GooglePlay the videos cannot be played after successful dynamic feature pack install and the URI path is blank. I am using the recommended way to generate the URI as described in: https://developer.android.com/guide/playcore/feature-delivery#resource-uri

Here is my code to get the URI. It works locally but not when on GooglePlay Internal Testing.

@Composable
fun getResourceUri(resourceId: Int): Uri {
    val context = LocalContext.current
    return Uri.Builder()
        .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
        .authority(context.packageName) 
        .appendPath(context.resources.getResourceTypeName(resourceId))
        .appendPath(
            String.format(
                "%s%s:%s",
                context.resources.getResourcePackageName(resourceId), 
                context.resources.getResourceEntryName(resourceId)
            )
        )
        .build()
}
TXTDEV
  • 1
  • 2

0 Answers0