3

Getting NoClassDefFoundError within project and in Google Maps for Android sample found in google-play-services folder.

I have tried so far:

  • Importing google-play-services_lib into workspace through wizard and making sure code is copied to directory
  • Manually copying google-play-services_lib into directory with sample, then importing into workspace
  • Copying jar into workspace
  • Google Play Services is installed on test devices (Nexus 5, Galaxy S4)
  • There is a green check next to the library under my project when going to properties > android
  • I can see the classes in source at compile time, compiles with no errors
  • Reinstalled the lib from the Android SDK Manager and made sure the key is correct in Google API console; also made sure v2 of maps was enabled for that key
  • Added proguard exceptions as per integration instructions

Any ideas?

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.package.projectname"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="18"
        android:targetSdkVersion="21" />

    <permission
        android:name="com.package.projectname.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.package.projectname.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.package.projectname.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.package.projectname.MapActivity"
            android:label="@string/title_activity_map"
            android:parentActivityName="com.package.projectname.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.package.projectname.MainActivity" />
        </activity>

        <uses-library
            android:name="com.google.android.maps"
            android:required="true" />

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value=“my_key_from_google_api_console” />
    </application>

</manifest>
Oh Danny Boy
  • 4,857
  • 8
  • 56
  • 88
  • Check this http://developer.android.com/google/play-services/setup.html – Deniz Jul 29 '14 at 09:12
  • That is the resource I used to setup. My notes specify all the variations and deviations attempted in addition to following that guide line for line several times. – Oh Danny Boy Jul 29 '14 at 18:22
  • I would also like to specify that I have completed this setup before, on a different version of the tools. I have also reinstalled the tools, eclipse, JDK three times in an attempt to fix. – Oh Danny Boy Jul 29 '14 at 18:24
  • Which class is the NoClassDefFoundError complain about? – Eduard Aug 01 '14 at 17:52
  • @EduardK. int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()); yields the error. Removing this throws the error at an XML containing: class="com.google.android.gms.maps.MapFragment – Oh Danny Boy Aug 01 '14 at 17:54
  • Seems to occur at any point referencing a class in the Google Play Services, as if the classes cannot be found. This is why I believed it to be proguard, but this is identical to documentation found here: http://developer.android.com/google/play-services/setup.html – Oh Danny Boy Aug 01 '14 at 17:55
  • It sounds like it can't find the Google Play services library. How did you add it as a dependency? – Eduard Aug 01 '14 at 18:17

1 Answers1

2

I don't think you need the line:

    <uses-library
        android:name="com.google.android.maps"
        android:required="true" />

In fact, I think that's the name of the old maps library. Try removing it and see if that fixes your problem. Also, make sure your code is importing from com.google.android.gms.maps and com.google.android.gms.maps.model, the packages for Google Maps API V2.

UPDATE

Your build configuration isn't including the Google Play Services jar in your APK.

To fix this in IntelliJ: https://stackoverflow.com/a/17977734/1235702

To fix this in Eclipse, follow steps 3 and 4 here: https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw (I didn't write this doc, but kudos to whoever did!)

  1. Add the Google Play Services project into your Eclipse workspace.
    • Click File -> Import..., select Android -> Existing Android Code into Workspace Browse to and select /extras/google/google_play_services/libproject/google-play-services_lib
  2. To add the dependency to Google Play Services into your project
    • Project -> Properties -> Android -> Library, Add -> google-play-services_lib

(Sorry; the markdown won't let me set the numbers to 3 and 4 explicitly.)

Screenshot from OP for posterity: Eclipse properties for Google Play Services Lib

Community
  • 1
  • 1
brokethebuildagain
  • 2,162
  • 1
  • 22
  • 44
  • Thank you for your response. Removing seems to yield the same error. I am targeting Google APIs (18), but have also tried Android 4.3 (18) if that makes a difference. – Oh Danny Boy Aug 01 '14 at 17:50
  • Hmm. Well, you definitely don't need it. What IDE are you using and how are you building it? – brokethebuildagain Aug 01 '14 at 17:53
  • I am using Eclipse 4.2.1 with ADT 34.0.2.1259578 - building directly to a Nexus 5 with Google Play Services installed and a Samsung Galaxy S4 with the same library installed. App itself compiles and runs on both devices, but crashes with specified error when referencing anything in the Google Play Services lib. Google Play Services level 18 (not the froyo version) – Oh Danny Boy Aug 01 '14 at 17:58
  • I had this problem with Intellij, so I had to do this: http://stackoverflow.com/a/17977734/1235702 This looks like the same solution for eclipse: http://stackoverflow.com/a/16603125/1235702 – brokethebuildagain Aug 01 '14 at 18:00
  • The Eclipse example provided shows the jars under Order and Export, however, my projects Order and Export does NOT show the jar. I believe you are correct in that this is the issue. Any idea how to add this jar? When clicking on "Android" in the Preferences pane for my project, I see the lib with the path and a green checkmark. Additionally, I see the jar when clicking on the "Android Private Libraries" package in the Google Play Services project and my project, further adding to the confusion. – Oh Danny Boy Aug 01 '14 at 18:14
  • I think if you import `android-sdk\extras\google\google_play_services\libproject\google-play-services_lib` into your workspace as a "library project" it should be available? I'm just going off of this: http://stackoverflow.com/a/14400585/1235702 as I don't use Eclipse. :/ – brokethebuildagain Aug 01 '14 at 18:20
  • Aha! Try steps 3 and 4 here: https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw – brokethebuildagain Aug 01 '14 at 18:23
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/58514/discussion-between-cullenj-and-oh-danny-boy). – brokethebuildagain Aug 01 '14 at 18:51
  • The ordering worked after a reimport. Thanks so much. Bounty can be awarded in 22 hours; will do so then. Thanks again. – Oh Danny Boy Aug 01 '14 at 19:35
  • 1
    Thanks! Glad it worked; I remember what a headache that issue was to slog through now. :) – brokethebuildagain Aug 01 '14 at 19:46
  • My apologies about that. Bounty awarded. – Oh Danny Boy Aug 05 '14 at 18:10