Frage

I have an application that supports different domains. My code is developed under the package: com.example. I would like to publish multiple application under different packages like:

com.example.domain1, com.example.domain2, etc.

In the manifest I define:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.domain1"

.... and for domain2:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.domain2"

The problem I am facing is that once I change the base package name from domain1 to domain2 I need to rename all my packages in the src folder as well as layouts. What I am looking for is to keep the same base packaging com.example and distribute the different apps under its sub-domains.

Is there a better way?

Clarification: When changing the package name, the resources file changes from com.example.R to com.example.domain2.R. This means that I have to go into all src java classes and layouts etc. and update the generated R file location. That is not handy.

War es hilfreich?

Lösung

I ended up marking my main project as a library and then creating a project for each domain and linking to the library.

No need to play around with the manifest or the R.java file.

Thanks to @Tenfour04 for pointing me in the right direction!

Andere Tipps

In your manifest, each Activity, Service, Provider and Receiver has a name attribute. By default they use a shortcut like ".MainActivity" The leading . is a shortcut for the package name at the top level of the manifest.

So if you don't want to rename all those packages in the src folder, just type out explicit names for the Activities, Services, Providers, and Receivers in your manifest, for example, android:name="com.example.sharedmultiprojectdomainname.MainActivity".

If you are using Gradle as your build system, you might want to incorporate build variants into your build, which will solve package problems. More on this can be found in this Google I/O speech

Hope this helps.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top