Custom Search

Friday, October 12, 2018

how to build apk with ads supported from construct 2 using cordova cli and enhance

Hello everyone in this tutorial i will show you how to export apk that support ads by using corodova cli and enhance so lets start.

the first thing you need to do is to install NodeJS ,  Java jdk and android studio ( after installing android studio you must configure SDK MANAGER and install all java version from 4.0 to the highest version ) then install cordova by opening cmd and typing npm install -g cordova  ( after you install all add path in system variable . to do that right click in computer → properties → in your left click advanced system settings then scroll down then click environment variables :

- in system variables tab scroll down until you find "path" then edit it by adding those lines :
C:\Program Files (x86)\Java\jdk1.8.0_121\bin;C:\Program Files\nodejs\;C:\Users\yourusername\AppData\Local\Android\sdk\tools;C:\Users\yourusername\AppData\Local\Android\sdk\platform-tools
( this is for windows 32 bit " C:\Program Files (x86)\Java\jdk1.8.0_121\bin " if you installed java jdk 64 bit the code will be " C:\Program Files\Java\jdk1.8.0_121\bin" also you can visit the android studio and java sites for more information about variables you must adding. )

also in the same tab ( system variables ) add new system variables by clicking new → type in variable name : _JAVA_OPTIONS and give it value : -Xmx512M then click ok.

- after that go to enhance and create an account , after login click enhance my app → select ads you want to use then choose construct 2 in drag and drop library tab then download the drag and drop library that contain enhance plugin for construct 2 and a capx example to how add ads conditions and action.
- now go to construct 2 and add an event sheet and call him ads include and add those conditions and action to it :

then inlcude this event sheet to all other events sheet in your project

then add this action in when you want ads be shown :
action : enhance → show Interstitial ads ( i use only Interstitial ads so if you want to add video rewarded ads or banner see the capx example provided by enhance ) .
after that export your project as cordova :
after exportation finish i recommend to you to compress all png located in www/images to resize the apk size by using a site like compresspng. and you can rename all your pictures after compression with tool called "rename master" to not waste much time by renaming all png one by one.
now the folder www should be like that :

now this is what i do personally :
i open config.xml with notepad ++ then make sure the targetsdkversion is 26
and i delete crosswalk webview plugin + whitelist plugin + config plugin and add this plugin :
<plugin name="cordova-connector" source="git" spec="https://github.com/enhance-co/cordova-connector.git" /> 
then i save the changes .
now i open cmd by click windows button in keyboard then type in search bar : cmd and click enter then in cmd  i type cd desktop ( so the cordova project will be installed in my desktop ) → type cordova create project ( project is the name of your project ) wait until project created then copy the files exported from construct 2 project :

then paste them inside the project created by cordova and accept replacement of files :


now back to cmd and type cd project ( to enter in project folder ) → type cordova platform add android → wait until all files added then type cordova build android --release
( if you get error about minsdk in config.xml is smaller than the one existed in manifest.xml go to C:\Users\your usernamae\Desktop\project\platforms\android\CordovaLib  and open manifest file then edit the minsdk to be the same as the one in config.xml and execute the cordova build code again.
after the build success you will find the apk in :  C:\Users\yourusername\Desktop\project\platforms\android\app\build\outputs\apk\release
- now go back to enhance choose ads types you added in construct 2 → pick construct 2 as drag and drop library  → upload the apk . after upload finish click continue. → in ad mediation choose admob mediation ( or whatever you use ) then paste you interstitial ad unit id then click continue.
now if you have already the keystore file related to your app check : upload my certificate and allow enhance to sign on my behalf  → then upload the keystore file and type the keystore pass and alias name and password. if you not create your keystore yet just create it by using a small tool called apk signer ( after you create the keystore you must remember the keystore and alias name and password ) and also you must protect the keystore file and copy it in external usb or any safe place. → in app version tab type your version name and version code then click enhance now.
if you give you a warning just ignore it and click enhance anyway.
after enhance complete download your apk and enjoy.
i hope this tutorial help many people who find difficulty to make apk from construct 2 project. if you have any question feel free to ask me by leave a comment.


No comments:

Post a Comment