Android dynamic delivery in Library project

464 views Asked by At

I'm building an Android Library and I would like some of its features to be downloaded only on-demand, as dynamic feature modules.

Is it possible to use Dynamic Delivery (from Google Play Core library) in an Android Library project?

I tried adding dynamicFeatures = [':my_dynamic_feature'] to my Library project's build.gradle, but when I try to do a Gradle sync, I'm getting the following error:

Could not set unknown property 'dynamicFeatures' for object of type com.android.build.gradle.LibraryExtension.

For this reason I suspect that Dynamic Delivery is only supported for 'com.android.application' but not for 'com.android.library'.

Can someone confirm whether this is supported or not?
Or at least planned for a future release of Play Core library?

Thanks!

1

There are 1 answers

0
shubhamgarg1 On

Yes, currently it can only be used from the application class.

If you want to design your library in a way that it can later support a dynamic feature, you can move the dynamic feature related code to a separate library, let's call it DFLibrary. Instead of directly calling the DFLibrary methods, you can use reflection.

Now, any client that wants to use your library and the DFLibrary but does not want to handle dynamic feature installation can include the dependencies of both your library and DFLibrary.

In case the client wants to use DFLibrary as a dynamic feature module, it can itself create a Dynamic feature module and include the DFLibrary dependency in it and then handle the downloading of that dynamic feature module.