What do you do if you need to change AndroidManifest.xml, and OpenFL’s customization options aren’t enough? Sure you can add permissions using
<config:android permission="android.permission.WHATEVER" />, and change the app title, and so on…
But what if you want to support multiple screen sizes? You need to include a
<supports-screens> tag, or Google may hide your app from tablet users! This is yet another of the billions of scenarios that OpenFL fails to account for. (Sheesh, OpenFL dev team, get a move on.)
What you need is full control of the AndroidManifest.xml, but if you change it in the Lime project, it’ll just get reverted when you update to a new version. And making an extension for this is just plain overkill.
Creating Your Own Manifest File
Before you can worry about overriding AndroidManifest.xml, you’re going to need something to replace it with. Ideally something as similar as possible, to avoid breaking anything. Start by getting a copy of Lime’s template file. (For the record, if you want to replace a different template file, search this folder.)
Save your copy of AndroidManifest.xml somewhere in your project. I suggest making a “templates” folder for files like this, but you can put it wherever. Open up your copy of the file and add the following right before
Using Your Manifest File
Finally! Enough preparation, it’s time to circumvent the natural order and impose our will upon OpenFL! No longer shall we be bound by the constraints imposed upon us! Together we shall rise up, take control, and-
What’s that? “Get on with it”? Oh fine…
Type this in your project.xml file:
<template path="templates/AndroidManifest.xml" rename="app/src/main/AndroidManifest.xml" />
Yep, that’s it.
path tells it where (in your Haxe project) to get the file from, and
rename tells it where (in your Android project) to put it.
Which Files Can be Overridden?
To answer this question, first compile your project for Android, and open
bin/android/bin). Take a good look – everything the light touches is your kingdom. By which I mean you can override the files in that folder.
However, you need to make sure put your file in the same folder as the file you’re overriding. GameActivity.java is located in
app/src/main/java/org/haxe/lime, so you’d put this in project.xml:
<template path="templates/GameActivity.java" rename="app/src/main/java/org/haxe/lime/GameActivity.java" />