【问题标题】:Cant get Nativescript plugin to work "nativescript-admob"无法让 Nativescript 插件工作“nativescript-admob”
【发布时间】:2016-05-06 00:15:26
【问题描述】:

我已在 SDK Manager Extras 中安装了先决条件“Google play service”。运行时,应用程序页面显示在没有横幅的模拟器上,并且 CLI 日志显示错误。谁能告诉我我错过了什么?

    admob.createBanner({
        // if this 'view' property is not set, the banner is overlayed on the current top most view
        // view: ..,
        testing: true, // set to false to get real banners
        size: admob.AD_SIZE.SMART_BANNER, // anything in admob.AD_SIZE, like admob.AD_SIZE.SMART_BANNER
        iosBannerId: "ca-app-pub-XXXXXX/YYYYYY", // add your own
        androidBannerId: "ca-app-pub-9495738740700511/5085446949", // add your own
        // Android automatically adds the connected device as test device with testing:true, iOS does not
        iosTestDeviceIds: ["yourTestDeviceUDIDs", "EAA5B49DBA3AD30CC27A343C86CD7ADF"],
        margins: {
          // if both are set, top wins
          //top: 10
          bottom: 50
        }
      }).then(
          function() {
            console.log("admob createBanner done");
          },
          function(error) {
            console.log("admob createBanner error: " + error);
          }
    )
  1. 我创建了新项目“tns create adtest”
  2. 添加了插件“tns plugin add nativescript-admob”
  3. 添加了平台“tns platform add android”
  4. 由“tns livesync android --watch”运行

---错误日志---

Project successfully prepared
The application with id "org.nativescript.adtest" is not installed on device with identifier emulator-5554.
Project successfully prepared
WARNING: The file: D:\GoogleDrive\PROJECTS\adtest\node_modules\nativescript-admob\platforms\android\AndroidManifest.xml is depricated, you can read more about what will be the expected plugin structure here: https://www.nativescript.org/blog/migrating-n-android-plugins-from-version-1.7-to-2.0

:config phase:  createDefaultIncludeFiles
        +found plugins: nativescript-admob
 {
              "F0" {
                dimension "nativescriptadmob"
              }
            }
}       +found plugins: tns-core-modules-widgets
 {
            "F1" {
              dimension "tnscoremoduleswidgets"
            }
          }
        }
:config phase:  createPluginsConfigFile
         Creating product flavors include.gradle file in D:\GoogleDrive\PROJECTS\adtest\platforms\android/configurations folder...

:config phase:  pluginExtend
        +applying configuration from: D:\GoogleDrive\PROJECTS\adtest\platforms\android\configurations\include.gradle
        +applying configuration from: D:\GoogleDrive\PROJECTS\adtest\platforms\android\configurations\nativescript-admob\include.gradle
        +applying configuration from: D:\GoogleDrive\PROJECTS\adtest\platforms\android\configurations\tns-core-modules-widgets\include.gradle

:config phase:  copyAarDependencies

:config phase:  addAarDependencies
        +adding dependency: D:\GoogleDrive\PROJECTS\adtest\platforms\android\libs\aar\widgets-release.aar
:preBuild UP-TO-DATE
:preF0F1DebugBuild UP-TO-DATE
:checkF0F1DebugManifest
:preF0F1ReleaseBuild UP-TO-DATE
:prepareComAndroidSupportAnimatedVectorDrawable2330Library
:prepareComAndroidSupportAppcompatV72330Library
:prepareComAndroidSupportSupportV42330Library
:prepareComAndroidSupportSupportVectorDrawable2330Library
:prepareComGoogleAndroidGmsPlayServicesAds840Library
:prepareComGoogleAndroidGmsPlayServicesBasement840Library
:prepareWidgetsReleaseLibrary
:prepareF0F1DebugDependencies
:compileF0F1DebugAidl UP-TO-DATE
:compileF0F1DebugRenderscript UP-TO-DATE
:generateF0F1DebugBuildConfig UP-TO-DATE
:cleanLocalAarFiles
:ensureMetadataOutDir
:collectAllJars
:setProperties
:asbg:generateInterfaceNamesList
:asbg:runAstParser UP-TO-DATE
:asbg:generateBindings UP-TO-DATE
:generateF0F1DebugAssets UP-TO-DATE
:mergeF0F1DebugAssets
:generateF0F1DebugResValues UP-TO-DATE
:generateF0F1DebugResources UP-TO-DATE
:mergeF0F1DebugResources UP-TO-DATE
:processF0F1DebugManifest UP-TO-DATE
:processF0F1DebugResources
:generateF0F1DebugSources
:compileF0F1DebugJavaWithJavac UP-TO-DATE
:compileF0F1DebugNdk UP-TO-DATE
:compileF0F1DebugSources UP-TO-DATE
:buildMetadata UP-TO-DATE
:transformClassesWithDexForF0F1Debug UP-TO-DATE
:mergeF0F1DebugJniLibFolders UP-TO-DATE
:transformNative_libsWithMergeJniLibsForF0F1Debug UP-TO-DATE
:processF0F1DebugJavaRes UP-TO-DATE
:transformResourcesWithMergeJavaResForF0F1Debug UP-TO-DATE
:validateDebugSigning
:packageF0F1Debug
:zipalignF0F1Debug
:assembleF0F1Debug
:assembleDebug
:deleteExplodedAarFolder UP-TO-DATE
:buildapk

BUILD SUCCESSFUL

Total time: 11.657 secs
Project successfully built
JS: Treating this deviceId as testdevice: CA5F7DA5D57FD0D05E676D0CD880FB80
chromium: [INFO:library_loader_hooks.cc(120)] Chromium logging enabled: level = 0, default verbosity = 0
05-06 03:27:04.304  3124  3124 I BrowserStartupController: Initializing chromium process, singleProcess=true
chromium: [WARNING:resource_bundle.cc(285)] locale_file_path.empty()
05-06 03:27:04.349  3124  3124 E DataReductionProxySettingListener: No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp
JS: Error in admob.createBanner: TypeError: Cannot read property 'android' of null
JS: admob createBanner error: TypeError: Cannot read property 'android' of null
chromium: [WARNING:data_reduction_proxy_config.cc(423)] SPDY proxy OFF at startup
chromium: [INFO:CONSOLE(0)] "Creating Application Cache with manifest https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.appcache", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
chromium: [INFO:CONSOLE(0)] "Application Cache Checking event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
chromium: [INFO:CONSOLE(0)] "Application Cache Downloading event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
chromium: [INFO:CONSOLE(0)] "Application Cache Progress event (0 of 4) https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.js", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
chromium: [INFO:CONSOLE(0)] "Application Cache Progress event (1 of 4) https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/production/sdk-core-v40-impl.js", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
chromium: [INFO:CONSOLE(0)] "Application Cache Progress event (2 of 4) https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/canary/sdk-core-v40-impl.js", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
chromium: [INFO:CONSOLE(0)] "Application Cache Progress event (3 of 4) https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/native_ads.js", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
chromium: [INFO:CONSOLE(0)] "Document was loaded from Application Cache with manifest https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.appcache", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
chromium: [INFO:CONSOLE(0)] "Application Cache Checking event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
chromium: [INFO:CONSOLE(0)] "Application Cache NoUpdate event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)

【问题讨论】:

    标签: javascript android admob google-play-services nativescript


    【解决方案1】:

    我的建议是简单地使用 tns android debug。这样您就可以看到导致此错误的原因: 无法读取 null 的属性“android”

    在我看来,您调用 admob 为时过早,并且并非所有内容都已初始化。无论如何,只需调试它:)

    希望这会有所帮助。

    【讨论】:

    • 说得对,可能还早。我已将它放在页面 navigatingTo 函数中,可能没有足够的时间来初始化。当我在 TAP 按钮中移动它时,它只需点击即可。但我的问题是现在我想在页面启动时加载它。 Nativescript 是否有类似页面加载或定位它的最佳方式?
    • 当然。只需查看他们的文档docs.nativescript.org。比在 SO 上发帖更快;)
    • nativescript.org/tns.xsd" loaded="pageLoaded"> 当然你导出的函数应该是 pageLoaded
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    • 2018-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多