Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google map v2 initializing error on secondary dex mechanism android

I'm getting an error on initializing map, when I try to use map as a external library and tried to make secondary, the apk is created and when I tried to launch map it crashes. But when I tried the same thing without dex it works fine (stacktrace is below).

How can I resolve this issue? I'm facing 65536 limit exceed error. So, it's only way to create apk, and I'm using ant.

java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
10-06 22:20:24.374: E/AndroidRuntime(17015):    at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
10-06 22:20:24.374: E/AndroidRuntime(17015):    at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
10-06 22:20:24.374: E/AndroidRuntime(17015):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:291)
10-06 22:20:24.374: E/AndroidRuntime(17015):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
like image 827
Aman Avatar asked Oct 06 '14 16:10

Aman


2 Answers

It seems you use google-play-services.jar. The jar file does not include some resources.

Link the google-play-services_lib to your project.

java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable in android

like image 156
wf9a5m75 Avatar answered Nov 14 '22 11:11

wf9a5m75


If you use eclipce import Google Play Services from your SDK to workspace and add as library. If you use Android Studio add gradle to this as dependecies. compile 'com.google.android.gms:play-services:6.1.+'

Here is link for developing with Google Play Services: http://developer.android.com/google/play-services/setup.html

You cannot use jar file for google play services.

You can find further information about 64k Limit at Jake Wharton's blog ; http://jakewharton.com/play-services-is-a-monolith/

Also with Android 5.0 Lolipop release google release a MultiDexApplication library. You should try it. http://developer.android.com/reference/android/support/multidex/MultiDexApplication.html

Note: With API v21, this feature supported natively by Android.

like image 32
Sinan Kozak Avatar answered Nov 14 '22 09:11

Sinan Kozak