So I run into this problem today. I got an exception saying
"NoClassDefFoundException" class com.example.app.MainClass$3
I know what this exception means so first I looked inside classes.jar file located in /app/build/intermediates/exploded-aar/$packageName%/%versionName%/jars.
There I found the "missing" class with exactly the same signature: MainClass$3
. So it WAS generated. Then on my smartphone I went to /data/app/%packageName%/
and looked inside base.apk
file. Inside it I found a file named classes.dex
. I opened it with Notepad++ and I found mentioning of my MainClass$3
there as well! Why this class could not be found? What else should I check? I cannot post original exception messages nor files cause it's commercial, but I'll try to clarify things as much as I can if needed.
UPDATE #1: There is something I think I need to add. The odd thing about all of this is that this class is the only one that cannot be found from the whole library. It's not new, I added it long time ago, so I just thought, maybe some exception that occurred while running some code from that class causing this error?
UPDATE #2: I debugged my app and saw the strangest thing ever: I was able to call constructor of the problematic class with arguments and the object was SUCCESSFULLY CREATED. Then I called a method of the class and got this exception. Here is the method I call
public Observable<String> getSnapshotTaker() {
int a = 1;
Observable<String> snapshotTaker = Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> subscriber) {
queueSnapshot(true, 0, subscriber);
}
});
return snapshotTaker;
}
I inserted
int a = 1;
for debugging purpose. App crashes with the exception on the second line of the method, where I'm trying to create an Observable. So, it looks like it's not the class SnapshotManager
which is causing the crash but rather this Observable
. But why the exception message looks like this then?
UPDATE #3: Here is the stack trace:
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.test.pack.SnapshotManager$3
at com.test.pack.SnapshotManager.getSnapshotTaker(SnapshotManager.java:370)
at com.test.pack.CameraPresenter.takePhoto(CameraPresenter.java:31)
at com.test.pack.MainActivity$MainShutterClickListener.onClick(MainActivity.java:1100)
at android.view.View.performClick(View.java:5204)
at android.view.View$PerformClick.run(View.java:21153)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)