java.lang.NoClassDefFoundError: rx.subjects.SerializedSubject

The problem is as follows:
Write picture description here

Write picture description here

The problem refers to this sentence in my code

publishBus = new SerializedSubject<>(PublishSubject.<Event>create());

This problem is weird. It can be compiled and passed normally, but the app will crash when it runs. Let me talk about the solution to the problem first , and then explain the principle:

  1. Modify in build.gradle:

    defaultConfig { 
        ...
        multiDexEnabled true
        }
        ...
        dependencies {
        compile 'com.android.support:multidex:1.0.1'
        ...
        }
  2. Add MultiDex.install(getBaseContext()) in your CustomApplication onCreate(), or, Application class extend MultiDexApplication:

     public class CustomApplication extends Application {
          
          
            ...
               @Override
                protected void attachBaseContext(Context base) {
                    super.attachBaseContext(base);
                    MultiDex.install(base);
                }
            ...
  3. The number of configuration methods exceeds 64K/configuration application for Dalvik executable subpackaging: the
    magical Android65536 -
    Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the App's compiled code. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. In computer science, the term kilo (K for short) means 1024 (or 2^10). Since 65,536 equals 64 X 1024, this limit is also known as the "64K reference limit".

    Specific explanation: https://developer.android.com/studio/build/multidex.html#about

Guess you like

Origin blog.csdn.net/lrxb_123/article/details/73650648