This tutorial hasn't been translated.
This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.
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.
Open Windows PowerShell and go to the folder with your export. Then type the following command:
In the output of cordova prepare it mentions androideya@~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
cordova build android
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
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.
你好 我好久没有更新C2了。近期发现更新到r261 以上的版本。 CORDOVA CLI build 出来的android APP 无法在手机里面打开。黑屏无法启动APP. 能帮帮我么？
R261无法BUILD API 28
Hello, I haven't updated C2 for a long time. Recent updates have been found to be more than r261. Android APP built by CORDOVA CLI cannot be opened in the phone. Black screen can't start APP. Can you help me?
R261 cannot BUILD API 28