2016-04-02 55 views
2

我是Xamarin Android新手。我試圖在我的應用程序上顯示一個基本的谷歌地圖。我有API密鑰等設置谷歌地圖API。然而,當我運行模擬器給出了一條消息「應用程序不會沒有谷歌播放服務運行」。Xamarin應用程序不會運行沒有谷歌播放服務

我已經安裝了所有使用android sdk manager的軟件包/ SDK,我嘗試使用API​​ level 22(Android 5.0 Lollipop)。

下面的代碼是初始化谷歌地圖(它從xamarin例子下載)。

任何人都可以告訴我我在這裏失蹤。

 using System; 
     using Android.App; 
     using Android.Content; 
     using Android.Gms.Maps; 
     using Android.Gms.Maps.Model; 
     using Android.Runtime; 
     using Android.Views; 
     using Android.Widget; 
     using Android.OS; 

     namespace App2 
     { 
     [Activity(Label = "App2", MainLauncher = true, Icon = "@drawable/icon")] 
     public class MainActivity : Activity, IOnMapReadyCallback 
     { 
     private GoogleMap _gMap; 
     protected override void OnCreate(Bundle bundle) 
     { 
     base.OnCreate(bundle); 

     // Set our view from the "main" layout resource 
     SetContentView(Resource.Layout.Main); 
     GetMap(); 
    } 

    private void GetMap() 
    { 

     if (_gMap == null) 
     { 
      FragmentManager.FindFragmentById<MapFragment>(Resource.Id.map).GetMapAsync(this); 
     } 
    } 

    public void OnMapReady(GoogleMap map) 
    { 
     _gMap = map; 
    } 
    } 
} 

Main.axml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<fragment 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:name="com.google.android.gms.maps.MapFragment" /> 

的Android Mainfest

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="App2.App2" android:versionCode="1" android:versionName="1.0" android:installLocation="auto"> 
<uses-sdk android:minSdkVersion="16" /> 
<application android:label="App2" android:icon="@drawable/Icon"> 
    <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyCKBrF-_IrAQlkUyFG7GT4qgEJ7qOgyNRI" /> 
</application> 
<uses-feature android:glEsVersion="0x00020000" android:required="true" /> 
<!-- We need to be able to download map tiles and access Google Play Services--> 
<uses-permission android:name="android.permission.INTERNET" /> 
<!-- Allow the application to access Google web-based services. --> 
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
<!-- Google Maps for Android v2 will cache map tiles on external storage --> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<!-- Google Maps for Android v2 needs this permission so that it may check the connection state as it must download data --> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<!-- These are optional, but recommended. They will allow Maps to use the My Location provider. --> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

Error All SDKs Installed

回答

3

這似乎是,該設備,或者在這種情況下,仿真器,沒有谷歌播放安裝服務。 Android應用程序中的軟件包僅提供對Google Play服務的訪問,Google Play服務通常安裝在設備本身上。從這個意義上說,Google Play服務更像是一個共享運行時。

要解決這個問題,您應該可以按照以下guide在模擬器上安裝Google Play服務。

我希望這有助於!

+0

嗨clb,謝謝你的回覆。我遵循你的指示並下載了相應的zip文件,但問題是我無法將它拖放到我的播放器上,當我嘗試將播放器上的zip文件拖放時,它會給我一個圈(禁)圖標。任何想法可能會造成這種情況。 – Robin

+0

嘿!我需要看看我是否可以在我的系統上重現這一點。我會回覆這個線程 – clb

2

它看起來像你試圖在沒有安裝Google Play服務的模擬器圖像上運行應用程序。

首先,我總是會建議使用物理設備進行測試,但是如果您需要測試不具有設備的各種API級別,那麼使用模擬器就足夠了。

如果您使用的是Google AVD,那麼您的create a new virtual device已包含Google Play服務。

如果您使用的是Xamarin Android Player,那麼您可以使用@clb提到的this guide。不過,請記住,Xamarin Android Player是預覽軟件,並且不受官方支持。如果這是模擬器,您在安裝Google Play服務時遇到問題,那麼您的最佳支持選項是file a bug report。 (該指南目前顯示日誌的錯誤位置,現在通過(Windows)右鍵單擊底部欄(Mac),單擊幫助菜單>生成錯誤報告 - 日誌將壓縮在桌面上)日誌的錯誤位置。

如果你仍然有問題,請讓我知道你正在使用的模擬器,我會看看我是否可以進一步幫助!

+0

嗨,艾倫,我檢查了我的應用程序在物理設備上,它工作正常。我想現在我必須忍受它,直到Xamarin Player發佈新版本。另一種可能性可能是我正在運行沒有hyper-v的windows 10 Home。 – Robin

1

正如其他人所說的,問題似乎是您沒有在模擬器上安裝Google Play服務(又名Google API)。這裏有一個指向我寫的教程的鏈接,告訴你如何做到這一點。還有一個視頻:https://birdsbits.wordpress.com/2016/05/26/testing-location-aware-apps-on-an-emulator

+0

如果你在這裏發佈一些信息,除了提供鏈接到你的博客,這將是有幫助的。鏈接可能腐爛。 –

+0

關鍵是通過SDK管理器安裝Google API,然後在設置設備時選擇 - 特別是在CPU/ABI部分。 –

相關問題