0

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 !

dangling_refrenz
  • 325
  • 3
  • 12
  • Well, the simplest solution is to have one APK with the `minSdkVersion` set to 15. I do not know what benefit there is in making your life more complicated, having to have two separate APK files with two separate `minSdkVersion` values. Whoever is stating this "requirement" should explain, in detail, why this "requirement" exists, as that may have an impact on the solution. – CommonsWare Feb 25 '16 at 18:52
  • I tried that first - but got errors because the leanback APIs are only available for API-21 onwards... found this thread on SO... http://stackoverflow.com/questions/28075533/is-that-leanback-library-support-api-level-19-android-for-tv-app – dangling_refrenz Feb 25 '16 at 18:57
  • "but got errors because the leanback APIs are only available for API-21 onwards" -- that depends on the APIs. Some work from API Level 17 onwards. Beyond that, you will have separate launcher activities anyway (one for mobile devices, one for TVs). So long as you don't have a mobile device attempt to launch a TV activity, you won't have any problem. This isn't a question of `minSdkVersion`; it is a question of ensuring that you deliver the right UI to the user's form factor. – CommonsWare Feb 25 '16 at 19:00
  • yes I was trying to build with minSDK set to API-17 since leanback is available for v17. So will likely settle for 17 instead of 15 – dangling_refrenz Feb 25 '16 at 19:08

1 Answers1

2

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.

mpostal
  • 355
  • 2
  • 8
  • 19