Проблемы с импортом файла класса Google Android - PullRequest
0 голосов
/ 11 сентября 2018

Я создаю модуль push-уведомлений в моем приложении с 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
}

и есть зависимости приложения 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;

Мой метод 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());
}

Я что-то не так делаю? Я много раз проверял gradle и не нахожу ошибки! Thx !!!!!

1 Ответ

0 голосов
/ 11 сентября 2018

Согласно официальной документации, пожалуйста, обновите ваши зависимости до последних версий. Поэтому, пожалуйста, измените следующие строки кода

Изменение

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'
...