NoClassDefFoundError for code in an Java library on Android
I had the same issue, I did the following to fix the problem.
- Go to "Properties" of the project.
- Select "Java Build Path"
- Select "Order and Export" Tab
- You should see the selected project's "src" and "gen" paths and dependencies here.
- The order how they listed were first "src" and then "gen" path
- I switch them, so that "gen" folder is build before the "src"
gen - automated code in project (from dependencies and references)
src - source code in project
There was no need to restart the Eclipse. It just started working.
Honestly I have never tried "Android Tools > Fix Project Properties", sometimes it might be doing the same thing. I do not know, I just did above after seen the error message, thinking something is wrong with the build paths.
Edit
Later on it was not sufficient, I was getting the error again. Then I "checked" all the dependencies listed in that view. Now it works again. So far so good. I will keep this updated if it fails again.
FYI: in my last attempt, I tried "Android Tools > Fix Project Properties", but it didn't work out for me.
NoClassDefFoundError on external library project for Android
It has been clearly stated in offcial API here:
A library project can include a JAR library
You can develop a library project that itself includes a JAR library, however you need to manually edit the dependent application project's build path and add a path to the JAR file
The jar lib must be manually added to the dependent application project's build path, not only the library project build path itself.
Update from SDK r17:
This is automatically handled by ADT now, check out new feature for ADT 17.0.0 release here:
Added feature to automatically setup JAR dependencies. Any .jar files in the /libs folder are added to the build configuration (similar to how the Ant build system works). Also, .jar files needed by library projects are also automatically added to projects that depend on those library projects. (more info)
android studio: NoClassDefFoundError exception on runtime with Java Library Module
This issue is resolved in Android Studio 0.4.4 :D (http://tools.android.com/recent/androidstudio044released)
NoClassDefFoundError for .jar library at runtime in Android Studio
New Findings
My GS4 (Android 4.3) cannot run this app, but HTC One M8 (Android 5.0.1) can run it
Root Cause
65K methods limit
Refer to this document: https://developer.android.com/tools/building/multidex.html
Basically there is a methods reference limit and the only solution is to use multidex configuration. However there are implementation for platforms prior 5.0 and after 5.0
Solution
The solution is described in both:
https://developer.android.com/tools/building/multidex.html
https://developer.android.com/reference/android/support/multidex/MultiDexApplication.html
For my project, since it supports older version of Android, I go with the "multidex support library" solution.
- Set the build tool version of all library modules and app module to the latest 21.1.2
- For module that has Application class, add compile 'com.android.support:multidex:1.0.0' as dependency
- Refer to this link to modify your application class. https://developer.android.com/reference/android/support/multidex/MultiDexApplication.html
- At the same gradle script, under android -> defaultConfig block, add "multiDexEnabled true"
- If your system gives "Java Heap Size" error, in the app module's gradle script, add the following
dexOptions { incremental true javaMaxHeapSize "4g"}
Related Topics
Get Selected Item Using Checkbox in Listview
How to Enable Logcat/Console in Eclipse For Android
How to Install Google Frameworks (Play, Accounts, etc.) on a Genymotion Virtual Device
How to Programmatically "Restart" an Android App
Android.Content.Activitynotfoundexception:
How to Disable Landscape Mode in Android
Why Does Layoutinflater Ignore the Layout_Width and Layout_Height Layout Parameters I'Ve Specified
Difference Between Fragmentpageradapter and Fragmentstatepageradapter
How to Specify Different Layouts for Portrait and Landscape Orientations
Calling a Fragment Method from a Parent Activity
Convert View to Bitmap on Android
Android: Reverse Geocoding - Getfromlocation
How to Get the Android Emulator's Ip Address
Android: Java.Lang.Securityexception: Permission Denial: Start Intent
Custom Notification Layouts and Text Colors
How to Get Package Name from Anywhere
How to Detect Swipe Direction Between Left/Right and Up/Down