谷歌安卓导入类文件的问题



我正在使用Firebase C.M.在我的应用程序中创建一个推送通知模块。但是,当我构建解决方案时,出现错误:

error: cannot access zza
class file for com.google.android.gms.common.internal.safeparcel.zza not found

这是我的毕业项目:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

还有 Gradle 应用程序的依赖项:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
implementation 'com.squareup.okhttp3:okhttp:3.8.0'
implementation 'org.greenrobot:eventbus:3.0.0'
implementation 'com.jakewharton:butterknife:8.6.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
implementation 'com.android.support:cardview-v7:21.0.+'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-messaging:10.2.1'
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'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
transitive = true
}
}
apply plugin: 'com.google.gms.google-services'

我认为问题与此导入有关

import com.google.firebase.messaging.RemoteMessage;

我的方法在消息收到:

private static final String ADMIN_CHANNEL_ID ="admin_channel";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
setupChannels();
}
int notificationId = new Random().nextInt(60000);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, ADMIN_CHANNEL_ID)
.setContentTitle(remoteMessage.getData().get("title"))
.setContentText(remoteMessage.getData().get("message"))
.setAutoCancel(true)
.setSound(defaultSoundUri);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId /* ID of notification */, notificationBuilder.build());
}

我做错了什么吗?我已经检查了很多次gradle,但没有发现错误!感谢!!!!!

根据官方文档,请将您的依赖项更新到最新版本。所以请更改以下代码行

改变

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

implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-messaging:17.3.0'

您还可以将项目的类路径 gms 服务升级到最新版本:

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

相关内容

  • 没有找到相关文章

最新更新