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 https://gist.github.com/2235151 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"

ANDROID_HOME=/Applications/android-sdk-macosx
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH

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

3 comments:

  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'

    Christoph

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

    ReplyDelete
  3. This site is very useful for everyone. I have found lot of stuff here, which is very interesting, but don't forget to check my website. We have amazing jackets and coats. All products are available at discounted price. We have limited stock. Order your favorite ones now. Mark L. Young Filthy Rich Green Jacket

    ReplyDelete