phil155 phil155 - 1 year ago 89
Android Question

Android maven plugin: renameManifestPackage unexpected behavior

I encountered the following problem:
The app I implemented includes another project as a dependency (of type aar). Both projects share the same parent pom. The dependency includes resources, which the app is using. To access the resources within the library project, the resource id is fetched by calling

context.getResources().getIdentifier(resourceKey, resourceType, packageName)
. I get the package name by calling
on the given
Before changing the package names of the projects by using


accessing the library resources worked fine. But after renaming the package name of the app I get a
because the
call still expects the old package name of the app and calling
returns the new one (as expected).

Now I wonder if I'm missing something or if this a bug in the android maven plugin?

Answer Source

The answer is: I missed something. I opened a ticket regarding this problem at the project site ( It turned out that what I've seen as a problem is expected behavior of the renameManifestPackage configuration, since renaming not only the manifest package but also the resources is out of scope for this configuration.

There is, however, a not too ugly workaround for this:

Instead of retrieving the package name from the Context object, it is possible to retrieve it from the Resources object. Here comes the part where it gets a bit ugly: A resource with the single purpose of retrieving the package name needs to be added since other resources are usually subjects to change:

<?xml version="1.0" encoding="utf-8"?>
    <!-- The only purpose of this resource is to retrieve the resource package name -->
    <item name="used_for_package_name_retrieval" type="id"/> 

Now you can retrieve the resource package name as follows:

Resources resources = context.getResources();
String packageName = resources.getResourcePackageName(;

Credit goes to:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download