2

I have integrated Quick Blox Chat SDK version 3.8.1 (the latest version available as on 25-Sep-2018). I have successfully integrated the chat SDK. The problem which I'm facing is app crashes while opening for the first time with the following error.

 java.lang.RuntimeException: An error occurred while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:353)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
    at java.util.concurrent.FutureTask.run(FutureTask.java:271)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
    at java.lang.Thread.run(Thread.java:764)
 Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzbq;
    at com.google.android.gms.gcm.Task$Builder.checkConditions(Unknown Source:10)
    at com.google.android.gms.gcm.OneoffTask$Builder.checkConditions(Unknown Source:0)
    at com.google.android.gms.gcm.OneoffTask$Builder.build(Unknown Source:0)
    at com.quickblox.messages.services.SubscribeTaskManager.a(Unknown Source:49)
    at com.quickblox.messages.services.SubscribeService.c(Unknown Source:22)
    at com.quickblox.messages.services.SubscribeService.a(Unknown Source:145)
    at com.quickblox.messages.services.SubscribeService.a(Unknown Source:125)
    at com.quickblox.messages.services.SubscribeService.e(Unknown Source:12)
    at com.quickblox.messages.services.SubscribeService.b(Unknown Source:18)
    at com.quickblox.messages.services.SubscribeService.onHandleWork(Unknown Source:46)
    at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:392)
    at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:383)
    at android.os.AsyncTask$2.call(AsyncTask.java:333)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 
    at java.lang.Thread.run(Thread.java:764) 
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzbq" on path: DexPathList[[zip file "/data/app/-HWe3wDorvDDaXln_aZyI2g==/base.apk"],nativeLibraryDirectories=[/data/app/HWe3wDorvDDaXln_aZyI2g==/lib/x86, /data/app/HWe3wDorvDDaXln_aZyI2g==/base.apk!/lib/x86, /system/lib, /vendor/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at com.google.android.gms.gcm.Task$Builder.checkConditions(Unknown Source:10) 
    at com.google.android.gms.gcm.OneoffTask$Builder.checkConditions(Unknown Source:0) 
    at com.google.android.gms.gcm.OneoffTask$Builder.build(Unknown Source:0) 
    at com.quickblox.messages.services.SubscribeTaskManager.a(Unknown Source:49) 
    at com.quickblox.messages.services.SubscribeService.c(Unknown Source:22) 
    at com.quickblox.messages.services.SubscribeService.a(Unknown Source:145) 
    at com.quickblox.messages.services.SubscribeService.a(Unknown Source:125) 
    at com.quickblox.messages.services.SubscribeService.e(Unknown Source:12) 
    at com.quickblox.messages.services.SubscribeService.b(Unknown Source:18) 
    at com.quickblox.messages.services.SubscribeService.onHandleWork(Unknown Source:46) 
    at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:392) 
    at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:383) 
    at android.os.AsyncTask$2.call(AsyncTask.java:333) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 
    at java.lang.Thread.run(Thread.java:764) 

The app were working fine without any issue prior to integrate chat SDK. So I'm strongly belive that the issue is caused by chat SDK.

Notes

Mutidex is already enabled

Here is my app gradle file

    buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}


android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion 21
        targetSdkVersion 28
        multiDexEnabled true
        versionCode 1
        versionName "1.0 - Alpha Dev version"


        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
            }
        }

        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }


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

    dataBinding {
        enabled = true
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

}

dependencies {
    def paging_version = "1.0.1"
    def material = "1.0.0-rc01"
    def qbSdkVersion = '3.8.1'
    def swipyVersion = '1.2.3'
    def stickylistheadersVersion = '0.4.2'
    def androidSupport = '28.0.0'
    def androidArch = '1.1.1'
    def playService = '15.0.1'


    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "com.android.support:appcompat-v7:$androidSupport"
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation "com.android.support:design:$androidSupport"
    implementation 'com.google.firebase:firebase-crash:16.2.0'

    implementation "android.arch.lifecycle:extensions:$androidArch"
    implementation "android.arch.lifecycle:viewmodel:$androidArch"
    implementation "android.arch.persistence.room:runtime:$androidArch"
    annotationProcessor "android.arch.persistence.room:compiler:$androidArch"

    implementation "com.google.android.gms:play-services-location:$playService"
    implementation "com.google.android.gms:play-services-places:$playService"
    implementation "com.google.firebase:firebase-core:16.0.3"

    implementation 'com.google.firebase:firebase-messaging:17.3.2'



    implementation 'com.nineoldandroids:library:2.4.0'
    implementation 'com.daimajia.slider:library:1.1.5@aar'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'pub.devrel:easypermissions:1.2.0' /*permission simplified*/
    implementation 'com.github.jrvansuita:PickImage:2.2.3'/*Image picker Camera/Gallery*/
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' /*Image cropper*/
    implementation 'com.wdullaer:materialdatetimepicker:3.6.3' /*Date picker*/
    implementation 'com.kofigyan.stateprogressbar:stateprogressbar:1.0.0'
    implementation('com.github.ganfra:material-spinner:2.0.0') {
        exclude group: 'com.android.support', module: 'appcompat-v7'
    }
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'

    implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
    implementation 'com.github.danimahardhika:cafebar:1.3.1'/*Snack Toast  SDK*/
    implementation(name: 'sinch-android-verification-1.5.1', ext: 'aar') /*SMS verification*/
    implementation 'com.github.blocoio:faker:1.2.7' /*Data faker*/
    implementation 'com.github.joielechong:countrycodepicker:2.1.8'
    implementation 'com.yarolegovich:sliding-root-nav:1.1.0' /*Custom nav drawer*/
    implementation "com.yuyakaido.android:card-stack-view:1.0.0-beta9" /*Card stack view*/
    implementation 'com.jaredrummler:android-animations:1.0.0' /*View Animator*/
    implementation 'com.facebook.fresco:fresco:1.10.0'
    implementation 'com.github.Binary-Finery:Bungee:master-SNAPSHOT'/*Activity Translation*/
    implementation 'com.github.ybq:Android-SpinKit:1.1.0' /*Loading animations*/
    implementation 'com.github.thunder413:DateTimeUtils:1.0' /*Date converter utility*/
    implementation(name: 'filepicker', ext: 'aar')
    implementation(name: 'materialrangebar', ext: 'aar')
    implementation 'com.github.warkiz.widget:indicatorseekbar:2.0.9'
    implementation 'com.github.PuffoCyano:Range-Time-Picker-Dialog:v1.5' /*Multi time range picker*/


    implementation('com.crashlytics.sdk.android:crashlytics:2.9.5@aar') {
        transitive = true;
    }

    implementation "com.quickblox:quickblox-android-sdk-chat:$qbSdkVersion"
    implementation "com.quickblox:quickblox-android-sdk-extensions:$qbSdkVersion"
    implementation "com.quickblox:quickblox-android-sdk-messages:$qbSdkVersion"
    implementation 'com.quickblox:chat-message-adapter:2.0'
    implementation "com.github.orangegangsters:swipy:$swipyVersion@aar"
    implementation "com.timehop.stickyheadersrecyclerview:library:$stickylistheadersVersion@aar"


}

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

Let me explain the scenario where app crash.

  1. Run app from Android studio / Build APK and install directly in to device.
  2. Splash screen -> Login page {here crash happens - surprisingly it's only happens at first time of app launch , if i kill the app and launched again this issue not showing up }

Any help appreciated.

Nikhil
  • 911
  • 15
  • 28

2 Answers2

3

Since version 3.2 android SDK provides new feature - auto subscription to push notification out of the box. It means you don’t need bother how to get GCM or FCM token, create QBPushNotifications.createSubscription and what to do with received data in your code anymore.

Actually what's making the app crash is that, you have not added the GCM dependency as stated by Quickblox. Add the GCM dependency with version same as your other play services sdk version:

implementation "com.google.android.gms:play-services-gcm:$your_version"

This will remove Caused by: java.lang.NoClassDefFoundError

Nikhil
  • 911
  • 15
  • 28
Insane Developer
  • 1,014
  • 10
  • 19
  • Let me gave it a try and update you soon. Is it resolved your issue? – Nikhil Sep 27 '18 at 11:36
  • As you mentioned above, the issue was resolved. Let me go through multiple test cases to confirm this issue won't happen in the future anymore. – Nikhil Sep 28 '18 at 04:20
  • Yes, it is working perfectly fine. It's weird even though we are using FCM for push notification still we have to include gcm library as part of quick blox chat dependency – Nikhil Sep 28 '18 at 05:25
0

After hours of research and trial and error, I ended up with something like this to overcome the issue.

I found that the issue is mainly because of Quick Blox SubscribeService.

To overcome that follow the below workaround.

<service android:name="com.quickblox.messages.services.fcm.QBFcmPushInstanceIDService">
                    <intent-filter>
                        <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
                    </intent-filter>
                </service>

Remove the above service tag from the app manifest. The QBFcmPushInstanceIDService get invoked every time we open the application and an FCM token get refreshed which il trigger the following

SubscribeService.subscribeToPushes(this, true);

There the error occurs.

The SubscribeService must be called only after the successful login to Quick Blox server. So what I did was I removed it from the manifest and used default FCM functionality.

    // Get token for sending notification to device { Google FCM }
        FirebaseInstanceId.getInstance().getInstanceId()
                .addOnCompleteListener(task -> {
                    if (!task.isSuccessful()) {
                        Log.warn("getInstanceId failed" + task.getException());
                        return;
                    }

                    // Get new Instance ID token
                    String token = task.getResult().getToken();
                    SubscribeService.subscribeToPushes(this, true);



                });

The above code must be initiated only after once you login into the quick blox chat server

Nikhil
  • 911
  • 15
  • 28
  • This answer didn't help me. Unique token is generated only once during app first run. I went through the Quickblox doc again and found some hint to resolve. I am putting that as an answer. – Insane Developer Sep 27 '18 at 10:45
  • Please use the accepted answer to solve the issue. I spend a couple of long hours to fix the issue and My answer was just a workaround for the issue as I had to overcome the issue at any cost – Nikhil Sep 28 '18 at 05:29