Building a debug APK
1. From Construct 2 export your project to cordova. File→ Export project → Cordova
2. Select the location you wanna export to and uncheck minify →Next
3. Make sure Hide status bar and export audio for android are checked. When i export without any of the permissions my game works fine. Scirra has an old tutorial on exporting to cordova on it’s site which covers most options:
4. Select your minimal android version and Click Export and wait till construct 2 is done
5. As mentioned before from august 2018 google demands new apps, and app updates to target/support an api that is only a year old. In other words developers must adapt a new API within a year. This does not mean old api’s can not be supported.
Use a text editor, notepad(++) will do, to adjust the target API in the config.xml and config.json files exported by Construct 2 to full fill googles requirement.
API 21 → Android 5.0
API 27 → Android 8.1
<preference name="android-targetSdkVersion" value="27" />
<preference name="android-minSdkVersion" value="21" />
In the configuration files Construct 2 produced there are some lines for iOS. When you leave them cordova gives output about preperations and failure's for building an iOS app too. So i removed them from the files to get a faster and cleaner process.
Now the actual build process:
Open Windows PowerShell and go to the folder with your export. Then type the following command:
In the output of cordova prepare it mentions androidspr@~7.0.0 or so. This is not the android version, but the version of cordova’s internal build for android engine.
The output also mentions Android target: android-26. It puts it in some of the produced files as well. But the build process ignores that, so we can ignore it to.
When you removed all iOS code this command gives a lot less output
This takes a minute or so. During which my firewall pops up a few times. When away from my desk, cordova times out when waiting.
On success it say's where your debug apk is placed
When i build with android 5.0 as minimal version, the build fails, saying missing dependencies try ‘npm install cordova-custom-config’. When that happens I do the npm install step and then it works (for me)
When building with android 4.1 as minimal version this does not happen? Anybody any idea about why?
Your debug APK is in projectfolder\platforms\android\app\build\outputs\apk\debug
Building with Crosswolk (minimum version is older then android 5.0)
When you target older platform’s the oldest supported now (april 2018) is android 4.1(API 16), you might run into a recent bug when building: Failed to execute aapt. There is a solution for that. After running cordova requirements go and edit the build.gradle file in yourapp\platforms\android\app, NOT the one in the android folder you pass.
Add the following code between the buildscript and allprojects code.
Image of the build.gradle file:
Now build again and you get 5 apk’s
On my old Nexus 7 (second gen) tablet the armv7-debug runs smoother then the universal I got with minimum API version 21.
Now you can test your game on different android devices by side loading it.