0

I'm trying to add following dependencies in build.gradle -

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

But app will keep crashing with following message -

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

If i'm going to remove firebase from here then the crash will go away. I have tried with firebase version 16.0.6 too but still it will keep crashing.

Following is my app level 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'
}

Following is my project level 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
}
Paraskevas Ntsounos
  • 1,755
  • 2
  • 18
  • 34
Mandeep Kumar
  • 776
  • 4
  • 18

2 Answers2

0

you'd have to add apply plugin: "com.google.gms.google-services" at the bottom of the module level's build.gradle (so that the values of google-services.json will be applied to the resources; this file can be downloaded from the Firebase console). most likely, you'd also have to add implementation "com.google.android.gms:play-services-base:16.1.0" to the dependencies, in order to provide that one missing class.

and there are also duplicate com.android.support vs. androidx dependencies; for example:

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

...even if it won't throw NoClassDefFoundError, there will be duplicates unless these are fixed. better first fully migrate to androidx and then try to fix the issue with Play Services; because while being right within the half-done process of refactoring, it is rather difficult to attribute an issue to something.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • @MandeepKumar clean the project and rebuild & make sure to use a device/emulator image which does support play services. adding the `apply plugin` to the top, as the other answer suggests is non-sense, because the order of instructions plays a role there. – Martin Zeitler Feb 01 '19 at 13:20
  • Tried putting down the apply plugin at bottom , tried cleaning and rebuilding the project , still crashing . It is crashing on emulator only not on a real device . I'm using emulator with api 27 – Mandeep Kumar Feb 01 '19 at 13:38
  • @MandeepKumar the API level barely matters, it needs to be an image with Play Services installed. also, those `-alpha1` versions are obsolete since quite a while, long replaced by final versions (they should all be marked with a yellow background). `com.google.firebase:firebase-auth` would pull in `play-services-base` as dependency, without having to explicitly add it... that `NoClassDefFoundError` clearly hints for an issue with the Play Services, either Gradle plugin, Java library, or having the APK installed on the device. – Martin Zeitler Feb 01 '19 at 15:25
0

You should update your dependencies in app gradle file like:

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'
}

And project 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'
}

Hope this help you!

Paraskevas Ntsounos
  • 1,755
  • 2
  • 18
  • 34