12

Building Android apps (APKs) in Construct 3

Tags

Add to Favourites

7 Favourites
Construct 3
Construct 3

Buy Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Buy Now Construct 3 users don't see these ads

Tutorial Stats

? 1,006 sessions
? 25 sessions per day
? 1,189 page views
? 30 page views per day

Report Tutorial

Report this tutorial for spam or for being inappropriate.

Published 12 Oct, 2017
1,938 words
~8-13 minutes

Construct 3 has its own mobile app build service, which can build your mobile apps for you. This feature is only available to subscribers. Here's how to get Construct 3 to build an APK (an Android app) for you.

Prepare your project

You might want to catch up on the tutorials supporting multiple screen sizes and touch controls to make sure your project is ready for use on mobile. It's also easy to test on mobile using Construct 3's Remote Preview feature.

Also, make sure you fill out everything in the About section of Project Properties, such as the author, app ID, version and so on. All this information will be used by the exported app.

Export

Once you're satisfied your project works well on mobile and is ready to be exported, select MenuProjectExport and pick the Android (Cordova) option.

When the Cordova options dialog appears, there's a dropdown list labelled Android build. If you just want to test your project as a mobile app, choose Debug APK. If you're ready to publish your app to the Google Play store, choose Unsigned release APK. (Note Construct currently cannot sign release APKs for you.)

Building the APK

When you continue, your project will be uploaded to the app build service for building. This can take a while. You can carry on working in Construct while the app is uploaded, built and downloaded again. The status of the build will be shown in the lower-left corner of the window.

When the build finishes, a dialog will pop up with a "Build finished!" message, and a link to download the resulting APK.

Testing a debug APK

Follow these steps if you chose the Debug APK option. Otherwise skip to the next section for information about signing a release APK.

Enable developer mode

You can't run debug APKs on an Android device until you enable Developer Mode. Follow these steps to enable it:

  1. Open Settings
  2. Find the About section and tap it
  3. Find the Build number. This might be in a sub-section, like Software information, or More.
  4. Tap the Build number repeatedly until you see a notification that developer mode is enabled.

Now you can install debug APKs! It will also show a new Developer options section in Settings, but you don't need that for this guide.

Transfer the APK to your device

Once you've downloaded the .apk file, it's on your computer, but it needs to be on your Android device. There are a number of ways you can transfer the file to your device. Here's a couple of ideas:

  • Upload it to a cloud storage service like Google Drive, Dropbox or OneDrive. Then use the mobile app to download it again on the device.
  • Connect your device to your computer with a cable and transfer it across to the device's storage.
  • Copy the file to a USB drive, and then connect the USB drive to the Android device. (You might need a USB On-The-Go cable.)
  • Construct 3 works on Android, so you can actually do the build in Construct 3 on an Android device and have the APK download to the device directly.
  • Look for an Android app that supports transferring files from a computer.
  • If all else fails, try emailing it to yourself in an attachment and open the email on the device.

Run the APK

Once you tap the APK file on your Android device, you should see a screen asking if you want to install it. Tap Install and after a moment you should see a success message and an option to open the app. (It'll also be in the apps section if you want to run it later.) Open the app and you should see your game running!

Signing a release APK

Follow these steps if you chose the Unsigned release APK option. Otherwise see the previous section.

Release APKs are intended for publishing to the Google Play store. Before you can publish it, you must align it (to optimise it) then sign it (to securely verify you as the author). You can't run a release APK on your device until it is signed. Depending on the device you may also need to enable developer mode (see the previous section), or enable permission to install apps from unknown sources, before you can install the release APK. This is because it doesn't come directly from the Google Play Store. (Installing an APK manually is also known as side-loading.)

Tips on using command lines

You'll need to run some programs from the command line to follow these steps. On macOS and Linux it's referred to as the Terminal. Older versions of Windows use the Command prompt, but in the latest versions of Windows 10 it's been replaced with Powershell. Normally you can just search for these names as an app and run it. Many systems have shortcuts to open them as well, such as holding Shift and right-clicking in a folder on Windows. Here are some more tips to help you follow these steps:

  • The command line has a current directory, which is always displayed. This is where files are written to and read from by default, if you use a relative name like file.txt in a command.
  • A command to run a program is the filename of the program followed by any options (called arguments in a command line).
  • Usually if a path has a space in it, e.g. C:\Program Files, it must be surrounded in double quotes to work correctly, e.g. "C:\Program Files".
  • In Windows PowerShell, if the path to the program itself has a space in it, prefix it with &. For example if you get an error trying to run "C:\Program Files\tool.exe", try running & "C:\Program Files\tool.exe" instead.

Installation

You'll need to install two pieces of software for signing APKs:

  1. JDK (Java Development Kit), which contains the keytool utility
  2. Android Studio, which contains the Android development tools

You'll also need to take a note of the installation directories. For example on a Windows system, the tools we'll need will be in paths similar to these (but note particulars of version numbers and usernames may be different):

  • C:\Program Files\Java\jdk1.8.0_121\bin for keytool
  • C:\Users\YourUserName\AppData\Local\Android\sdk\build-tools\26.0.2 for zipalign and apksigner

In the following steps, we'll shorten the full paths to path\to\jdk and path\to\android\build-tools for brevity. When you see these, you'll need to replace them with the full paths. Don't forget to surround them in double-quotes if they contain a space, and in PowerShell, if you use double quotes also prefix it with &.

Create a key

You also need to create a private key to sign the APK with. You'll also need to create a password for the key. Both the password and the key file must be kept a secret for your app to be secure. Take a note of the password somewhere safe, since you'll need it later, as well as any time you sign an APK in future with the same key.

First create a new empty folder to hold all our signing related files in. Then make sure the command line has that set as its current directory. Normally you can do this with the cd command, e.g.:

cd path\to\folder

To create a key, run the following keytool command:

path\to\jdk\keytool -genkey -v -keystore release-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias my-alias

You will then be prompted to enter a password for the key, and to confirm it. Take note of this password in a safe place, you'll need it later!

You'll also be asked for information about the publisher of the app, including your name, the name of your organizational unit, the name of your organization, your city or locality, your state or province, and the two-letter country code. These are optional, you can simply press return without entering anything to skip a field. At the end it will ask you to confirm - simply enter y to accept.

You'll also be asked to enter a key password - just press return to make it the same as the previous password. Once completed, you should get a file named release-key.jks in your folder.

Aligning

Copy your unsigned release APK to the same folder as your release key. For simplicity following these commands, rename it to app.apk. It needs to be aligned, which is an optimisation. This is done with a tool named zipalign. Use the following command to do this.

path\to\android\build-tools\zipalign -v -p 4 app.apk aligned.apk

This creates a new file named aligned.apk in the folder. This is an aligned, but still unsigned, APK file to use for the next step.

Signing

Now you need to use the release key you created earlier to sign the APK. This is a way of securely proving that you are the author of the app and that it hasn't been tampered with.

The APK is signed with a tool named apksigner. Use the following command:

path\to\android\build-tools\apksigner sign --ks release-key.jks --out signed.apk aligned.apk

You'll need to enter the password you created with your release key earlier. Once completed, you should have a signed release APK in your folder named signed.apk!

You can verify the signing was successful by running:

path\to\android\build-tools\apksigner verify signed.apk

There shouldn't be any errors listed when you run that command. If it says nothing, it's OK.

At this point you'll probably want to rename signed.apk to something more useful, e.g. mygame-release-signed.apk.

Example

The following commands were used on a Windows 10 PC with a PowerShell prompt. Note that you cannot use these commands directly yourself! They include things like usernames in the path, and specific version numbers. They are provided as an example to help you follow the previous steps.

Creating a release key: (note this command involves a path with a space, so it was wrapped in quotes, and & added so PowerShell understands it)

& "C:\Program Files\Java\jdk1.8.0_121\bin\keytool" -genkey -v -keystore release-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias my-alias

Aligning APK:

C:\Users\Ashley\AppData\Local\Android\sdk\build-tools\26.0.2\zipalign -v -p 4 app.apk aligned.apk

Signing APK:

C:\Users\Ashley\AppData\Local\Android\sdk\build-tools\26.0.2\apksigner sign --ks release-key.jks --out signed.apk aligned.apk

Verifying APK:

C:\Users\Ashley\AppData\Local\Android\sdk\build-tools\26.0.2\apksigner verify signed.apk

Tips

Typically most of the work here is one-off setup. Once you have followed these steps once, it's much quicker to sign another APK: you can jump straight to the Aligning section and use the same release key.

Advanced users might want to create a small script to run these commands automatically, which will help make the process quicker.

You can also test release APKs on your device once they're signed - see the previous section Transfer the APK to your device.

Publishing

You can now upload this APK to the Google Play Console. You'll need to register a Google Play Developer account if you don't have one already, which may also involve a fee.

From here onwards you're using Google's services, so it's best to refer to their official documentation. Take a look at the Google Play Console Help Center for further guidance.

Share this Tutorial

Make games in your browser

You may use this tutorial for any purpose (even commercial) if you properly attribute it. Click here for more information.

Beta Mode: You may find bugs/missing content. Read more & Report Bugs