Customizing AndroidManifest.xml

What is the correct (or just working) way now to customize AndroidManifest.xml when building an app for Android? I just need to modify android:versionCode and remove excessive permissions.

Last time I had to build a release version of my game I used OpenFL 3.6.1 and I just overwritten a generated manifest with my own file (by adding something like <template path="manifest.xml" rename="app/src/main/AndroidManifest.xml"/> to project.xml). It was hacky and inflexible, but it worked and that was enough.

Now I’m ready to release an update which uses OpenFL 4.5.0 and I’ve just discovered that the trick with overwriting doesn’t work anymore (at least for me). Judging by the structure of the export folder tree the whole process has changed dramatically. Also there is a file with the name manifest-merger-release-report.txt deep in the folders which suggests that the final AndroidManifest.xml is a result of some merging, presumably of the file I provide with something else. Anyway, I get a wrong version code and permissions the game doesn’t need.

So could someone explain me how can I change the version code and remove permission nodes in AndroidManifest.xml?

I would recommend using <template path="templates" /> with a custom template directory of your own. This works like source paths, so you can define multiple tags, and the tools will handle overrides based on order.

Look at the structure of the Lime or OpenFL “templates” directory and use the same file/folder order for any files you want to override

I think android/template/app/src/main/AndroidManifest.xml is what you’re looking for, so mirror the same in your own template path :slight_smile:

Thanks @singmajesty! I have done as you suggested and everything works fine. There is still a problem though - I can’t get rid of stupid permissions. They get mixed into my manifest and I don’t understand what’s their source.

Here are the last lines of manifest-merger-release-report.txt:

android:uses-permission#android.permission.WRITE_EXTERNAL_STORAGE
IMPLIED from /Users/odolya/Projects/Haxe Projects/frostfire/Export/android/final/bin/app/src/main/AndroidManifest.xml:2:1-25:12 reason: org.haxe.extension has a targetSdkVersion < 4
android:uses-permission#android.permission.READ_PHONE_STATE
IMPLIED from /Users/odolya/Projects/Haxe Projects/frostfire/Export/android/final/bin/app/src/main/AndroidManifest.xml:2:1-25:12 reason: org.haxe.extension has a targetSdkVersion < 4
android:uses-permission#android.permission.READ_EXTERNAL_STORAGE
IMPLIED from /Users/odolya/Projects/Haxe Projects/frostfire/Export/android/final/bin/app/src/main/AndroidManifest.xml:2:1-25:12 reason: org.haxe.extension requested WRITE_EXTERNAL_STORAGE

They are not even the usual set of vibrate, internet and wake lock!

I wonder where the target SDK version is set?

Ok, here is what I have found:

There is an android manifest for “extension-api”. To be honest I don’t have a clear idea what extension-api is and why it needs its own AndroidManifest.xml, but I know that it gets merged with the manifest of my app.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.haxe.extension" >

</manifest>

Looks like a template for extensions, although I don’t use any extensions. Anyway, it doesn’t have <uses-sdk/> node and it means that targetSdkVersion is not specified. When this attribute is not specified it gets the value of minSdkVersion attribute by default. But this one is not specified either and its default value is 1. As a result this empty manifest tells the builder that targetSdkVersion=1. I didn’t know it can affect permissions, but apparently it can:

If the lower-priority manifest file has a lower value for targetSdkVersion that provides it an implicit permission, and the higher-priority manifest does not have the same implicit permission (because it’s targetSdkVersion is equal to or higher than the version in which the restriction was added), then the merger tool explicitly adds the system permission to the merged manifest.

This way my app gets unneeded permissions WRITE_EXTERNAL_STORAGE and READ_PHONE_STATE.

I don’t know if something is broken in my installation of OpenFL/lime or is it a glitch of the latest versions. I have solved my problem by adding <uses-sdk android:minSdkVersion="4" /> to that empty manifest file. :raised_hands:

Like this?

Yeah, exactly. Probably there should be more like this:

<uses-sdk android:minSdkVersion="::ANDROID_MINIMUM_SDK_VERSION::"/>

but I’m not sure how/when these values are substituted, so I left a magic number there :slight_smile: