couldn't run Google Maps Android API Utility D

2020-03-26 09:17发布

问题:

i'm having problems to run the Google Maps Android API Utility Demo, it shows this error:

04-03 16:32:37.397: E/dalvikvm(2592): Could not find class 'com.google.maps.android.utils.demo.ClusteringDemoActivity', referenced from method com.google.maps.android.utils.demo.MainActivity.onCreate
    04-03 16:32:37.452: E/AndroidRuntime(2592): FATAL EXCEPTION: main
    04-03 16:32:37.452: E/AndroidRuntime(2592): java.lang.NoClassDefFoundError: com.google.maps.android.utils.demo.ClusteringDemoActivity
    04-03 16:32:37.452: E/AndroidRuntime(2592):     at com.google.maps.android.utils.demo.MainActivity.onCreate(MainActivity.java:20)
    04-03 16:32:37.452: E/AndroidRuntime(2592):     at android.app.Activity.performCreate(Activity.java:5163)
    04-03 16:32:37.452: E/AndroidRuntime(2592):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
    04-03 16:32:37.452: E/AndroidRuntime(2592):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
    04-03 16:32:37.452: E/AndroidRuntime(2592):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
    04-03 16:32:37.452: E/AndroidRuntime(2592):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
    04-03 16:32:37.452: E/AndroidRuntime(2592):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
    04-03 16:32:37.452: E/AndroidRuntime(2592):     at android.os.Handler.dispatchMessage(Handler.java:99)
    04-03 16:32:37.452: E/AndroidRuntime(2592):     at android.os.Looper.loop(Looper.java:137)
    04-03 16:32:37.452: E/AndroidRuntime(2592):     at android.app.ActivityThread.main(ActivityThread.java:4895)
    04-03 16:32:37.452: E/AndroidRuntime(2592):     at java.lang.reflect.Method.invokeNative(Native Method)
    04-03 16:32:37.452: E/AndroidRuntime(2592):     at java.lang.reflect.Method.invoke(Method.java:511)
    04-03 16:32:37.452: E/AndroidRuntime(2592):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
    04-03 16:32:37.452: E/AndroidRuntime(2592):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
    04-03 16:32:37.452: E/AndroidRuntime(2592):     at dalvik.system.NativeStart.main(Native Method)

although i followed the steps shown in the installation demo, and the class ClusteringDemoActivity exists in the package.

回答1:

I solved this by adding the GoogleMapsUtil as a library to the demo project.

If you are following the setup guide at https://developers.google.com/maps/documentation/android/utility/setup at the step Reference the utility library from the utility demo app do the following instead:

  1. Right click on your demo project (MainActivity) and choose Properties.
  2. Click the Android tab.
  3. Under the Library section click Add and select the maps util project (called library)


回答2:

The docs tell you to use:

compile 'com.google.maps.android:android-maps-utils:0.4+'

Using this will give the error. You must use android-maps-utils:0.3+

compile 'com.google.maps.android:android-maps-utils:0.3+'

This will get rid of the error.