Skip to content

This code sample shows how you can leverage Play Feature Delivery to enable on-demand delivery of the Amazon IVS Player SDK on Android.

License

Notifications You must be signed in to change notification settings

aws-samples/amazon-ivs-on-demand-android-demo

Amazon IVS On-demand SDK delivery Android demo

This code sample shows how you can leverage Play Feature Delivery to enable on-demand delivery of the Amazon IVS Player SDK, which will be downloaded from the Google Play Store when requested.

A modularized app will create clearly defined boundaries between separate parts of your application, and allowing you to decrease your app’s size further. In practice, this means that you can call an API to install the module (the Amazon IVS Player SDK) after the app has been downloaded and installed on your user’s device. Using on-demand installation saves initial download time and size.

This is achieved by releasing your Android application with .aar bundles. (Note: this cannot be done with an .apk)

Setup Instructions

The setup is tailored for a project that uses the nav-graph navigation. Follow along for instructions. If needed, please refer to the Quick Start Guide provided by Google.

Step 1: Add a new Dynamic Module to your project

Click on File -> New -> New Module...

Select Dynamic Feature and enter all the values necessary.

Pick the desired feature type - in our case we use on-demand delivery.

Step 2: Create or update you Application class

The class must extend SplitCompatApplication - don't forget to add it as name in your application tag in theAndroidManifest.xml file. Override the attachBaseContext(..) function of the application and call SplitCompat.install(this).

Step 3: Install the split module in every activity that needs access to the feature module

If you wish to use the feature module after it's downloaded you must call SplitCompat.installActivity(this) in every activity that needs access to it. If you plan to use the module in an fragment, you must install it in the parent activity of the fragment.

Step 4: Add the play core and navigation feature-delivery dependency

Add the following:

api "androidx.navigation:navigation-dynamic-features-fragment:2.3.5"
implementation "com.google.android.play:core:1.10.0"

to your main gradle file to enable feature module loading when using the navigate(..) function to switch between fragments.

Step 5: Update your navigation host to use DynamicNavHostFragment

In your activity layout file change the navigation host name to:

android:name="androidx.navigation.dynamicfeatures.fragment.DynamicNavHostFragment"

Step 6: Listen for the feature download or add a custom AbstractProgressFragment

There are two ways to handle the feature download, either use the InstallManager to observe the feature download or create a fragment that extends the AbstractProgressFragment and implement the 3 callbacks to listener for the download state.

Both appoaches have known issues:

  • The manual install way described here has a bug with the installMonitor.isInstallRequired boolean. It will always return true even if you have the feature installed. This means that when you use the navigate(id, null, null, DynamicExtras(installMonitor) as described there and then use it again when the installation is completed - you'll have your fragment opened twice.
  • The custom progress fragment has a bug with the onProgress callback - it doesn't return values smoothly, so it'll jump from 1%-2% to 100%.

The demo app in this repository uses the custom progress fragment. The fragment is launched automatically when navigating to a fragment that is inside a feature module. To enable the progress fragment - set it as value in your nav_graph like so:

app:progressDestination="@id/loading_fragment"

When using the custom progress fragment you don't have to worry about download / install states as it will be handled automatically. If the fragment is loaded or already pre-loaded, it will be opened.

Step 7: Test your app

To test how the feature delivery works either upload your app to the Google Play Store, or use the bundletool to simulate the experience.


End result

amazon-ivs-on-demand-android-demo.mp4

Amazon IVS Documentation

License

This sample code is made available under a modified MIT license. See the LICENSE file.

About

This code sample shows how you can leverage Play Feature Delivery to enable on-demand delivery of the Amazon IVS Player SDK on Android.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Languages