Android 在地图片段上显示白色屏幕,但在模拟器上运行良好

Android 在地图片段上显示白色屏幕,但在模拟器上运行良好,android,google-maps,firebase,Android,Google Maps,Firebase,当我在安卓设备上运行谷歌地图时,我正在我的应用程序中使用谷歌地图,该设备显示一个白色屏幕,左下角有谷歌标志。但当我在模拟器上运行它时,会完美地显示地图 下面是MapsActivity.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_p

当我在安卓设备上运行谷歌地图时,我正在我的应用程序中使用谷歌地图,该设备显示一个白色屏幕,左下角有谷歌标志。但当我在模拟器上运行它时,会完美地显示地图

下面是MapsActivity.xml

<RelativeLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:id="@+id/appBarLayout">

    <include layout="@layout/main_app_bar_layout"
        android:id="@+id/main_page_toolbar" />

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.DrawerLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawerLayout"
    android:layout_marginTop="@dimen/cast_libraries_material_featurehighlight_inner_radius">

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_below="@id/main_page_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MapsActivity"
        tools:ignore="NotSibling" />



    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_home"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:menu="@menu/navigation_menu"
        android:layout_gravity="start"
        app:headerLayout="@layout/navigation_header_layout">

    </android.support.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>

</RelativeLayout>
下面是Android Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="MY_PACKAGE_NAME">

<!--
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
     Google Maps Android API v2, but you must specify either coarse or fine
     location permissions for the 'MyLocation' functionality. 
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".StartActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <!--
         The API key for Google Maps-based APIs is defined as a string resource.
         (See the file "res/values/google_maps_api.xml").
         Note that the API key is linked to the encryption key used to sign the APK.
         You need a different API key for each encryption key, including the release key that is used to
         sign the APK for publishing.
         You can define the keys for the debug and release targets in src/debug/ and src/release/. 
    -->
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

    <activity
        android:name=".MapsActivity"
        android:label="@string/title_activity_maps" />
    <activity
        android:name=".ProfileActivity"
        android:parentActivityName=".MapsActivity"/>
    <activity android:name=".SettingsActivity"
        android:parentActivityName=".MapsActivity">
    </activity>
</application>

</manifest>
我已经启用了“谷歌地图Android API”。并且API密钥存在。
但是,我没有找到“谷歌地图Android API v2”。它与Manifest.xml中的“谷歌地图Android API”相同吗?

您必须像这样重命名活动:

android:name="com.project.me.appname.Activitys.MapsActivity"

在google maps api dashboard上为签名的Apk添加SHA-1指纹解决了我的问题。

设备上是否安装了google Play服务?这不是答案,但您是否在Android清单XML文件中声明了google api密钥?@Arthuratout Play Services是installed@TimBiegeleisen谢谢我在Android清单中声明了API密钥,并尝试重新生成新的API密钥。但错误未解决Post your manifest.xml感谢您在此处回答。您的观点是正确的,我已经按照您所说的做了,并将GOOGLE_MAPS_API_密钥粘贴到Manifest.xml中。之后,我在Google开发者控制台->凭证->API限制中为调试和发布apk添加了SHA-1。这就解决了我的问题。
Google Maps Android API: Authorization failure.  Please see https://developers.google.com/maps/documentation/android-api/start for how to correctly set up the map.
Google Maps Android API: In the Google Developer Console (https://console.developers.google.com)
Ensure that the "Google Maps Android API v2" is enabled.
Ensure that the following Android Key exists:
    API Key: YOUR_KEY_HERE
android:name="com.project.me.appname.Activitys.MapsActivity"