集成Firebase导致Android崩溃

时间:2018-11-13 06:44:58

标签: android firebase google-analytics

按照文档集成了Firebase之后……我在应用程序类的其中一行中崩溃了

GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);

日志:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzbq;
        at com.google.android.gms.internal.zzark.zzbl(Unknown Source:0)
        at com.google.android.gms.analytics.GoogleAnalytics.getInstance(Unknown Source:0)
        at com.bmw.bmwsales.BMWSalesApplication.onCreate(BMWSalesApplication.java:83)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1122)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6517)
        at android.app.ActivityThread.-wrap2(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1963)
        at android.os.Handler.dispatchMessage(Handler.java:108)
        at android.os.Looper.loop(Looper.java:166)
        at android.app.ActivityThread.main(ActivityThread.java:7425)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzbq" on path: DexPathList[[zip file "/data/app/com.bmw.bmwsales-uVdnAKZw9szHT_S3LTCH0A==/base.apk"],nativeLibraryDirectories=[/data/app/com.bmw.bmwsales-uVdnAKZw9szHT_S3LTCH0A==/lib/arm64, /system/lib64, /vendor/lib64, /product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at com.google.android.gms.internal.zzark.zzbl(Unknown Source:0) 
        at com.google.android.gms.analytics.GoogleAnalytics.getInstance(Unknown Source:0) 
        at com.bmw.bmwsales.BMWSalesApplication.onCreate(BMWSalesApplication.java:83) 
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1122) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6517) 
        at android.app.ActivityThread.-wrap2(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1963) 
        at android.os.Handler.dispatchMessage(Handler.java:108) 
        at android.os.Looper.loop(Looper.java:166) 
        at android.app.ActivityThread.main(ActivityThread.java:7425) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921) 

代码

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "package-name"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 16
        versionName "2.1"

        multiDexEnabled true
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    lintOptions {
        checkReleaseBuilds false
    }

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

repositories {
    mavenCentral()
    maven {
        url 'http://maven.batch.com/release'
    }
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
}

dependencies {
    implementation project(':library')
    implementation project(':urlImageViewHelper')
    //implementation 'com.google.android.gms:play-services:9.6.1'
    implementation 'com.google.android.gms:play-services:12.0.1'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    //implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:animated-vector-drawable:28.0.0'
    implementation 'com.android.support:mediarouter-v7:28.0.0'
    implementation 'com.google.code.gson:gson:2.2.4'
    //implementation 'com.batch.android:batch-sdk:1.6.0'
    implementation files('libs/bolts-android-1.2.0.jar')
    implementation files('libs/glide-3.4.0.jar')
    implementation files('libs/imagecoverflow-master.jar')
    implementation files('libs/mint-4.0.7.jar')
    implementation files('libs/Parse-1.9.2.jar')
    implementation files('libs/universal-image-loader-1.9.3-with-sources.jar')
    implementation files('libs/YouTubeAndroidPlayerApi.jar')
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.loopj.android:android-async-http:1.4.9'
    implementation 'com.github.d-max:spots-dialog:0.4@aar'
    implementation 'com.batch.android:batch-sdk:1.13+'
    implementation "com.google.firebase:firebase-core:16.0.1"
    implementation 'com.android.support:multidex:1.0.0'

    /*implementation 'com.google.android.gms:play-services-auth:10.0.1'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.google.firebase:firebase-storage:16.0.1'*/


}
apply plugin: 'com.google.gms.google-services'

3 个答案:

答案 0 :(得分:0)

看起来像您错过了这些。

将以下依赖项添加到您的项目级build.gradle:

dependencies {
  // ...
  classpath 'com.google.gms:google-services:3.0.0'
}

将以下对Google Play服务的依赖性添加到app / build.gradle:

dependencies {
  // ...
  compile 'com.google.android.gms:play-services-analytics:10.2.4'
}

有关更多信息:Google Analytics in Android

答案 1 :(得分:0)

修改build.gradle:

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0"

         defaultConfig {
             minSdkVersion 14 //lower than 14 doesn't support multidex
             targetSdkVersion 22

             // Enabling multidex support.
             multiDexEnabled true
         }
}

dependencies {
    compile 'com.android.support:multidex:1.0.3'
}

如果没有一个应用程序,则添加应用程序单例类

public class YouApplication extends Application {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

}

在清单中添加应用程序类作为名称

 <application
        android:name=".YouApplication "
        >

答案 2 :(得分:0)

我通过:

dependencies {
    implementation project(':library')
    implementation project(':urlImageViewHelper')
    //implementation 'com.google.android.gms:play-services:9.6.1'
    implementation 'com.google.android.gms:play-services:12.0.1'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    //implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:animated-vector-drawable:28.0.0'
    implementation 'com.android.support:mediarouter-v7:28.0.0'
    implementation 'com.google.code.gson:gson:2.2.4'
    //implementation 'com.batch.android:batch-sdk:1.6.0'
    implementation files('libs/bolts-android-1.2.0.jar')
    implementation files('libs/glide-3.4.0.jar')
    implementation files('libs/imagecoverflow-master.jar')
    implementation files('libs/mint-4.0.7.jar')
    implementation files('libs/Parse-1.9.2.jar')
    implementation files('libs/universal-image-loader-1.9.3-with-sources.jar')
    implementation files('libs/YouTubeAndroidPlayerApi.jar')
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.loopj.android:android-async-http:1.4.9'
    implementation 'com.github.d-max:spots-dialog:0.4@aar'
    implementation 'com.batch.android:batch-sdk:1.13+'
    implementation "com.google.firebase:firebase-core:12.0.1"

}

是版本冲突