将 Google 地图添加到现有项目有膨胀异常

Add Google map to existing project has inflate exception

我想向现有应用显示 activity 上的地图。我将地图片段添加到我的 xml 并获得 api 密钥但应用程序低于错误。我该如何解决这个问题?

我通过右键单击 activity 包和 select google 地图 activity 添加了地图 xml 和 activity,但仍然无法正常工作并且有错误。

我的xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    tools:context="com.co.KITIL.MapActivity"/>

<Button
    android:id="@+id/saveBtn"
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:text="شروع کار"
    android:textSize="15sp"
    android:background="@color/blue"
    android:textColor="@android:color/white"/>
</LinearLayout>

我的activity:

package com.co.KITIL;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;


public class MapActivity extends FragmentActivity implements OnMapReadyCallback {

SupportMapFragment mapView;
GoogleMap googleMap;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);
    mapView=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
    mapView.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {

}
}

AndroidManifest:

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

google_maps_api.xml 来自 debug.res.values;

<resources>

<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AI-----------------bcI</string>

错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com..KITIL/com..KITIL.MapsActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class fragment
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                   at a
                                                Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class fragment
                                                Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class fragment
                                                Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: calling Fragment constructor caused an exception

我在下面找到了我的解决方案 link:

Google map not showing in android activity?

我应该启用 google 映射 api 然后再次下载 google-services.json 并复制到解决方案中。