2015-04-01 44 views
0

我的代碼中有一個地圖片段。當我使用Android Studio中的「運行應用程序」運行它時,它工作正常。但是,當我將它作爲已簽名的apk輸出時,相同的代碼不會顯示地圖。我所得到的只是一個空白的屏幕,左下角有谷歌徽標。當我將它導出爲apk時,android應用停止工作

這是我的代碼:

 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { 
      fm = getActivity().getSupportFragmentManager(); 
     } else { 
      fm = getChildFragmentManager(); 
     } 
     mMap = ((SupportMapFragment) fm.findFragmentById(R.id.map)).getMap(); 

我的片段是:

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
android:layout_height="match_parent" android:id="@+id/map" 
tools:context="schoolbus.tracker.datavoice.schoolbusdrawer.MapsFragment" 
android:name="com.google.android.gms.maps.SupportMapFragment" /> 

我自己也嘗試getChildFragmentManager(),getSupportFragmentManager,但沒有奏效。

再次只有當我將它安裝爲已簽名的apk時纔會出現該錯誤。否則地圖運行良好。

謝謝。

+5

你有更換調試API在您的應用程序中使用釋放鍵的地圖鍵ion.After此後只有一個發佈apk會顯示谷歌地圖 – 2015-04-01 10:48:20

回答

1

我終於得到它的工作,我改變

<meta-data 
     android:name="com.google.android.maps.v2.API_KEY" 
     android:value="my-key" /> 

<meta-data 
android:name="com.google.android.geo.API_KEY" 
android:value="my-key"/> 

並補充說:

<uses-feature 
    android:glEsVersion="0x00020000" 
    android:required="true"/> 

其做工精細現在

1

用您的應用程序中的釋放鍵替換地圖的調試API密鑰。此後,只有一個發佈apk會顯示谷歌地圖。

+0

嗨,我仔細檢查了API密鑰,但它仍然沒有顯示。我去了這個鏈接:要得到一個,按照這個鏈接,按照指示,並在最後按「創建」: https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r= – 2015-04-01 11:15:21

+0

通常這種情況發生無效釋放鍵是你的sha指紋是否正確?請重新檢查它 – 2015-04-01 11:19:09

+0

我在此頁面上跟隨教程:http://android-er.blogspot.in/2012/12/displaying-sha1-certificate-fingerprint html的。並重新輸入我的指紋。但是地圖仍然沒有顯示 – 2015-04-01 11:59:31

相關問題