无法解析方法addOnCompleteListener

无法解析方法addOnCompleteListener

本文介绍了无法解析方法addOnCompleteListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我的程序的一部分在下面给出.我尝试与Firebase一起使用.有点用这种方法有很多问题.

Part of my program is given below. I try works with firebase. bit I have a lot of problems with this method.

subscribeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.d(TAG, "Subscribing to news topic");
            FirebaseMessaging.getInstance().subscribeToTopic("news").addOnCompleteListener(new OnCompleteListener <Void>() {
                        @Override
                        public void onComplete(@NonNull Task<Void> task) {
                            String msg = getString(R.string.msg_subscribed);
                            if (!task.isSuccessful()) {
                                msg = getString(R.string.msg_subscribe_failed);
                            }
                            Log.d(TAG, msg);
                            Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
                        }
                    });
        }
    });

这是错误:

cannot resolve method addOnCompleteListener anonymous com.google.android.gms.tasks.OnCompleteListener<java.lang.Void>

我的build.gradle

My build.gradle

dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
//implementation 'com.google.protobuf:protobuf-java:2.6.1'
implementation 'com.google.firebase:firebase-core:11.8.0'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.8.1'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile('com.thoughtworks.xstream:xstream:1.4.7') {
    exclude group: 'xmlpull', module: 'xmlpull'
}
compile 'jp.wasabeef:blurry:2.1.1'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.crystal:crystalrangeseekbar:1.1.3'
compile 'wzd.anarchy:library:unspecified'
implementation 'com.android.support:support-v4:25.4.0'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.8'
testCompile 'junit:junit:4.12'
compile 'com.google.protobuf:protobuf-java:3.0.0-beta-3'
dependencies {
    compile 'com.github.TouchBoarder:weekdays-buttons-bar:v1.0.2'
}
compile 'com.jakewharton:butterknife:8.6.0'
compile 'com.firebase:firebase-jobdispatcher:0.5.2'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation 'com.google.firebase:firebase-core:16.0.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
compile 'com.google.android.gms:play-services:12.0.1'
compile "com.polidea.rxandroidble:rxandroidble:1.4.3"
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'io.reactivex.rxjava2:rxjava:2.1.8'
}


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

如果添加实现,则会看到错误:无法访问zzbgl找不到com.google.android.gms.internal.zzbgl的类文件

If I add implementations, I see error: cannot access zzbglclass file for com.google.android.gms.internal.zzbgl not found

推荐答案

由于缺少某些依赖项,因此出现该错误.

You are getting that error because you are missing some dependencies.

FirebaseMessaging.getInstance().subscribeToTopic("news")

返回一个Task<Void>对象.为了在此对象上附加一个侦听器,您需要在build.gradle文件中添加以下依赖项:

Returns a Task<Void> object. In order to attach a listener on this object, you need to add the following dependencies to build.gradle file:

implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation 'com.google.firebase:firebase-core:16.0.1'

根据您的build.gradle文件,您还应该更改以下代码行:

According to your build.gradle file, you also should change this line of code:

compile 'com.google.android.gms:play-services:12.0.1'

implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.google.android.gms:play-services-analytics:16.0.1'

也不要忘记添加:

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

在另一个build.gradle文件中.

In the other build.gradle file.

这篇关于无法解析方法addOnCompleteListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 18:42