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 app’s AndroidManifest.xml. You can edit Lime’s copy, but that’ll change it for every project, and it’ll get reverted when you update Lime. You can edit the copy in Export/android, but that’ll get reverted the very next time you compile. You can make an extension, but that’s overkill.
Creating Your Own Manifest File
First things first. Before you can overwrite AndroidManifest.xml, you need to define what exactly you want to overwrite it with.
Conveniently, Lime has a whole folder of template files you can copy from. In this example, we’re replacing an Android template, so we look inside templates/android. A quick search turns up the file inside templates/android/template/app/src/main. (The “app/src/main” part will be important later; remember it.)
Copy AndroidManifest.xml into your project. I usually make a “templates” folder for files like this, but if you have your own way to organize it, that’s fine too. Open up your copy of the file and add the following somewhere between <manifest> and </manifest>:
<supports-screens
android:anydensity="true"
android:smallscreens="true"
android:normalscreens="true"
android:largescreens="true"
android:xlargescreens="true" />
Using Your Manifest File
Finally! Enough preparation, it’s time to impose our will upon Lime’s build process. No longer shall we be confined to normalScreens, we shall reach out and conquer anyDensity!
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. In this case, it goes in app/src/main.
Which Files Can be Overridden?
To answer this question, first compile your project for Android, and open Export/android/bin (or 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" />