Quick Blox Android 聊天 SDK (v3.8.1) - 启动时应用程序崩溃 com.quickblox.messages.services.SubscribeTaskManager.a(未知 Source:49)
Quick Blox Android Chat SDK (v3.8.1) - App Crash while launching com.quickblox.messages.services.SubscribeTaskManager.a(Unknown Source:49)
我已经集成了 Quick Blox Chat SDK 版本 3.8.1(最新版本于 2018 年 9 月 25 日可用)。我已经成功集成了聊天SDK。我面临的问题是应用程序在第一次打开时崩溃并出现以下错误。
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask.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.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.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)
在集成聊天 SDK 之前,该应用程序运行良好,没有任何问题。所以我坚信问题是由聊天 SDK 引起的。
备注
Mutidex 已启用
这是我的应用 gradle 文件
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'
让我解释一下应用崩溃的场景。
- 运行 来自 Android studio 的应用程序/构建 APK 并直接安装到设备中。
- 启动画面 -> 登录页面{这里发生崩溃 - 令人惊讶的是它只发生在第一次启动应用程序时,如果我终止应用程序并再次启动这个问题就不会出现}
感谢任何帮助。
经过数小时的研究和反复试验,我最终得到了这样的东西来解决这个问题。
我发现这个问题主要是因为 Quick Blox SubscribeService。
要解决这个问题,请遵循以下解决方法。
<service android:name="com.quickblox.messages.services.fcm.QBFcmPushInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
从应用程序清单中删除上述服务标签。每次我们打开应用程序时都会调用 QBFcmPushInstanceIDService 并刷新 FCM 令牌,这会触发以下
SubscribeService.subscribeToPushes(this, true);
出现错误。
SubscribeService 必须仅在成功登录到 Quick Blox 服务器后调用。所以我所做的是将它从清单中删除并使用默认的 FCM 功能。
// 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);
});
以上代码必须在您登录快速 blox 聊天服务器后才能启动
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.
实际上导致应用程序崩溃的原因是,您没有按照 Quickblox 的说明添加 GCM 依赖项。
添加与您的其他播放服务 sdk 版本相同的 GCM 依赖项:
implementation "com.google.android.gms:play-services-gcm:$your_version"
这将删除 Caused by: java.lang.NoClassDefFoundError
我已经集成了 Quick Blox Chat SDK 版本 3.8.1(最新版本于 2018 年 9 月 25 日可用)。我已经成功集成了聊天SDK。我面临的问题是应用程序在第一次打开时崩溃并出现以下错误。
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask.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.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.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)
在集成聊天 SDK 之前,该应用程序运行良好,没有任何问题。所以我坚信问题是由聊天 SDK 引起的。
备注
Mutidex 已启用
这是我的应用 gradle 文件
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'
让我解释一下应用崩溃的场景。
- 运行 来自 Android studio 的应用程序/构建 APK 并直接安装到设备中。
- 启动画面 -> 登录页面{这里发生崩溃 - 令人惊讶的是它只发生在第一次启动应用程序时,如果我终止应用程序并再次启动这个问题就不会出现}
感谢任何帮助。
经过数小时的研究和反复试验,我最终得到了这样的东西来解决这个问题。
我发现这个问题主要是因为 Quick Blox SubscribeService。
要解决这个问题,请遵循以下解决方法。
<service android:name="com.quickblox.messages.services.fcm.QBFcmPushInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
从应用程序清单中删除上述服务标签。每次我们打开应用程序时都会调用 QBFcmPushInstanceIDService 并刷新 FCM 令牌,这会触发以下
SubscribeService.subscribeToPushes(this, true);
出现错误。
SubscribeService 必须仅在成功登录到 Quick Blox 服务器后调用。所以我所做的是将它从清单中删除并使用默认的 FCM 功能。
// 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);
});
以上代码必须在您登录快速 blox 聊天服务器后才能启动
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.
实际上导致应用程序崩溃的原因是,您没有按照 Quickblox 的说明添加 GCM 依赖项。 添加与您的其他播放服务 sdk 版本相同的 GCM 依赖项:
implementation "com.google.android.gms:play-services-gcm:$your_version"
这将删除 Caused by: java.lang.NoClassDefFoundError