不幸的是,在启动谷歌地图活动时,应用程序已停止

时间:2017-08-11 17:29:07

标签: android google-maps

我正在尝试使用谷歌应用程序活动创建一个应用程序。我刚刚按照以下步骤使用谷歌地图活动创建谷歌地图应用程序,而不是添加任何额外的代码。应用程序在启动时崩溃。我已经给出了我的清单文件,builde.gradle(app)和logcat。 这是我的清单文件

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.ranjit.getlocation">
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

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


    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">


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

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

下面是build.gradle(app)文件

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.ranjit.getlocation"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.google.android.gms:play-services:10.0.1'
    testCompile 'junit:junit:4.12'
}

应用程序的logcat在

之下
 08-12 10:50:02.947 15439-15439/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   Process: com.example.ranjit.getlocation, PID: 15439
                                                   java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.example.ranjit.getlocation-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.ranjit.getlocation-1, /vendor/lib, /system/lib, /system/lib/arm]]
                                                       at android.app.ActivityThread.installProvider(ActivityThread.java:5029)
                                                       at android.app.ActivityThread.installContentProviders(ActivityThread.java:4621)
                                                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4561)
                                                       at android.app.ActivityThread.access$1500(ActivityThread.java:139)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                       at android.os.Looper.loop(Looper.java:149)
                                                       at android.app.ActivityThread.main(ActivityThread.java:5257)
                                                       at java.lang.reflect.Method.invokeNative(Native Method)
                                                       at java.lang.reflect.Method.invoke(Method.java:515)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
                                                       at dalvik.system.NativeStart.main(Native Method)
                                                    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.example.ranjit.getlocation-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.ranjit.getlocation-1, /vendor/lib, /system/lib, /system/lib/arm]]
                                                       at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                       at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
                                                       at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
                                                       at android.app.ActivityThread.installProvider(ActivityThread.java:5014)
                                                       at android.app.ActivityThread.installContentProviders(ActivityThread.java:4621) 
                                                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4561) 
                                                       at android.app.ActivityThread.access$1500(ActivityThread.java:139) 
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                       at android.os.Looper.loop(Looper.java:149) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:5257) 
                                                       at java.lang.reflect.Method.invokeNative(Native Method) 
                                                       at java.lang.reflect.Method.invoke(Method.java:515) 
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
                                                       at dalvik.system.NativeStart.main(Native Method) 

1 个答案:

答案 0 :(得分:2)

您必须在应用程序中包含multiDex。在清单中,您尚未包含 MulitiDexApplication

ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList

将此添加到您的依赖项。

  compile 'com.android.support:multidex:1.0.1'

在Gradle中添加multiDexEnabled true

android {
    defaultConfig {
        ...
        minSdkVersion 21 
        targetSdkVersion 26
        multiDexEnabled true    // add this line
    }
    ...
}

在清单中添加multiDex应用程序类。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <application
            android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>
</manifest>

避免包含完整的播放服务(compile 'com.google.android.gms:play-services:10.0.1')库。相反,使用你需要的特定库。

为地图添加了依赖

com.google.android.gms:play-services-maps:11.0.4