Android - sharing activities/code between differen

2019-06-17 06:33发布

问题:

I have a single android app with a custom logo, some custom json service endpoints, occasional custom text, and possibly a custom color scheme.

For my client this particular app will need to be rebranded and distributed as an entirely different app about 5-10 times over. So I'm looking for way to reuse the most amount of code - the activities and services will be identical except for the custom things I mentioned.

First off, how can I share projects in the sense that one project will hold all code (including activities), and the others just modify a few values. I can't think of a smart way to share both service code and activity code with the occasional value thrown in via properties.

Do android layout/string resource files have the ability to pull from properties? Can activities be bundled inside a jar and shared with other projects?

回答1:

You can use Android library project to share the common code. Start by reading this article



回答2:

You do not have to have different java namespaces, they can be common for all projects. All you need is to replace resources and modify manifest to contain different namespace for each application. There is no problem with several applications having the same name of classes inside. Unless you want to rebrand it all the way user could not find it is actually the same code, of course.



标签: android share