ExoPlayer’s new modular structure
In ExoPlayer 2.4 we’ve split the library into five modules:
- exoplayer-core: Core functionality (required).
- exoplayer-dash: Support for DASH content.
- exoplayer-hls: Support for HLS content.
- exoplayer-smoothstreaming: Support for SmoothStreaming content.
- exoplayer-ui: UI components and resources for use with ExoPlayer.
This post explains how to depend on these modules and why it may be beneficial to do so.
If you’re using ExoPlayer today, you probably declare it as a dependency in your build.gradle file:
Where 2.X.X is the version of ExoPlayer being used. In practice, however, your app might only use a subset of the functionality provided by the full library. For example, an app that plays only DASH streams doesn’t need the HLS and SmoothStreaming functionality provided by the full library. From ExoPlayer 2.4, such an app can depend on only the Core, DASH and UI modules:
If the app were to also implement its own playback controls and hence not need the UI components provided by the library, it could depend just on the Core and DASH modules:
It’s still possible to depend on the full library if you prefer:
This is equivalent to depending on all of the modules individually.
There are two potential benefits of depending on only the modules you need, rather than the full library:
- Smaller APK size: Whilst ProGuard and shrinkResources could (and still can be) used as effective tools for removing unused functionality, you may find that depending only on specific modules achieves further savings.
- Greater certainty over what code is not in your APK: Depending only on the modules you need gives you greater certainty that functionality in other modules is not being included in or used by your application. Be careful, however, to ensure that such modules are not being included as transient dependencies!
The modularization of ExoPlayer also adds some much needed structure to the ExoPlayer project, which will help to enforce a clean design as the library continues to grow. For example, it makes it impossible for a change to accidentally introduce a dependency between components that should be unrelated, for example a dependency between DASH and HLS components.
In conclusion, modularization benefits both app developers using ExoPlayer and the continued development of ExoPlayer itself. We recommend depending on specific modules rather than the full library when using ExoPlayer 2.4 and above.