最新的Firebase SDK将继续导致应用崩溃

时间:2019-02-01 11:49:37

标签: android firebase kotlin firebase-cloud-messaging

我正在尝试在build.gradle中添加以下依赖项-

implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-messaging:17.3.4'

但是应用程序将继续崩溃并显示以下消息-

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/util/zzq;

如果我要从此处删除Firebase,则崩溃将消失。我也尝试过使用Firebase 16.0.6版,但仍然会崩溃。

以下是我的应用程序级别build.gradle-

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

//apply plugin: 'io.fabric'


android {
compileSdkVersion 28
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

lintOptions {

    checkReleaseBuilds false

}

defaultConfig {
    minSdkVersion 22
    targetSdkVersion 28
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
    vectorDrawables.useSupportLibrary = true
}
repositories {
    maven {
        url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
    }
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}



dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:28.0.0-rc01'
implementation 'com.android.support:support-vector-drawable:28.0.0-rc02'
implementation 'com.android.support:support-v4:28.0.0-rc02'
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 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.slice:slice-core:1.0.0-alpha1'
implementation 'androidx.slice:slice-builders:1.0.0-alpha1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha1'
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
//    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
}

以下是我的项目级别build.gradle-

buildscript {
ext.kotlin_version = '1.2.60'
repositories {
    google()
    jcenter()
    maven {
        url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
    }
    maven { url 'https://jitpack.io' }

}
dependencies {
    classpath 'com.android.tools.build:gradle:3.2.0-rc02'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.google.gms:google-services:4.2.0'
}
}

allprojects {
repositories {
    google()
    jcenter()
    maven {
        url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
    }
    maven { url 'https://jitpack.io' }
}
}

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

2 个答案:

答案 0 :(得分:0)

您必须在模块级别apply plugin: "com.google.gms.google-services"底部处添加build.gradle(这样google-services.json的值将应用于资源;该文件可以从火力地堡控制台下载)。最有可能的是,您还必须在implementation "com.google.android.gms:play-services-base:16.1.0"上添加dependencies,以提供一个缺少的类。

并且还有重复的com.android.supportandroidx依赖性;例如:

// implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'

...即使不抛出NoClassDefFoundError,也有重复项,除非已修复。最好先将其完全迁移到androidx,然后再尝试通过Play服务解决该问题;因为虽然在重构的半完成过程中是正确的,但是将问题归因于某件事却相当困难。

答案 1 :(得分:0)

您应在 app gradle 文件中更新依赖项,例如:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

//apply plugin: 'io.fabric'


android {
    compileSdkVersion 28
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    lintOptions {

        checkReleaseBuilds false

    }

    defaultConfig {
        minSdkVersion 22
        targetSdkVersion 28
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
    }
    repositories {
        maven {
            url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}



dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:support-vector-drawable:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    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 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.slice:slice-core:1.0.0'
    implementation 'androidx.slice:slice-builders:1.0.0'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.google.firebase:firebase-core:16.0.6'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
//    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
}

项目gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

//apply plugin: 'io.fabric'


android {
    compileSdkVersion 28
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    lintOptions {

        checkReleaseBuilds false

    }

    defaultConfig {
        minSdkVersion 22
        targetSdkVersion 28
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
    }
    repositories {
        maven {
            url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}



dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:support-vector-drawable:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    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 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.slice:slice-core:1.0.0'
    implementation 'androidx.slice:slice-builders:1.0.0'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.google.firebase:firebase-core:16.0.6'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
//    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
}

希望这对您有所帮助!