【问题标题】:Fatal Exception: java.lang.NoClassDefFoundError com.google.android.gms.internal.firebase-perf.zzw致命异常:java.lang.NoClassDefFoundError com.google.android.gms.internal.firebase-perf.zzw
【发布时间】:2018-08-21 03:04:57
【问题描述】:

在应用启动时收到此错误。

致命异常:java.lang.NoClassDefFoundError: com.google.android.gms.internal.firebase-perf.zzw 在 com.google.firebase.perf.metrics.Trace.start(未知来源) 在 com.google.android.gms.internal.firebase-perf.zze.onActivityStarted(未知 来源) 在 android.app.Application.dispatchActivityStarted(Application.java:205) 在 android.app.Activity.onStart(Activity.java:1156) 在 android.support.v4.app.FragmentActivity.onStart(未知来源) 在 android.support.v7.app.AppCompatActivity.onStart(未知来源) 在 android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1268) 在 android.app.Activity.performStart(Activity.java:6333) 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2542) 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2671) 在 android.app.ActivityThread.-wrap11(ActivityThread.java) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1501) 在 android.os.Handler.dispatchMessage(Handler.java:111) 在 android.os.Looper.loop(Looper.java:207) 在 android.app.ActivityThread.main(ActivityThread.java:5774) 在 java.lang.reflect.Method.invoke(Method.java) 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:681)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'com.google.gms:google-services:3.2.0'
        classpath 'com.google.firebase:firebase-plugins:1.1.5'
        classpath 'io.fabric.tools:gradle:1.24.4'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}
allprojects {
    repositories {
        maven { url "https://jitpack.io" }
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

//

apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-crash'
apply plugin: 'io.fabric'
// Create a variable called keystorePropertiesFile, and initialize it to your
// keystore.properties file, in the rootProject folder.
def keystorePropertiesFile = rootProject.file("keystore.properties")

// Initialize a new Properties() object called keystoreProperties.
def keystoreProperties = new Properties()

// Load your keystore.properties file into the keystoreProperties object.
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"
    defaultConfig {
        applicationId "com.abc.xyz"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 18
        versionName "1.9"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }

//Signing configurations for build variants "release"
    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }

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

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:27.1.1'
    compile 'com.android.support.constraint:constraint-layout:1.1.2'
    compile 'com.android.support:design:27.1.1'
    compile 'com.android.support:support-v4:27.1.1'
    compile 'com.android.support:cardview-v7:27.1.1'
    compile 'de.hdodenhof:circleimageview:2.2.0'
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.squareup.retrofit2:converter-gson:2.3.0'
    compile 'com.squareup.okhttp3:okhttp-urlconnection:3.4.1'
    compile 'com.squareup.okhttp3:logging-interceptor:3.5.0'
    compile 'com.android.support:support-vector-drawable:27.1.1'
    compile 'com.google.firebase:firebase-crash:16.0.1'
    compile 'com.google.firebase:firebase-messaging:17.3.0'
    compile 'com.google.firebase:firebase-config:16.0.0'
    compile 'com.google.android.gms:play-services-location:15.0.1'
    compile 'com.google.android.gms:play-services-maps:15.0.1'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.google.firebase:firebase-auth:16.0.3'
    compile 'com.google.android.gms:play-services-auth:16.0.0'
    compile 'com.google.firebase:firebase-core:16.0.1'
    compile 'com.google.firebase:firebase-perf:16.1.0'
    compile 'com.google.android.gms:play-services-places:15.0.1'

 compile('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
        transitive = true
    }
    testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.firebase-perf'

【问题讨论】:

标签: android firebase noclassdeffounderror


【解决方案1】:

Firebase-crash 版本firebase-perf 版本 必须小于或等于 Firebase-core 版本 所以在您的代码中将 Firebase-crash:16.0.1 版本更改为 Firebase-crash:16.0.0 并将 firebase-perf:16.1.0 版本更改为 firebase-perf:16.0.0 因为你的 firebase-core 版本是 16.0.1

   compile 'com.google.firebase:firebase-perf:16.0.0'
   compile 'com.google.firebase:firebase-crash:16.0.0'

【讨论】:

【解决方案2】:

我遇到了同样的问题,虽然 Siva Kumar 的解决方案有效,但对我来说也有效的是在您的 项目 build.gradle 上使用最新的 google-services 库:

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

【讨论】:

    【解决方案3】:

    对我来说,其他解决方案都不起作用。非常令人沮丧,应用程序甚至没有启动。 最后我删除了性能监控:

    //apply plugin: 'com.google.firebase.firebase-perf'
    //implementation 'com.google.firebase:firebase-perf:16.1.2'
    

    【讨论】:

    • 对我来说,同样的问题,应用程序无法启动,我尝试了很多组合。我没有更新 google-services json 文件。我更新了问题仍然存在。最后删除了firebase性能监控“com.google.firebase:firebase-perf:16.1.2”包,一切正常。我使用的是这个包的旧版本(16.0.0),它工作正常,在最新的包中,事情没有按预期工作。谢谢@tsig
    【解决方案4】:

    我的问题分两步解决:

    • 首先,我将 build.gradle (app) 中的所有 Firebase 依赖项更新为最新版本。 只需更新每个突出显示的 Firebase 依赖项
    • 将 build.gradle(项目)上的 google-services 库更新到最新版本。也可以使用android studio的warning-highlight来引导。

      dependencies {
          classpath 'com.google.gms:google-services:4.3.0' // this is the latest as at July, 2019
      }
      

    在此之后一切都应该正常工作。

    我希望这会有所帮助。编码愉快!

    【讨论】:

      【解决方案5】:

      根据 Firebase 上的先决条件文档 - 关于 android 的性能监控文档:

      在开始之前,您需要在您的环境中设置一些东西:

      A device running Android 4.0 (Ice Cream Sandwich) or newer, and Google Play services 16.1.0 or higher
      The Google Play services SDK from the Google Repository, available in the Android SDK Manager
      The latest version of Android Studio, version 2.2 or higher
      

      此链接详细说明了设置。

      Firebase Performance Monitoring Guide

      此外,Alex 提到了我们可以通过升级 gradle 中提到的依赖项在构建周期中引入最新的 google 服务的方式

      classpath 'com.google.gms:google-services:4.1.0'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多