46959

NoClassDefFoundError: com.google.gson.GsonBuilder when using google play services with microsoft azu

Question:

I am building an android app which uses google play services for google maps and Microsoft azure for mobile services(cloud storage). When i use just Microsoft azure libraries i don't face any problems but when add google play libraries it gives me the following error.

Error

FATAL EXCEPTION: main java.lang.NoClassDefFoundError: com.google.gson.GsonBuilder at com.microsoft.windowsazure.mobileservices.MobileServiceClient.createMobileServiceGsonBuilder(MobileServiceClient.java:192) at com.microsoft.windowsazure.mobileservices.MobileServiceClient.<init>(MobileServiceClient.java:179) at com.microsoft.windowsazure.mobileservices.MobileServiceClient.<init>(MobileServiceClient.java:158) at com.example.jino.navigationplacepicker.ReviewPage.onCreate(ReviewPage.java:27)

this is library dependency structure from my gradle

dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.2.1' compile 'com.android.support:design:23.2.1' compile 'com.google.code.gson:gson:2.4' compile files('libs/azuresdk-android-2.0.3/mobileservices/guava-17.0.jar') compile files('libs/azuresdk-android-2.0.3/mobileservices/mobileservices-2.0.3.jar') compile files('libs/azuresdk-android-2.0.3/mobileservices/mobileservices-2.0.3-javadoc.jar') compile files('libs/azuresdk-android-2.0.3/mobileservices/mobileservices-2.0.3-sources.jar') compile 'com.google.android.gms:play-services:8.4.0' }

Hope you can help me out. Thanks in advance.

Answer1:

When you include compile 'com.google.android.gms:play-services:8.4.0' all of the play services packages are included. If you only need maps from play services, use compile 'com.google.android.gms:play-services-maps:8.4.0' instead.

See <a href="https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project" rel="nofollow">here</a> for a list of play services modules. I am currently testing all of the modules to see which might be the culprit. Stay tuned for an update if you are curious.

I am currently unsure exactly what causes this problem. Using the entire play services collection works on most of my devices, but not any of my Android 4.4.4 devices.

UPDATE: The issue is more likely due to number of packages used and not specific packages not being compatible with Azure. Probably related to the total method count exceeding 64K (DEX64K error).

Continue using specific modules and you should be fine.

Recommend