Build Instructions for Android Version on Windows - hyvanmielenpelit/GnollHack GitHub Wiki
Preparations
Devices
You need the following devices to follow these instructions:
- Windows computer — Windows 10 or later, 16 GB or more RAM, 512 GB or more SSD space.
- Android device — Android 12 or later, 4 GB or more RAM, 8 GB or more free storage space.
Software Installation
On the Windows computer, do the following:
- Install Visual Studio — Visual Studio Installation for Mobile Version Development
- Clone Repository — Clone Repository in Visual Studio
- Install WSL and Required Programs — Install Windows Subsystem for Linux
- Configure Visual Studio for Mobile Version Development
- Create
C:\Xamarin\Archives
in File Explorer and set Archives Location to it in Visual Studio → Tools → Options → Xamarin. - If you are using an old version of the repository, you may need to delete old directories, because we have changed some paths.
- Install Tile Sets and FMOD Sound Banks.
- Install Secrets File.
Android Device Preparation
- Enable Developer Mode and USB Debugging — Configure on-device developer options in Android
Starting Debugging or Creating Archive
- Open GnollHack Solution in Visual Studio.
- Set GnollHackX.Android as a startup project.
- Select Android+Windows as your solution platform in the menu bar.
- Select the right solution configuration in the menu bar:
- Debugging — Select Debug.
- Archiving — Select Release.
- Start Windows Subsystem for Linux (WSL) from the start menu.
- In WSL, start SSH by typing
sudo service ssh start
.
Debugging
- Attach your Android device to your computer using a USB cable.
- Allow USB debugging on the device if asked.
- Select your Android device in the menu bar.
- Select the debugger in the Android options:
- Xamarin debugger (for C# code) — Enable Fast Deployment in the Android options.
- C++ debugger — Works with and without Fast Deployment in the Android options. (See notes 1 and 2 below.)
- Select the package format in the Android options:
- APK — It's faster to deploy but sound and music streaming has noticeable lag (up to several seconds).
- AAB (bundle) — It's slower to deploy but sound and music streaming has no noticeable lag.
- Rebuild Solution.
- Hit the green Start button to start debugging.
- If the deployment succeeds but debugging does not start, please just try again. It works at some point.
- When you are about to start debugging, please ensure that the solution configuration is at
Android + Windows
. Visual Studio sometimes reverts it toAny CPU
that is not what we want. - If the build succeeds but the deployment fails promptly in an error, please restart Visual Studio.
Notes
Note 1
You need to have Visual Studio 2019 with the same workloads as Visual Studio 2022 installed that you may use the C++ debugger. Note that there's no .NET Multi-platform App UI development workload in VS 2019, but you must install the Mobile development with .NET workload instead. You do not actually need to start VS 2019, but it is enough to have it installed.
This bug is reported here and here.
This bug should be fixed in Visual Studio 17.7.
Note 2
If the C++ debugger crashes with SIGPWR
, you need to stop the debugging process in an early breakpoint and write the following in the Command Window:
Debug.MIExec handle SIGPWR nostop noprint
Debug.MIExec handle SIGXCPU nostop noprint
Note 3
FMOD sounds do not work correctly while debugging or when running a debug build. To make them work normally, you need to enable Streaming Banks to Memory in GnollHack's settings. This will consume some 500 MB of RAM. FMOD sounds work fine in release builds, though.
Troubleshooting Android Build Errors and Runtime Errors
If you run into a strange compile time error or a runtime error, where the game does not find a Java wrapper class, you can see the following instructions:
Creating APK/AAB Archive Package
- Select the desired package format (APK or "bundle" for AAB) in the Android options.
- Note that Google Play Store accepts only AAB packages.
- Disable Fast deployment in the Android options.
- Rebuild Solution.
- Select Build → Archive or right-click on the project and select Archive.
This will create an unsigned APK/AAB package.
Preparations for Signing APK/AAB
1. Creating the Keystore File
- In the Archive Manager, find the created archive and select Distribute.
- Select Ad Hoc.
- Click the green plus sign to add a new signing identity.
- Fill all the fields and hit Create.
- Write down the password used to create the signing identity.
- Double-click the created identity in the identity list.
- Select View in Explorer.
- Write down the full path to the keystore file. You will need it later, when you sign archives with jarsigner.
2. Download Java Development Kit for Windows
Signing APK/AAB
Once the APK/AAB package has been created, you need to sign it with jarsigner.
- In the Archive Manager, find the created archive and select Open Folder.
- Open Windows Powershell (Windows 10) or Terminal (Windows 11)
- Windows 10: In the File Explorer menu, click File → Open in Windows Powershell.
- Windows 11: You can right-click on free space in the File Explorer window and select Open in Terminal.
Then write:
&"C:\Program Files\Java\jdk-[jdk-version]\bin\jarsigner" -verbose -sigalg SHA256withRSA -digestalg SHA-256 -keystore "[created-key-store-location]" ./com.soundmindentertainment.gnollhack.aab [your-keystore-identity]
where:
- [jdk-version] is the version of JDK installed, for example,
16.0.2
. - [created-key-store-location] is the location of the keystore created above, for example,
C:\Users\tommi\AppData\Local\Xamarin\Mono for Android\Keystore\tommi-hmp\tommi-hmp.keystore
- [your-keystore-identity] is the name of the identity for which the keystore file was created, for example,
tommi-hmp
.
For example, our command is:
&"C:\Program Files\Java\jdk-16.0.2\bin\jarsigner" -verbose -sigalg SHA256withRSA -digestalg SHA-256 -keystore "C:\Users\tommi\AppData\Local\Xamarin\Mono for Android\Keystore\tommi-hmp\tommi-hmp.keystore" ./com.soundmindentertainment.gnollhack.aab tommi-hmp
When asked, please provide the password used to create the signing identity.
The package is now signed and ready to be uploaded to Google Play Store.
Uploading to Google Play Store
When you publish a new version of the game to Google Play Store, you need to increase android:versionCode in the Android manifest by 1.