2

我是純Javascript開發人員(angularjs & nodejs)&對android或ios應用程序沒有任何知識。我遵循的nativescipt教程,並創造nativescipt(角)與下面的鏈接幫助應用程序: Wiring up Google Maps Nativescript plugin with Angular 2
但在運行後:tns plugin add nativescript-google-maps-sdk,並在運行命令tns run android有一個例外NativeScript nativescript-google-maps-sdk不會喚​​醒

D:\ts\app\sample-Groceries>tns run android 
    Executing before-prepare hook from D:\ts\app\sample-Groceries\hooks\before-prepare\nativescript-dev-typescript.js 
    Found peer TypeScript 1.8.10 
    Project successfully prepared 
    WARNING: The file: D:\ts\app\sample-Groceries\node_modules\nativescript-google-maps-sdk\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 
    WARNING: The file: D:\ts\app\sample-Groceries\node_modules\nativescript-google-maps-sdk\platforms\android\res\values\nativescript_google_maps_api.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-google-maps-sdk 
    { 
        "F0" { 
        dimension "nativescriptgooglemapssdk" 
        } 
       } 
    }Renaming plugin directory to flavor name: D:\ts\app\sample-Groceries\platforms\android\src\nativescript-google-maps-sdk 
-> D:\ts\app\sample-Groceries\platforms\android\src\F0 
      +found plugins: tns-core-modules-widgets 
    { 
        "F1" { 
        dimension "tnscoremoduleswidgets" 
        } 
       } }Renaming plugin directory to flavor name: D:\ts\app\sample-Groceries\platforms\android\src\tns-core-modules-widgets 
D:\ts\app\sample-Groceries\platforms\android\src\F1 

    :config phase: createPluginsConfigFile 
      Creating product flavors include.gradle file in D:\ts\app\sample-Groceries\platforms\android/configurations folder... 

    :config phase: pluginExtend 
      +applying configuration from: D:\ts\app\sample-Groceries\platforms\android\configurations\include.gradle 
      +applying configuration from: D:\ts\app\sample-Groceries\platforms\android\configurations\nativescript-google-maps-sdk\include.gradle 
      +applying configuration from: D:\ts\app\sample-Groceries\platforms\android\configurations\tns-core-modules-widgets\include.gradle 

    :config phase: copyAarDependencies 

    :config phase: addAarDependencies 
      +adding dependency: D:\ts\app\sample-Groceries\platforms\android\libs\aar\widgets-release.aar 

    FAILURE: Build failed with an exception. 

我參觀https://www.nativescript.org/blog/migrating-n-android-plugins-from-version-1.7-to-2.0網頁,但沒有得到任何信息來解決這個例外。

回答

2

可能的解決辦法是嘗試與tns platform remove android刪除Android平臺,並與tns platform add android重新添加。

關於nativescript-google-maps-sdk插件。我從頭開始使用這個插件創建了示例項目。您可以在這裏查看:NativeScript-Angular-GoogleMaps。最重要的部分是在

NativeScript-Angular-GoogleMaps/app/App_Resources/Android/values/nativescript_google_maps_api.xml 添加此代碼段

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <string name="nativescript_google_maps_api_key">API_KEY</string> 
</resources> 

,並在文件node_modules/nativescript-angular/element-registry.js

此行

registerElement("mapView", function() { return require("nativescript-google-maps-sdk").MapView; });

這的末尾添加行將幫助NativeScript找到MapView元素。

+0

感謝真棒示例項目。 但建議我已經刪除android平臺並再次添加它,現在異常更改爲: '無法找到com.google.android.gms:play-services-maps:+的任何匹配項,因爲沒有com.google的版本.android.gms:發揮服務,地圖是available.' 我使用VSCode和Genymotion模擬器 –

+1

默認情況下Genymotion沒有谷歌播放服務。有兩種方法來解決這個問題:遵循這些:如何安裝谷歌播放上Genymotion服務](http://stackoverflow.com/questions/33344857/preview-google-nexus-5x-6-0-0- api-23-gapps)步驟,並在您的模擬器上配置Google Play服務,或在真實設備上部署您的應用。 –

+1

將'registerElement ...'行添加到文件'main.ts'就足夠了。在'node_modules'中更改文件不是一個好主意,因爲如果重新安裝模塊,則必須重做更改。 – Leukipp