Menginstall Cordova menggunakan npm
C:\>npm install -g cordovaMembuat Aplikasi pertama
$ cordova create hello com.example.hello HelloWorldMenambahkan platform Android di Cordova
$ cordova platform add android@9.0.0Menjalankan emulator
$ npx cordova emulate androidMenambahkan plugin cordova-plugin-admob-free
Install plugin cordova-plugin-admob-free
Referensi : https://ratson.github.io/cordova-plugin-admob-free/ $ npx cordova plugin add cordova-plugin-admob-free --save --variable ADMOB_APP_ID="ca-app-pub-3940256099942544/6300978111"
<?xml version='1.0' encoding='utf-8'?> <widget id="com.djavasoft.fw8" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> <name>Hello8</name> <description> A sample Apache Cordova application that responds to the deviceready event. </description> <author email="dev@cordova.apache.org" href="http://cordova.io"> Apache Cordova Team </author> <content src="index.html" /> <access origin="*" /> <allow-intent href="http://*/*" /> <allow-intent href="https://*/*" /> <allow-intent href="tel:*" /> <allow-intent href="sms:*" /> <allow-intent href="mailto:*" /> <allow-intent href="geo:*" /> <platform name="android"> <allow-intent href="market:*" /> <preference name="deployment-target" value="9.0" /> <preference name="android-minSdkVersion" value="22" /> <preference name="android-targetSdkVersion" value="26" /> <preference name="Orientation" value="portrait" /> </platform> <plugin name="cordova-plugin-admob-free"> <variable name="ADMOB_APP_ID" value="ca-app-pub-3940256099942544/3419835294" /> </plugin> <platform name="ios"> <allow-intent href="itms:*" /> <allow-intent href="itms-apps:*" /> </platform> </widget>Tambahkan kode javascript untuk menampilkan admob
<script type="text/javascript"> document.addEventListener('deviceready',function(){ admob.banner.prepare(); admob.banner.show({ id:'ca-app-pub-3940256099942544/6300978111', autoShow:true }) }); document.getElementById('admob-int').addEventListener('click',function(){ admob.interstitial.config({ id: 'ca-app-pub-3940256099942544/1033173712', }) admob.interstitial.prepare() admob.interstitial.show() }) </script>
Build release apk
Buat file build.json
{ "android": { "debug": { "keystore": "../android.keystore", "storePassword": "android", "alias": "mykey1", "password" : "password", "keystoreType": "" }, "release": { "keystore": "../android.keystore", "storePassword": "", "alias": "mykey2", "password" : "password", "keystoreType": "" } } }
$ cordova build android -- release -- buildConfig=build.jsonAtau :
$ cordova build android --release -- --keystore="..\android.keystore" --storePassword=android --alias=mykey