I tried adding firebase dependencies and my app start crashing without showing logcat, then I tested it with firebase test lab, then I saw this Fatal Exception. Please help me out.
java.lang.RuntimeException: Unable to instantiate application com.edu.ae.Applications: java.lang.ClassNotFoundException: Didn't find class "com.edu.ae.Applications" on path: DexPathList[[zip file "/data/app/com.edu.ae-_Z-yzsqBFr0um-xAQ9ruKQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.edu.ae-_Z-yzsqBFr0um-xAQ9ruKQ==/lib/arm64, /system/lib64, /product/lib64]]
FATAL EXCEPTION: main
Process: com.edu.ae, PID: 19557
java.lang.RuntimeException: Unable to instantiate application com.edu.ae.Applications: java.lang.ClassNotFoundException: Didn't find class "com.edu.ae.Applications" on path: DexPathList[[zip file "/data/app/com.edu.ae-_Z-yzsqBFr0um-xAQ9ruKQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.edu.ae-_Z-yzsqBFr0um-xAQ9ruKQ==/lib/arm64, /system/lib64, /product/lib64]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:1226)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6431)
at android.app.ActivityThread.access$1300(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.edu.ae.Applications" on path: DexPathList[[zip file "/data/app/com.edu.ae-_Z-yzsqBFr0um-xAQ9ruKQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.edu.ae-_Z-yzsqBFr0um-xAQ9ruKQ==/lib/arm64, /system/lib64, /product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
at android.app.Instrumentation.newApplication(Instrumentation.java:1155)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1218)
... 9 more
Suppressed: java.io.IOException: Failed to open dex files from /data/app/com.edu.ae-_Z-yzsqBFr0um-xAQ9ruKQ==/base.apk because: Failure to verify dex file '/data/app/com.edu.ae-_Z-yzsqBFr0um-xAQ9ruKQ==/base.apk': Field's class index unexpected, 63vs 62
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:365)
at dalvik.system.DexFile.<init>(DexFile.java:107)
at dalvik.system.DexFile.<init>(DexFile.java:80)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:444)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:403)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:126)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:101)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:74)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:87)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:116)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:114)
at android.app.ApplicationLoaders.getClassLoaderWithSharedLibraries(ApplicationLoaders.java:60)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:851)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:950)
at android.app.LoadedApk.getResources(LoadedApk.java:1188)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2462)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2454)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6343)
... 8 more
I restarted the project to see if it would work Here is the Applications.java, as for the MainActivity, I didn't add any code to it
package com.edu.ae;
import android.app.AlarmManager;
import android.app.Application;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.multidex.MultiDex;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
public class Applications extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
private Thread.UncaughtExceptionHandler uncaughtExceptionHandler;
@Override
public void onCreate() {
this.uncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Intent intent = new Intent(getApplicationContext(), DebugActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra("error", getStackTrace(ex));
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 11111, intent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager am = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 1000, pendingIntent);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(2);
uncaughtExceptionHandler.uncaughtException(thread, ex);
}
});
super.onCreate();
}
private String getStackTrace(Throwable th){
final Writer result = new StringWriter();
final PrintWriter printWriter = new PrintWriter(result);
Throwable cause = th;
while(cause != null){
cause.printStackTrace(printWriter);
cause = cause.getCause();
}
final String stacktraceAsString = result.toString();
printWriter.close();
return stacktraceAsString;
}
}
I forgot to mention that while building, it shows "failed to merge dex"