以下の手順で、nativescript-vue環境を構築しています。
https://nativescript-vue.org/en/docs/getting-started/quick-start/
具体的にはこのような感じです。
$ npm install -g @vue/cli @vue/cli-init $ vue init nativescript-vue/vue-cli-template hoge $ cd hoge $ npm install $ npm run watch:android
正常にandroid/ios共に表示されましたので、
これにAdMobを追加したいと考えております。
$ npm install nativescript-admob
を実施後、以下の処理をHome.vueの最後に追加しました。
AdMobのIDは適切なものに変えております。
Vue
1<script> 2var admob = require("nativescript-admob"); 3 4admob.createBanner({ 5 // if this 'view' property is not set, the banner is overlayed on the current top most view 6 // view: .., 7 testing: true, // set to false to get real banners 8 size: size, // anything in admob.AD_SIZE, like admob.AD_SIZE.SMART_BANNER 9 iosBannerId: "ca-app-pub-XXXXXX/YYYYYY", // add your own 10 androidBannerId: "ca-app-pub-AAAAAAAA/BBBBBBB", // add your own 11 // Android automatically adds the connected device as test device with testing:true, iOS does not 12 iosTestDeviceIds: ["yourTestDeviceUDIDs", "canBeAddedHere"], 13 margins: { 14 // if both are set, top wins 15 //top: 10 16 bottom: 50 17 }, 18 keywords: ["keyword1", "keyword2"] // add keywords for ad targeting 19 }).then( 20 function() { 21 console.log("admob createBanner done"); 22 }, 23 function(error) { 24 console.log("admob createBanner error: " + error); 25 } 26) 27</script>
このままでは、以下のようなエラーメッセージが表示されてしまいます。
JS: 'Error in admob.createBanner: Error: java.lang.NullPointerException: Attempt to invoke virtual method \'android.content.res.Resources android.content.Context.getResources()\' on a null object reference
何か勘違いしているか手順が足りないのだと思いますが、
NativeScript/Vue共に経験が少なく、解決できません。
アドバイスいただけると助かります。
よろしくお願いします。
以上
あなたの回答
tips
プレビュー