首页 > 解决方案 > 如何在 nativescript 插件种子中实现 google play 服务?

问题描述

我正在使用推荐的 nativescript-plugin-seed 为 nativescript 编写插件:https ://github.com/NativeScript/nativescript-plugin-seed 。对于我的插件,我需要使用 Google 位置服务,但我无法访问该服务。

我在 android 文件夹中的 include.gradle 中实现了依赖项:

dependencies {
    implementation "com.google.android.gms:play-services-location:17.0.0"
}

然后我尝试在 myApp.android.ts 中使用该服务,如下所示:

let client = com.google.android.gms.location.LocationServices;

它总是告诉我“typeof android”上不存在“gms”属性,我不知道我错过了什么。

标签: androidtypescriptpluginsgoogle-apinativescript

解决方案


如果您只想获取位置,则可以在插件中添加nativescript-geolocation插件作为依赖项,然后使用插件 API 来获取位置。

如果你喜欢一些定制,你可以在你的插件中实现你自己的版本,以android 实现为例。

如果您打算让您的插件可供公众使用,请尽量不要坚持使用 gradle 文件中的特定版本。

dependencies {
    def googlePlayServicesVersion = project.hasProperty('googlePlayServicesVersion') ? project.googlePlayServicesVersion : "11.4.0"
    compile "com.google.android.gms:play-services-location:$googlePlayServicesVersion"
}

推荐阅读