初始化Moengage后,应用程序崩溃。
java.lang.NoSuchMethodError:没有虚拟方法 getInstanceId()Lcom / google / android / gms / tasks / Task;在班上 Lcom / google / firebase / iid / FirebaseInstanceId;或其超一流 (出现“ com.google.firebase.iid.FirebaseInstanceId”的声明 在/data/app/com.morecustomersapp-1/base.apk:classes3.dex中) 在com.moengage.firebase.PushHandlerImpl.getPushToken(PushHandlerImpl.java:63) 在com.moengage.firebase.PushHandlerImpl.registerForPushToken(PushHandlerImpl.java:52) 在com.moengage.pushbase.push.MoEPushWorker.registerForPush(MoEPushWorker.java:214) 在com.moengage.pushbase.push.MoEPushWorker.handlePushRegistrationFallback(MoEPushWorker.java:261) 在com.moengage.pushbase.push.MoEPushWorker.onHandleIntent(MoEPushWorker.java:109) 在android.app.IntentService $ ServiceHandler.handleMessage(IntentService.java:67) 在android.os.Handler.dispatchMessage(Handler.java:102) 在android.os.Looper.loop(Looper.java:163) 在android.os.HandlerThread.run(HandlerThread.java:61)2019-04-01 02:58:31.843 23134-23499 / com.morecustomersapp E / UncaughtException:java.lang.NoSuchMethodError:没有虚拟方法 getInstanceId()Lcom / google / android / gms / tasks / Task;在班上 Lcom / google / firebase / iid / FirebaseInstanceId;或其超一流 (出现“ com.google.firebase.iid.FirebaseInstanceId”的声明 在/data/app/com.morecustomersapp-1/base.apk:classes3.dex中) 在com.moengage.firebase.PushHandlerImpl.getPushToken(PushHandlerImpl.java:63) 在com.moengage.firebase.PushHandlerImpl.registerForPushToken(PushHandlerImpl.java:52) 在com.moengage.pushbase.push.MoEPushWorker.registerForPush(MoEPushWorker.java:214) 在com.moengage.pushbase.push.MoEPushWorker.handlePushRegistrationFallback(MoEPushWorker.java:261) 在com.moengage.pushbase.push.MoEPushWorker.onHandleIntent(MoEPushWorker.java:109) 在android.app.IntentService $ ServiceHandler.handleMessage(IntentService.java:67) 在android.os.Handler.dispatchMessage(Handler.java:102) 在android.os.Looper.loop(Looper.java:163) 在android.os.HandlerThread.run(HandlerThread.java:61)
模块级别gradle:
implementation ('com.moengage:moe-android-sdk:9.3.01') {
exclude group: 'com.moengage', module: 'moe-location-lib'
}
项目级别gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:3.2.0'
classpath 'io.fabric.tools:gradle:1.+'
}
应用程序类:
public class AppConfig extends Application implements PushManager.OnTokenReceivedListener, OnAppBackgroundListener {
@Override
public void onCreate() {
super.onCreate();
MoEngage moEngage = new MoEngage.Builder(this, getResources().getString(R.string.mo_engage_app_id))
.setLogLevel(Logger.VERBOSE)
.enableLogsForSignedBuild()
.setNotificationSmallIcon(
R.drawable.ic_notification_holo)
.setNotificationLargeIcon(R.drawable.ic_launcher)
.enableLocationServices()
.build();
MoEngage.initialise(moEngage);
SharedPreferences preferences = getSharedPreferences("demoapp", 0);
boolean existing = false;
if (preferences.getBoolean("has_sent_install", false)) {
if (preferences.getBoolean("existing", false)) {
existing = true;
}
MoEHelper.getInstance(getApplicationContext()).setExistingUser(existing);
preferences.edit().putBoolean("has_sent_install", true).apply();
preferences.edit().putBoolean("existing", true).apply();
}
PushManager.getInstance().setTokenObserver(this);
MoEHelper.getInstance(getApplicationContext()).registerAppBackgroundListener(this);
}
@Override
public void goingToBackground() {
}
@Override
public void onTokenReceived(String token) {
Log.d("MoEngageDemo", "onTokenReceived: " + token);
}
}
答案 0 :(得分:0)
我也遇到了这个问题。但幸运的是找到了解决方案
val moEngage = MoEngage.Builder(this, BuildConfig.MOENGAGE_ID)
.enableSegmentIntegration()
.setLogLevel(Logger.VERBOSE)
.build()
MoEngage.initialise(moEngage)
我认为在MoEngage初始化期间,您可能会忘记添加enableSegmentIntegration()
在app / build.gradle中添加这些依赖项
implementation 'com.google.firebase:firebase-auth:19.4.0'
implementation 'com.google.firebase:firebase-analytics-ktx:17.5.0'
implementation 'com.google.firebase:firebase-core:17.5.0'
implementation 'com.google.firebase:firebase-messaging:20.2.4'