gpt4 book ai didi

android - OneSignal Android Studio 获取 FCM token 时出现未知错误

转载 作者:行者123 更新时间:2023-12-05 00:10:57 27 4
gpt4 key购买 nike

我有一个问题。我无法使用 OneSignal。我不知道为什么。我用谷歌搜索了这个错误,但没有任何帮助。

目前我使用 Android Studio 版本:4.2OneSignal最新版本:4.3.4还有最新的 Firebase 版本。我创建了一个新的 Firebase 项目和 OneSignal 项目。

这是错误:

2021-05-25 13:06:37.370 3225-4181/de.kggaming.application E/OneSignal: Unknown error getting FCM Token
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId;
at com.onesignal.PushRegistratorFCM.getToken(PushRegistratorFCM.java:60)
at com.onesignal.PushRegistratorAbstractGoogle.attemptRegistration(PushRegistratorAbstractGoogle.java:97)
at com.onesignal.PushRegistratorAbstractGoogle.access$100(PushRegistratorAbstractGoogle.java:37)
at com.onesignal.PushRegistratorAbstractGoogle$1.run(PushRegistratorAbstractGoogle.java:84)
at java.lang.Thread.run(Thread.java:923)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.FirebaseInstanceId" on path: DexPathList[[dex file "/data/data/de.kggaming.application/code_cache/.overlay/base.apk/classes3.dex", zip file "/data/app/~~37wP-zifceloViDoIaZiLQ==/de.kggaming.application-MT0rnPML9HHvlPgijekxXw==/base.apk"],nativeLibraryDirectories=[/data/app/~~37wP-zifceloViDoIaZiLQ==/de.kggaming.application-MT0rnPML9HHvlPgijekxXw==/lib/arm64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.onesignal.PushRegistratorFCM.getToken(PushRegistratorFCM.java:60) 
at com.onesignal.PushRegistratorAbstractGoogle.attemptRegistration(PushRegistratorAbstractGoogle.java:97) 
at com.onesignal.PushRegistratorAbstractGoogle.access$100(PushRegistratorAbstractGoogle.java:37) 
at com.onesignal.PushRegistratorAbstractGoogle$1.run(PushRegistratorAbstractGoogle.java:84) 
at java.lang.Thread.run(Thread.java:923) 

这是我的 build.gradle(项目):

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.0"
classpath 'com.google.gms:google-services:4.3.8'
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'


// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
mavenCentral()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

这是我的应用程序 build.gradle:

plugins {
id 'com.onesignal.androidsdk.onesignal-gradle-plugin'
id 'com.android.application'
id 'com.google.gms.google-services'

}

android {
compileSdkVersion 30

defaultConfig {
applicationId "de.kggaming.application"
minSdkVersion 26
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.firebase:firebase-messaging:22.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation platform('com.google.firebase:firebase-bom:28.0.1')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.onesignal:OneSignal:[4.0.0, 4.99.99]'
}

这里是应用类:

package de.kggaming.application;

import android.app.Application;

import com.onesignal.OneSignal;

public class ApplicationClass extends Application {
private static final String ONESIGNAL_APP_ID = "XXXXXXXXXXXXXXXXXXXXXXXX";
@Override
public void onCreate() {
super.onCreate();
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.DEBUG, OneSignal.LOG_LEVEL.DEBUG);

// OneSignal Initialization
OneSignal.initWithContext(this);
OneSignal.setAppId(ONESIGNAL_APP_ID);
}
}

该应用程序没有任何功能。只是一个空 Activity 和这个信号实现。

你能帮我解决这个问题吗?

谢谢!

最好的问候,

小工具

最佳答案

解析失败:Lcom/google/firebase/iid/FirebaseInstanceId

在尝试初始化依赖于 firebase SDK 的 hypertrack_plugin 时,我的 flutter 项目遇到了类似的问题。

enter image description here

经过两天的搜索,在 android/app/build.gradle

中添加了这个实现

希望这个解决方案也能解决您的问题。

dependencies {
implementation "com.google.firebase:firebase-iid"
}

从这个 Link 找到了解决方案

关于android - OneSignal Android Studio 获取 FCM token 时出现未知错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67686867/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com