NoClassDefFoundError for code in an Java library on Android

前端 未结 24 1647
梦如初夏
梦如初夏 2020-11-22 15:19

I am experiencing an error quite often among my users. The app crashes during startup. When the MainActivity is supposed to be loaded the VM apparently cannot find the class

相关标签:
24条回答
  • 2020-11-22 15:53

    In my case, I was trying to add a normal java class (from a normal java project) compiled with jre 1.7 to an android app project compiled with jre 1.7.

    The solution was to recompile that normal java class with jre 1.6 and add references to the android app project (compiled with jre 1.6 also) as usual (in tab order and export be sure to check the class, project, etc).

    The same process, when using an android library to reference external normal java classes.

    Don't know what's wrong with jre 1.7, when compiling normal java classes from a normal java project and try to reference them in android app or android library projects.

    If you don't use normal java classes (from a normal java project) you don't need to downgrade to jre 1.6.

    0 讨论(0)
  • 2020-11-22 15:55

    I met NoClassDefFoundError for a class that exists in my project (not a library class). The class exists but i got NoClassDefFoundError. In my case, the problem was multidex support. The problem and solution is here: Android Multidex and support libraries

    You get this error for Android versions lower than 5.0.

    0 讨论(0)
  • 2020-11-22 15:56

    I fixed this issue by adding library project path in project.propertied manually. some how eclipse did not added this entry automaticvally along with "add project". so the point where app was trying to refer any componenrt inside lib project it was crashing .

    you also can try the same thing . app dependecy in projec.properties like

    android.library.reference.1=....\android-sdks\extras\google\google_play_services\libproject/google-play-services_lib

    and run .

    0 讨论(0)
  • 2020-11-22 15:57

    Some time java.lang.NoClassDefFoundError: error appear when use ART instead of Dalvik runtime. To change runtime just go to Developer Option -> Select Runtime -> Dalvik.

    0 讨论(0)
  • 2020-11-22 15:58

    I tried all of the above said solutions but did not worked out for me, Here is what i did to get it done project-> config build path-> order and export-> move dependent project on top

    0 讨论(0)
  • 2020-11-22 15:59

    For me this problem was related to the API that I was using not being deployed. For example, I used a ZSDK_API.jar as a reference.

    To fix the issue I had to right click on the project and select properties. From JAVA BUILD PATH, I had to add the API that was not being deployed. This was weird as the app was throwing MainActivity class not found and in reality the error was caused by the DiscoveryHandler class not being found.

    Hopes this helps someone.

    0 讨论(0)
提交回复
热议问题