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
On Android Studio:
1) Add multiDexEnabled = true
in your default Config
2) Add compile com.android.support:multidex:1.0.0 in your dependencies
3) Application class
extend MultiDexApplication
instead of just Application
Activity again added to manifest.I tried in my manifest then app worked.
<activity
android:name="com.xxx.xxx.MainActivity"
Other idea. For example, you have class derived from "android.support.v4.app.Fragment".
However you made a mistake and inherited it from "android.app.Fragment". Then you will have this error on the Android 2 devices.
I'm currently using SDK 20.0.3 and none of the previous solutions worked for me.
I was able to get things to work by
This brought this created Java class files that were compiled for the Dalvik VM instead of the Java VM when the Android project was built. This allowed the Java class files in the Android Library jar file to go thru dexing when the Android project .apk was created. Now when the app was run the Java project classes were found instead of a Java.lang.NoClassDefFoundError being thrown.
If you want to use a jar file instead of linking the source, then you will need to create a Library Android project. (An Android Project with 'is library' checked in Properties -> Android.) You will then need to either link the source of the Java Project to the Android Library project as described above or copy the source files from the 'src' folder of the Java Project to the 'src' folder of the Android Library project. Build the Android Library project. Then you will be able copy the Android Project jar file that was created into the 'libs' folder of the Android folder because the class files in it were compiled for the Davlik VM instead of the Java VM when the Android project was built. This allows the Java class files in the Android Library jar file to go thru dexing when the Android project .apk is created. Now when the app is run the Java project classes will be found instead of a Java.lang.NoClassDefFoundError being thrown.
Just in case it helps someone, I faced the same issue. My jar file was under the libs directory and the jar was added to the build path. Still it was throwing that exception.
I just cleaned the project and it worked for me.
Eclipse -> Project -> Clean -> Select the project and clean
For me, the issue was that the referenced library was built using java 7. I solved this by rebuilding using the 1.6 JDK.