How can I support my Android application for multiple Android stores?

白昼怎懂夜的黑 提交于 2019-12-03 06:34:23

I would start by refactoring your existing codebase into an Android Library Project. This is pretty easy to do. Be sure to read this. The documentation is pretty sparse but I was able to get it to work with it. Be careful to follow the section "Declaring library components in the the manifest file" exactly.

So to refactor into a library you basically mark the existing project as a library project. You just have to tick a box in the projects settings (see the link).

Now go to the library and we want to change the package name to something different. So for example if your released version package is com.mywebsite.myappname.android_market then I would rename this to com.mywebsite.myappname.common_code

You can right click the Project and select Android Tools->Rename application package. This half worked for me. I also had to manually rename all references in the code to my R class manaully. You can just use a global search replace though to rename from com.mywebsite.myappname.android_market.R to com.mywebsite.myappname.common_code.R

Now your library is ready

Now time to make the actual project that you will build.

Create a new android project and name with the package name for android market such as com.mywebsite.myappname.android_market. Follow the instructions on the link to add your new commons library as a library this package uses.

One limitation with Android Library Projects is that the manifest of the library will NOT be merged into the manifest of your top level project. You need to paste it in there by hand. Also (see link) you need to make sure everything in your manifest uses fully qualified package names. So if you used to have activity names such as android:name=".SplashScreenActivity" change it to android:name="com.mywebsite.myappname.common_code.SplashScreenActivity"

So again you need to merge everything by hand, including permissions, intents, activities etc.

Now just build the top project and you are good. Make a wrapper for each variant that you want to build.

You could also have these new top level projects implement anything that is different between your different versions. So your Android Market wrapper could implement one splash screen, and your Amazon version a different splash screen. Or you could just use an enum in your common project to drive it an keep both splash screens in there.

Another nice feature is that resources in the top project will override resources in the library if they are provided. So if you want to for instance on your splash have an Amazon Version Logo and a Android Market logo that changes based on the version just use the same image name as in commons and put a different copy in the two versions.

While not directly related to your question I encountered a similar roadblock in creating both free and paid versions of my application. Android allows you to export any application as a library. You can find this option within the project properties in Eclipse. So by exporting your entire application as a library, you can then incorporate it in to other applications. Once your library has been exported you can create an Amazon and Google app using the library as a base. This will prevent you from having to rename the XML files to get each application in to a usable state.

Libraries are nice because you can also package up resources with them as well. You can even add resources containing the same name in the client applications and these will overwrite the library's version. So you could have different splash screens based on the market your application is in. The only place libraries fell short for me was including assets. Unfortunately raw, unprocessed assets will not be included in a client application from a library.

I would look into using version control like git and having three branches. One branch would not have a manifest, this core branch would have all common code that you could update once. The other two branches would be Amazon, Google, and what ever else comes up. These branches would have app specific code, the manifest, splash screens etc. When your done working in your core branch and want to push updates, you can make a temp branch off core called googleRelease (or something) and merge your google branch.

This is a relatively generic example, git is powerful and you could approach it in a variety of ways.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!