24

I'm developing an Android SDK library. In this library I've declared and used some Activities. Now I've tried to include the library in an application but I've noticed that I must declare all the library activities in the app. This is a very bad thing because in the library, I've included a lot of activities and the developer has to copy all the activities in his own app. Is there a solutions to this?

Mechanical snail
  • 29,755
  • 14
  • 88
  • 113
ets23
  • 241
  • 1
  • 2
  • 3
  • 2
    what do you mean copy the activities to the other app? are you talking about the manifest? If so, Google says they intend to add manifest merging in the future but you need to copy/paste for now. If not, you are doing it wrong. – Nathan Schwermann Feb 18 '11 at 21:46
  • @schwiz manifestmerger.enabled=true is exist now, but we should force developers(who use my library in their apps), to set min and target SDK to our min and target sdk! (source: http://stackoverflow.com/questions/10976635/using-the-new-manifestmerger-property-in-android#21397467) – Dr.jacky May 12 '15 at 07:12

2 Answers2

26

No, this is a known limitation of the libraries at the moment. There is a lot of discussion in the android development community of fixing this in the future, but for now it is a limitation of how they do libraries.

From the doc

In the manifest file of the application project, you must add declarations of all components that the application will use that are imported from a library project. For example, you must declare any <activity>, <service>, <receiver>, <provider>, and so on, as well as <permission>, <uses-library>, and similar elements.

Also, excellent answer here by Mark Murphy.

Jay Lieske
  • 4,788
  • 3
  • 30
  • 41
Nick Campion
  • 10,479
  • 3
  • 44
  • 58
  • Thanks for your reply.. Maybe i've to use Dialogs instead of activities. This could be avoid this limitation. Do you agree? – ets23 Feb 18 '11 at 21:58
  • (in addition: i don't need to create a jar) – ets23 Feb 18 '11 at 22:05
  • The only part of your library that will need to be in the consuming project is the declaration in the android manifest. I'm not sure what you mean about using dialogs instead of activities. – Nick Campion Feb 19 '11 at 00:04
  • If i use Dialogs to display user interfaces i don't need to declare them in the manifest. – ets23 Feb 19 '11 at 12:03
  • 1
    Architecturally there is a significant difference between dialogs and activities. Dialogs will share much more state with the application consuming them and you'll need to setup some structured mechanism for the consuming app to invoke them. It really depends on what you're trying to do to determine if that is a viable alternative. – Nick Campion Feb 19 '11 at 17:13
22

Update 1: When using Gradle, Manifest merging is done now automatically. More details on how it works and how to resolve conflicts can be found here (thanks for the remark guy.gc)

Original post:

To update this thread: auto merge is now possible. You would only have to add

manifestmerger.enabled=true

to your project.properties. Using the new "manifestmerger" property in Android discusses this also.

I know this is an old thread but I just stumbled upon it and want to prevent others (me included) from thinking it is not possible. This one line was totally enough in my projects to make use of Activities in the library-consuming App.

Community
  • 1
  • 1
Stefan Medack
  • 2,731
  • 26
  • 32
  • 1
    Actually manifest merging is done automatically. http://developer.android.com/tools/building/manifest-merge.html If needed you can define how conflicts are resolved – guy.gc Mar 17 '16 at 10:04
  • 1
    Thanks for the comment @guy.gc, I will update the answer – Stefan Medack Apr 22 '16 at 08:46