I receive this error and program crashes when I try to run the app on phone with older than API level 22. However the app works fine on phone with API level 22. What could b
I followed the 2nd approach mentioned by jackaal. I had included the whole play services in my gradle. After removing this and selecting only the required play services apis fixed my problem.
Since the play services has a lot of apis, the total method count is beyond 65k by itself. So this causes error in mobiles with api level 21 and below.
Before gradle:-
compile 'com.google.android.gms:play-services:8.4.0'
After gradle:-
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
compile 'com.google.android.gms:play-services-plus:8.4.0'
After spending couple of days to solve this strange problem, Finally found the cause of the crash. Although the error persists, program runs without any problem now.
The reason why the program runs fine with API level 22 and not not with below 21 is the method limit in android which is 65K. Above 21 natively supports loading multiple dex files from application APK files where below 21 does not. Documents states it here
The solution for this problem is solved at this stackoverflow post
or
if you use google play services, instead of compiling the whole APIs, selectively compile may help. You can find more details here.