问题描述
我查看了Google UniversalMusic Player代码示例,该示例使用通用代码库制作了一个通用APK,以支持从手机到电视的所有设备类型,如下所示: https://github.com/googlesamples/android-UniversalMusicPlayer
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
我的要求是让单个APK在移动设备和电视上支持不同的最低API版本-移动电话的最低API-15和电视的最低API-21(因为Android TV仅从API-21开始)
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 !
推荐答案
我认为最好的解决方案是创建两个APK.
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.
创建通用模块后,只需将其添加到移动和电视Gradle中:compile project(':common')
.
After creating the common module, just add to both mobile and tv gradle: compile project(':common')
.
然后,您将拥有通用模块中所有可用于移动和电视的代码.因此,对于手机和电视,您将拥有不同的gradle文件(以及不同的sdk版本),并且您将拥有一个通用的模块,可以保留它们都将使用的代码.
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.
要发布APP,您可以按照此,这样您就可以在同一个Play商店项目中发布这两个APK.
To publish the APP you can follow this so you can publish both APK in the same play store project.
这篇关于有什么方法可以使移动设备上的API-15 +和电视上的API-21 +通用APK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!