I looked at the Google UniversalMusic Player code sample for making a common APK with a common codebase to support all device types from mobiles to TV, as given here: https://github.com/googlesamples/android-UniversalMusicPlayer
My requirement is to have a single APK support different min API versions on mobile and TV - min API-15 for mobile and min API-21 for TV (since Android TV starts only from API-21)
How could I do this with minimal code duplication (ie. if making a separate mobile and tv module then I have to replicate the code in both modules) ? Thanks !
I think the best solution is to create two APKs.
You can create a project for mobile and TV, they will be in separate modules, but in the same project, then you can create a common module that you will put everything that both will use, to avoid duplicated code.
After creating the common module, just add to both mobile and tv gradle: compile project(':common')
.
Then you will have all the code that is in the common module available for both mobile and tv. So you will have different gradle files (and different sdk versions) for mobile and TVs and you will have a common module that you can keep the code that both will use.
I think this is the best approach because you can put all controls that you need on TV (like remote control, view focus control, etc) in the TV project, it will not have any impact in the mobile.
To publish the APP you can follow this so you can publish both APK in the same play store project.