The problem I am facing is that my android application works well on devices having API 5.0 and above but crashes on devices having Kitkat(4.4) and its corresponding lower v
One issue that you may face is this one, as explained in the documentation:
multiDexEnabled true
Applications that use multidex may not start on devices that run versions of the platform earlier than Android 4.0 (API level 14) due to a Dalvik linearAlloc bug (Issue 22586). If you are targeting API levels earlier than 14, make sure to perform testing with these versions of the platform as your application can have issues at startup or when particular groups of classes are loaded. Code shrinking can reduce or possibly eliminate these potential issues.
When you are using multidex
, then try to extend your application class with MultiDexAppication
instead of Application
and override below method this required for Android below 5.0 (because 5.0 and above support to the multidex)
@Override
protected void attachBaseContext(Context base)
{
super.attachBaseContext(base);
MultiDex.install(BaseApplication.this);
}
and in dependencies add this
compile 'com.android.support:multidex:1.0.1'
This might not be relevant to the particular scenario but as the heading of the question relates to the problem I encountered and the reason I came across this question. So I am answering it here. I encountered an issue similar to this, but in my case extending multidexapplication, and enabling multidex weren't doing the job. I ended up using a plugin for counting methods in my project. By using that I realised that I am no way near the 65K limit and the bug is related to something else. I found this page where they someone had talked about disabling instant-run from Settings, which actually did the job for me. Now I am not using the multi-dex library and the builds are faster as well. If I encounter the issue again, I will update the answer accordingly.
I just had this problem and solved it by adding the following line to the applications AndroidManifest.xml as an attribute on the application tag:
android:name="android.support.multidex.MultiDexApplication"
I have two apps which share the same resources and libraries. The only difference is in the exposed interface. I added multidex to both but forgot to put the above attribute in the manifest for one. The NoClassDefFoundError did not help much at all.
You can also check out the following: http://developer.android.com/tools/building/multidex.html