新创建的Google Map活动上的运行时错误

时间:2018-11-23 21:11:19

标签: java android google-maps

我刚刚在android studio中创建了一个新的google map活动,但是它给了运行时错误。我也在这个项目中使用Firebase。即时消息不是android开发中的新功能,但这是我第一次使用google maps api。友善的帮助 MapsActivity.java

    package com.dreamfighter.roomrental;

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

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}


/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney and move the camera
//        LatLng sydney = new LatLng(-34, 151);
//        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
//        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
}

activty_maps.xml

<?xml version="1.0" encoding="utf-8"?>
<fragment 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:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapsActivity" />

AndroidManifest.xml

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

    <!-- To auto-complete the email text field in the login form with the user's emails -->

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

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

    <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">
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="i dont want my api key on stack overflow" />

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".LoginActivity"
            android:label="@string/title_activity_login" />
        <activity
            android:name=".RegisterActivity"
            android:label="@string/title_activity_register" />
        <activity android:name=".single_full_post" />
        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps"></activity>
    </application>

</manifest>

错误:

11-24 02:05:00.185 14219-14219/com.dreamfighter.roomrental E/BoostFramework: BoostFramework() : Exception_1 = java.lang.ClassNotFoundException: Didn't find class "com.qualcomm.qti.Performance" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib64, /vendor/lib64]]
11-24 02:05:00.397 14219-14219/com.dreamfighter.roomrental E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dreamfighter.roomrental/com.dreamfighter.roomrental.MapsActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class fragment
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
        at android.app.ActivityThread.-wrap14(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
     Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class fragment
     Caused by: android.view.InflateException: Binary XML file line #2: 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
        at android.support.v4.app.Fragment.instantiate(Fragment.java:481)
        at android.support.v4.app.FragmentContainer.instantiate(FragmentContainer.java:33)
        at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3664)
        at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
        at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:338)
        at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
        at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:67)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:784)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:496)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:378)
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:446)
        at android.app.Activity.setContentView(Activity.java:2544)
        at com.dreamfighter.roomrental.MapsActivity.onCreate(MapsActivity.java:20)
        at android.app.Activity.performCreate(Activity.java:6942)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
        at android.app.ActivityThread.-wrap14(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
        at android.support.v4.app.Fragment.instantiate(Fragment.java:459)
        at android.support.v4.app.FragmentContainer.instantiate(FragmentContainer.java:33) 
        at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3664) 
        at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111) 
        at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:338) 
        at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39) 
        at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:67) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:784) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:496) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:378) 
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:446) 
        at android.app.Activity.setContentView(Activity.java:2544) 
        at com.dreamfighter.roomrental.MapsActivity.onCreate(MapsActivity.java:20) 
        at android.app.Activity.performCreate(Activity.java:6942) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
        at android.app.ActivityThread.-wrap14(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6682) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 
     Caused by: java.lang.IllegalAccessError: Class com.google.android.gms.dynamic.zza extended by class com.google.android.gms.maps.SupportMapFragment$zzb is inaccessible (declaration of 'com.google.android.gms.maps.SupportMapFragment$zzb' appears in /data/app/com.dreamfighter.roomrental-1/split_lib_dependencies_apk.apk:classes2.dex)
        at java.lang.reflect.Constructor.newInstance0(Native Method) 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
        at android.support.v4.app.Fragment.instantiate(Fragment.java:459) 
        at android.support.v4.app.FragmentContainer.instantiate(FragmentContainer.java:33) 
        at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3664) 
        at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111) 
        at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:338) 
        at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39) 
        at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:67) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:784) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:496) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:378) 
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:446) 
        at android.app.Activity.setContentView(Activity.java:2544) 
        at com.dreamfighter.roomrental.MapsActivity.onCreate(MapsActivity.java:20) 
        at android.app.Activity.performCreate(Activity.java:6942) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
        at android.app.ActivityThread.-wrap14(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6682) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 


    --------- beginning of crash
11-24 02:05:00.397 14219-14219/com.dreamfighter.roomrental E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.dreamfighter.roomrental, PID: 14219
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dreamfighter.roomrental/com.dreamfighter.roomrental.MapsActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class fragment
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
        at android.app.ActivityThread.-wrap14(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
     Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class fragment
     Caused by: android.view.InflateException: Binary XML file line #2: 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
        at android.support.v4.app.Fragment.instantiate(Fragment.java:481)
        at android.support.v4.app.FragmentContainer.instantiate(FragmentContainer.java:33)
        at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3664)
        at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
        at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:338)
        at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
        at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:67)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:784)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:496)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:378)
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:446)
        at android.app.Activity.setContentView(Activity.java:2544)
        at com.dreamfighter.roomrental.MapsActivity.onCreate(MapsActivity.java:20)
        at android.app.Activity.performCreate(Activity.java:6942)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
        at android.app.ActivityThread.-wrap14(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
        at android.support.v4.app.Fragment.instantiate(Fragment.java:459)
        at android.support.v4.app.FragmentContainer.instantiate(FragmentContainer.java:33) 
        at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3664) 
        at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111) 
        at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:338) 
        at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39) 
        at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:67) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:784) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:496) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:378) 
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:446) 
        at android.app.Activity.setContentView(Activity.java:2544) 
        at com.dreamfighter.roomrental.MapsActivity.onCreate(MapsActivity.java:20) 
        at android.app.Activity.performCreate(Activity.java:6942) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
        at android.app.ActivityThread.-wrap14(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6682) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 
     Caused by: java.lang.IllegalAccessError: Class com.google.android.gms.dynamic.zza extended by class com.google.android.gms.maps.SupportMapFragment$zzb is inaccessible (declaration of 'com.google.android.gms.maps.SupportMapFragment$zzb' appears in /data/app/com.dreamfighter.roomrental-1/split_lib_dependencies_apk.apk:classes2.dex)
        at java.lang.reflect.Constructor.newInstance0(Native Method) 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
        at android.support.v4.app.Fragment.instantiate(Fragment.java:459) 
        at android.support.v4.app.FragmentContainer.instantiate(FragmentContainer.java:33) 
        at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3664) 
        at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111) 
        at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:338) 
        at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39) 
        at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:67) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:784) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:496) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:378) 
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:446) 
        at android.app.Activity.setContentView(Activity.java:2544) 
        at com.dreamfighter.roomrental.MapsActivity.onCreate(MapsActivity.java:20) 
        at android.app.Activity.performCreate(Activity.java:6942) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
        at android.app.ActivityThread.-wrap14(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6682) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 

Build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.dreamfighter.roomrental"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.android.gms:play-services-maps:12.0.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-auth:16.0.1'
    implementation 'com.master.android:glideimageview:1.0'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'com.google.android.gms:play-services:12.0.1'
}
apply plugin: 'com.google.gms.google-services'

2 个答案:

答案 0 :(得分:1)

我也遇到了同样的问题,并通过以下步骤解决了问题。

主要是版本问题。 Firebase仅支持最新版本。如果您使用的是Firebase分析(实施'com.google.firebase:firebase-core:16.0.1'),那么我们应该使用最新的Google服务。因此您使用的是12.0.1,它将不支持。

 implementation 'com.google.android.gms:play-services-maps:15.0.1'
 implementation 'com.google.android.gms:play-services-location:15.0.1'

以上版本解决了我的问题。

答案 1 :(得分:-2)

找到的解决方案: 在项目级别build.gradle文件中,将类路径'com.google.gms:google-services:4.0.1'替换为类路径'com.google.gms:google-services:3.2.1'。

更新 再次找到解决方案: 我添加了更多的依赖关系后,错误又回来了。只需将所有依赖项更新为最新版本,即可解决问题。