如何实现多个Android版本使用不同的库?
我知道有很多关于与免费/付费版本相关的多个 Android 版本的问题,但这可能有点不同。
我的应用程序目前使用 AdMob 进行广告,并在 Android Market 和 Samsung App Store 上发布。不幸的是,三星商店未来将要求每个人迁移到自己的广告网络,三星 AdHub。 AdMob 和 AdHub 都有自己的库和 SDK。
我正在寻找一种构建 2 个不同版本的解决方案,一个包括 AdMob,另一个包括 AdHub(以及所有必要的代码)。当发布新版本时,我需要什么解决方案才能轻松构建 2 个版本而不需要太多麻烦?
许多解决方案建议将主项目移动到库项目中,然后构建两个其他应用程序,其中包括库项目(基础项目)。但我不太喜欢这种解决方案(如果可能的话,我更喜欢将我的应用程序保留在一个项目中),我正在尝试寻找替代方案,然后决定哪一个更适合我的需求。
I know there are a lot of questions out there about multiple Android versions pertaining to free/paid versions but this might be a little different.
My app currently uses AdMob for advertising and it's published on the Android Market and on the Samsung App Store. Unfortunately, the Samsung store will require everyone to migrate to their own Ad Network in the future, Samsung AdHub. Both AdMob and AdHub have their own libraries, their own SDKs.
I'm looking for a solution to build 2 different versions, one including AdMob the another including AdHub (and all the necessary code). What solutions do I have to easily build 2 versions without much hassle when it's time for a new version release?
Lots of solutions recommend to move the main project into a library project and then build 2 other apps which include the library project (the base project). But I'm not very fond of that solution (I prefer to keep my app in one single project, if possible) and I'm trying to look for alternatives and then make up my mind about which one is better for my needs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为您应该使用策略设计模式在代码中实现这一点。它非常适合,并且可以在您喜欢的任何触发器上切换(甚至在运行时)。如果为每个 jar 文件创建一个外观,您将能够在构建时更改依赖关系,并具有相同的源代码。
使用此方法的其他选项只是在应用程序中进行一些配置来确定要使用哪个库。
I'd think you should make this possible in your code using the Strategy design pattern. It suites well and can be switched at any trigger your like (even on runtime). If you make a facade for each jar file you will be able to change the dependencies while building, having the same source code.
Other option with this method is just making some configuration in your application that determines which library to use.
可以在这里找到一些有趣的解决方案:
https://groups.google.com /d/topic/android-developers/8pRugcnzR_E/讨论
Some interesting solutions can be found here:
https://groups.google.com/d/topic/android-developers/8pRugcnzR_E/discussion
现在的方法是使用 Android Studio 并为每个应用程序使用不同的 Gradle 风格。因此,如果您修复核心功能,您可以快速为每个应用商店及其自己的广告网络进行构建。
The way to go now is to use Android Studio and use different Gradle flavors for each app. Thus, if you fix core functionality, you can quickly do a build for each appstore with it's own ad network.
图书馆项目是一条出路。创建一个基础项目,在其中实现所有常见的内容,然后创建两个单独的项目,将通用项目用作“库”。然后只需实现使应用程序表现不同所需的其余部分即可。
Library Projects is the way to go. Create a base project where you implement all the common stuff and then create two separate project that use the common one as a "Library". then just implement the rest needed to make the Apps behave differently.