pandemonium_engine_docs/engine_development/compiling/compiling_for_android.md

222 lines
8.1 KiB
Markdown
Raw Normal View History

2023-01-12 20:49:14 +01:00
# Compiling for Android
This page describes how to compile Android export template binaries from source.
If you're looking to export your project to Android instead, read `doc_exporting_for_android`.
## Note
In most cases, using the built-in deployer and export templates is good
enough. Compiling the Android APK manually is mostly useful for custom
builds or custom packages for the deployer.
Also, you still need to follow the steps mentioned in the
2023-01-12 19:29:11 +01:00
`doc_exporting_for_android` tutorial before attempting to build
a custom export template.
## Requirements
For compiling under Windows, Linux or macOS, the following is required:
2023-01-12 20:57:31 +01:00
- `Python 3.5+ ( https://www.python.org/downloads/ )`.
- `SCons 3.0+ ( https://scons.org/pages/download.html )` build system.
- `Android SDK ( https://developer.android.com/studio/#command-tools )`
(command-line tools are sufficient).
- Required SDK components will be automatically installed.
- On Linux,
**do not use an Android SDK provided by your distribution's repositories as it will often be outdated**.
- Gradle (will be downloaded and installed automatically if missing).
- JDK 11 (either OpenJDK or Oracle JDK).
2023-01-12 20:57:31 +01:00
- You can download a build from `ojdkbuild ( https://github.com/ojdkbuild/ojdkbuild )`.
2024-03-16 20:56:52 +01:00
To get the Pandemonium source code for compiling, see `doc_getting_source`.
2024-03-16 20:56:52 +01:00
For a general overview of SCons usage for Pandemonium, see `doc_introduction_to_the_buildsystem`.
2023-01-12 20:49:14 +01:00
## Setting up the buildsystem
2023-01-12 19:43:03 +01:00
- Set the environment variable `ANDROID_SDK_ROOT` to point to the Android
SDK. If you downloaded the Android command-line tools, this would be
the folder where you extracted the contents of the ZIP archive.
- Install the necessary SDK components in this folder:
- Accept the SDK component licenses by running the following command where `android_sdk_path` is the
path to the Android SDK, then answering all the prompts with `y`:
2023-01-12 22:00:14 +01:00
```
2023-01-12 20:47:54 +01:00
tools/bin/sdkmanager --sdk_root=( android_sdk_path> --licenses
2023-01-12 22:00:14 +01:00
```
- Complete setup by running the following command where `android_sdk_path` is the path to the Android SDK.
2023-01-12 22:00:14 +01:00
```
2023-01-12 20:47:54 +01:00
tools/bin/sdkmanager --sdk_root=( android_sdk_path> "platform-tools" "build-tools;30.0.3" "platforms;android-29" "cmdline-tools;latest" "cmake;3.10.2.4988404"
2023-01-12 22:00:14 +01:00
```
To set the environment variable on Windows, press :kbd:`Windows + R`, type "control system", then click
on **Advanced system settings** in the left pane, then click on **Environment variables** on the window that appears.
To set the environment variable on Linux or macOS, use `export ANDROID_SDK_ROOT=/path/to/android-sdk` where `/path/to/android-sdk`
points to the root of the SDK directories.
## Building the export templates
2024-03-16 20:56:52 +01:00
Pandemonium needs two export templates for Android: the optimized "release"
2023-01-12 19:43:03 +01:00
template (`android_release.apk`) and the debug template (`android_debug.apk`).
As Google will require all APKs to include ARMv8 (64-bit) libraries starting
from August 2019, the commands below will build an APK containing both
ARMv7 and ARMv8 libraries.
2024-03-16 20:56:52 +01:00
Compiling the standard export templates is done by calling SCons from the Pandemonium
root directory with the following arguments:
- Release template (used when exporting with **Debugging Enabled** unchecked)
2023-01-12 22:00:14 +01:00
```
scons platform=android target=release android_arch=armv7
scons platform=android target=release android_arch=arm64v8
cd platform/android/java
# On Windows
2024-03-16 20:56:52 +01:00
.\gradlew generatePandemoniumTemplates
# On Linux and macOS
2024-03-16 20:56:52 +01:00
./gradlew generatePandemoniumTemplates
2023-01-12 22:00:14 +01:00
```
2023-01-12 19:43:03 +01:00
The resulting APK will be located at `bin/android_release.apk`.
- Debug template (used when exporting with **Debugging Enabled** checked)
2023-01-12 22:00:14 +01:00
```
scons platform=android target=release_debug android_arch=armv7
scons platform=android target=release_debug android_arch=arm64v8
cd platform/android/java
# On Windows
2024-03-16 20:56:52 +01:00
.\gradlew generatePandemoniumTemplates
# On Linux and macOS
2024-03-16 20:56:52 +01:00
./gradlew generatePandemoniumTemplates
2023-01-12 22:00:14 +01:00
```
2023-01-12 19:43:03 +01:00
The resulting APK will be located at `bin/android_debug.apk`.
### Adding support for x86 devices
If you also want to include support for x86 and x86-64 devices, run the SCons
2023-01-12 19:43:03 +01:00
command a third and fourth time with the `android_arch=x86`, and
`android_arch=x86_64` arguments before building the APK with Gradle. For
example, for the release template:
2023-01-12 22:00:14 +01:00
```
scons platform=android target=release android_arch=armv7
scons platform=android target=release android_arch=arm64v8
scons platform=android target=release android_arch=x86
scons platform=android target=release android_arch=x86_64
cd platform/android/java
# On Windows
2024-03-16 20:56:52 +01:00
.\gradlew generatePandemoniumTemplates
# On Linux and macOS
2024-03-16 20:56:52 +01:00
./gradlew generatePandemoniumTemplates
2023-01-12 22:00:14 +01:00
```
This will create a fat binary that works on all platforms.
The final APK size of exported projects will depend on the platforms you choose
to support when exporting; in other words, unused platforms will be removed from
the APK.
### Cleaning the generated export templates
You can use the following commands to remove the generated export templates:
2023-01-12 22:00:14 +01:00
```
cd platform/android/java
# On Windows
2024-03-16 20:56:52 +01:00
.\gradlew cleanPandemoniumTemplates
# On Linux and macOS
2024-03-16 20:56:52 +01:00
./gradlew cleanPandemoniumTemplates
2023-01-12 22:00:14 +01:00
```
## Using the export templates
2024-03-16 20:56:52 +01:00
Pandemonium needs release and debug APKs that were compiled against the same
version/commit as the editor. If you are using official binaries
for the editor, make sure to install the matching export templates,
or build your own from the same version.
2024-03-16 20:56:52 +01:00
When exporting your game, Pandemonium opens the APK, changes a few things inside and
adds your files.
Installing the templates
2023-01-12 19:43:03 +01:00
The newly-compiled templates (`android_debug.apk`
2024-03-16 20:56:52 +01:00
and `android_release.apk`) must be copied to Pandemonium's templates folder
with their respective names. The templates folder can be located in:
2024-03-16 20:56:52 +01:00
- Windows: `%APPDATA%\Pandemonium\templates\( version>\`
- Linux: `$HOME/.local/share/pandemonium/templates/( version>/`
- macOS: `$HOME/Library/Application Support/Pandemonium/templates/( version>/`
2023-01-12 20:47:54 +01:00
`( version )` is of the form `major.minor[.patch].status` using values from
2024-03-16 20:56:52 +01:00
`version.py` in your Pandemonium source repository (e.g. `3.0.5.stable` or `3.1.dev`).
2023-01-12 19:43:03 +01:00
You also need to write this same version string to a `version.txt` file located
next to your export templates.
However, if you are writing your custom modules or custom C++ code, you
might instead want to configure your APKs as custom export templates
here:
2023-01-12 20:16:00 +01:00
![](img/andtemplates.png)
You don't even need to copy them, you can just reference the resulting
2024-03-16 20:56:52 +01:00
file in the `bin\` directory of your Pandemonium source folder, so that the
next time you build you will automatically have the custom templates
referenced.
## Troubleshooting
### Platform doesn't appear in SCons
2023-01-12 19:43:03 +01:00
Double-check that you've set the `ANDROID_SDK_ROOT`
environment variable. This is required for the platform to appear in SCons'
list of detected platforms.
2023-01-12 20:47:54 +01:00
See `Setting up the buildsystem ( doc_android_setting_up_the_buildsystem )`
for more information.
### Application not installed
Android might complain the application is not correctly installed.
If so:
- Check that the debug keystore is properly generated.
- Check that the jarsigner executable is from JDK 8.
2023-01-12 20:57:31 +01:00
If it still fails, open a command line and run `logcat ( https://developer.android.com/studio/command-line/logcat )`:
2023-01-12 22:00:14 +01:00
```
adb logcat
2023-01-12 22:00:14 +01:00
```
Then check the output while the application is installed;
the error message should be presented there.
Seek assistance if you can't figure it out.
### Application exits immediately
If the application runs but exits immediately, this might be due to
one of the following reasons:
- Make sure to use export templates that match your editor version; if
2024-03-16 20:56:52 +01:00
you use a new Pandemonium version, you *have* to update the templates too.
- `libpandemonium_android.so` is not in `libs/( android_arch>/`
2023-01-12 20:47:54 +01:00
where `( android_arch )` is the device's architecture.
- The device's architecture does not match the exported one(s).
Make sure your templates were built for that device's architecture,
and that the export settings included support for that architecture.
2023-01-12 19:43:03 +01:00
In any case, `adb logcat` should also show the cause of the error.