Import Open Source Library Java.lang.NoClassDefFoundError:rx.plugins.RxJavaPlugins

Source: Internet
Author: User

Questions:

The library of a new open source library in its own project, the compilation ran successfully on the phone began to appear abnormal, but the mobile phone version above or equal to 21 is normal. Error message:

java.lang.NoClassDefFoundError: rx.plugins.RxJavaPlugins
    • 1

In fact, there are some Rxjava to use the file prompts display, but before the use of Rxjava are normal, and import a library after the error, the error is definitely not on the Rxjava, so the real error is the first half sentence.

java.lang.NoClassDefFoundError
    • 1
Reason:

The cause of the problem is that the project does not initialize the MULTIDEX option!

Official documentation notes: Multidex support forAndroid 5.0 and higher

Android 5.0 and higher uses a runtime called ART which natively supports loading multiple Dex files from application APK F Iles. ART performs pre-compilation at application install time which scans for classes (.. N). dex files and compiles them into a single. oat file for execution by the Android device. For more information on the Android 5.0 runtime, see Introducing ART. The reason why your app was working fine on API level 21.

Overall,Android 5.0 and later has a time-consuming operation called ART that supports loading multiple Dex files from an application's apk file. Art performs pre-compilation during application installation, scanning classes (.. N). dex file and compile it as a single. oat file for Android devices to execute.

The above is why the application can work properly at API level 21.

Workaround:

Multidex support prior to Android 5.0

Versions of the platform prior to Android 5.0 with the Dalvik runtime for executing app code. By default, the Dalvik limits apps to a single Classes.dex bytecode file per APK. In order to get around this limitation, you can use the Multidex support library, which becomes part of the primary DEX fi Le of your app and then manages access to the additional DEX files and the code they contain.

The above is for Android version before 5.0 is less than 5.0 when the solution (3 steps, indispensable):

    • 1 in the app folder, specify the location of the Build.gradle file to add:
true
    • 1
    • 2 Add Multidex package dependency in the Build.gradle file under the app folder
    ‘com.android.support:multidex:1.0.0‘
    • 1
    • 3 inherit the project custom application multidexapplication, or override the method directly in the custom application code as follows:
     @Override    protected void attachBaseContext(Context base) {        super.attachBaseContext(base); MultiDex.install(this); }
    • 1
    • 2
    • 3
    • 4
    • 5

Compile again and the problem can be solved.

This problem is primarily a version issue that is caused by the art program, which java.lang.NoClassDefFoundError can be resolved by this method.

Import Open Source Library Java.lang.NoClassDefFoundError:rx.plugins.RxJavaPlugins

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.