Thursday, March 29, 2012

Unity3d and custom AndroidManifest.xml: post processing when pre-processing doesn't work

In our Unity3d project, we need a custom AndroidManifest.xml. Our first use was to increase the build number. This is required so that our files can be deployed to appaloosa-store. Like testflight the store requires new versions to have an increased version number.

Unity3d lets you customize your AndroidManifest.xml by placing a file under Assets/Plugins/Android/AndroidManifest.xml. As said earlier, we generate this file using StringTemplate. This file is supposedly copied under the APK packaging directory during the build (under Temp).

Except it doesn't work for us. For some reason Unity3.5 copies then overwrites the file during the build process. I am not really sure why. Unity's support told me the cause might be because we are using another plugin (we are using the playtomic one).

So we implemented a work-around. We still generate the proper AndroidManifest.xml during build pre-processing but as this file doesn't end up in the APK, we also post-process the APK before deploying it to appaloosa-store.

The script for post-processing the APK is found here and is heavily inspired by this unity3d forum post. Note that we use the debug.keystore instead.

And here is how we invoke the script:

echo "Forcing the generated manifest"

export PATH=$ANDROID_HOME/platform-tools:$PATH

./scripts/  target/Our.apk  Assets/Plugins/Android/AndroidManifest.xml target/Our.apk


  1. Hey,

    thanks for the nice post.
    To me it seems like the file under Assets/Plugins/Android/AndroidManifest.xml is touched but some parts get overriden afterwards, like the bundle version code.
    Have you considered to modify the 'ProjectSettings.asset' in a pre build step and update the 'AndroidBundleVersionCode'


  2. This is extremely helpful article. Saved me huge amount of time. Thanks for posting this!

  3. Android is a software package and Linux based operating system for mobile devices. Android is used for touchscreen based smartphones, tablets etc. for more information follow Android Online Training