Renaming the Android Manifest package
I recently needed to be able to change the package name of an app at build time. This is a common need when you have a paid and a free version of an app. It’s also useful if you want to be able to install multiple versions of an app on your phone, such as a “dev” and a “stable” build.
One way to do it is to transform the whole project as a library project, and then create one final project for each version, that depends on the library project.
There is another way: aapt has a
--rename-manifest-package parameter that rewrites the package name of the binary
AndroidManifest.xml file in the final APK.
Here is what aapt help says:
The great advantage is that your code won’t change, the R class stays identical.
Since r17, this option is available in the aapt Ant task, through the
manifestpackage attribute. You’ll need to override the
-package-resources target, copied from the SDK
android:apk goal of the android-maven-plugin has a renameManifestPackage parameter.
One last thing
If you load some resource ids at runtime, you may need to update your code.
I used to do this:
This usually works great, especially in library projects where you do not know the package name.
However, the problem here is that the resources were processed before the package name was finally updated. So
packageName is wrong.
It’s easy to fix though, by retrieving the package name of another resource with
Let’s create a resource id dedicated to that purpose, for example in
And now we get the right package:
This tip helps creating different versions of the same app.
As you can see on this screenshot, the package name can then be set as a build parameter, to create parameterized builds in Jenkins.