roostertech

coding and day dreaming

Using Android manifestmerger

If you have a large project that consist of multiple library each contributing Activity/Receiver into the final app, managing the manifest could be a pain. One way of doing this is to keep a giant manifest in the final application but that can get unwieldy. ADT rev 20 introduce a nifty new manifest merger. So the idea is each library would manage their own activities in their own manifest and at build time all the manifest get combined together by manifest mergers.

Steps:

1. Each library will maintain their own manifest. Wrap your activities in an empty application tag. Also no version code is needed as the only the one in the final app matter.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="roostertech.net.stuff">
<application>
activities and stuff
</application>
<uses-sdk android:targetSdkVersion="10" android:minSdkVersion="10" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>

2. Manifest for your application should not contain activities that are already defined in libraries’ manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="roostertech.net.app"
 android:versionCode="1"
 android:versionName="1"
>
 <application
 android:debuggable="true"
 android:icon="@drawable/icon"
 android:label="@string/app_name"
 />
 <uses-sdk
 android:targetSdkVersion="10"
 android:minSdkVersion="10" />
</manifest>

3. Add flag to your application’s project.properties

manifestmerger.enabled=true

And that is all. In case you need to do any post processing on the generated manifest, override “-pre-compile” target.

One response to “Using Android manifestmerger

  1. Pingback: Not the right Activity java.lang.SecurityException: Permission Denial: starting Intent | 我爱源码网

Leave a comment