恢弘志士之气,不宜妄自菲薄。这篇文章主要讲述谷歌Android的导入类文件存在问题相关的知识,希望能为你提供帮助。
我正在使用firebase C.M.在我的应用程序中创建推送通知模块。但是,当我构建解决方案时,我收到一个错误:
error: cannot access zza
class file for com.google.android.gms.common.internal.safeparcel.zza not found
这是我的gradle项目:
// 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
}
【谷歌Android的导入类文件存在问题】并且gradle app有依赖关系:
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;
我的方法onMessageReceived:
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());
}
难道我做错了什么?我已经检查了很多次,我没有发现错误!谢谢!!!!!
答案根据官方文档,请将您的依赖项更新为最新版本。所以请更改以下代码行
更改
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'
您还可以将项目的classpath gms服务升级到最新版本:
classpath 'com.google.gms:google-services:4.0.1'
推荐阅读
- PubNub GCM通知无法在Android 5.0及更高版本上运行
- 即使App已关闭,也会收到Android推送通知
- 当用户在Android中使用XMPP离线时向用户发送通知
- 接收新的FCM消息(前台和后台)时Android应用程序崩溃
- 我无法从Android GCM获取注册ID
- 推送通知是否在设置中被禁用后传递到Android手机()
- 将应用程序部署到Google App Engine时出现超时错误
- com.google.firebase.messaging.zza(找不到引用的类android.graphics.drawable.AdaptiveIconDrawable)
- Xamarin.Forms Android推送通知不会出现